orbit-graphql-schema
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

orbit-graphql-schema Build Status

GraphQL schema builder for Orbit.

Installation

Install with yarn:

yarn add orbit-graphql-schema

Usage

import { ApolloServer } from 'apollo-server';
import { Schema } from '@orbit/data';
import { makeExecutableSchema } from 'orbit-graphql-schema';
import SQLSource from 'orbit-sql';
 
const schema = new Schema({
  models: {
    author: {
      attributes: {
        name: { type: 'string' }
      },
      relationships: {
        books: {
          type: 'hasMany',
          model: 'book',
          inverse: 'author'
        }
      }
    },
    book: {
      attributes: {
        title: { type: 'string' }
      },
      relationships: {
        author: {
          type: 'hasOne',
          model: 'author',
          inverse: 'books'
        }
      }
    }
  }
});
 
const source = new SQLSource({
  schema,
  knex: {
    client: 'pg',
    connection: process.env.DATABASE_URL
  }
});
 
const server = new ApolloServer({
  schema: makeExecutableSchema(schema),
  context: {
    source
  }
});
 
server.listen();

License

MIT License (see LICENSE for details).

/orbit-graphql-schema/

    Package Sidebar

    Install

    npm i orbit-graphql-schema

    Weekly Downloads

    1

    Version

    0.1.4

    License

    MIT

    Unpacked Size

    34.1 kB

    Total Files

    12

    Last publish

    Collaborators

    • tchak