0.1.4 • Published 4 years ago

orbit-graphql-schema v0.1.4

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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).