Skip to content

Instantly share code, notes, and snippets.

@jefelewis
Created July 13, 2018 08:53
Show Gist options
  • Save jefelewis/98122cd7605edc0137e92603949d18cb to your computer and use it in GitHub Desktop.
Save jefelewis/98122cd7605edc0137e92603949d18cb to your computer and use it in GitHub Desktop.
grapql-express
// Imports: GraphQL
const graphQL = require('graphql');
// Imports: GraphQL Packages
const {
GraphQLObjectType,
GraphQLString,
GraphQLSchema,
GraphQLInt,
GraphQLID,
GraphQLList,
GraphQLNonNull
} = graphQL;
// Imports: MongoDB Schema
const BOOK = require('../mongoose-schemas/bookschema.js');
const AUTHOR = require('../mongoose-schemas/authorschema.js');
// GraphQL: Book Type
const BOOKTYPE = new GraphQLObjectType({
name: 'Book',
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
genre: { type: GraphQLString },
author: {
type: AUTHORTYPE
}
}
})
});
// GraphQL: Author Type
const AUTHORTYPE = new GraphQLObjectType({
name: 'Author',
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
age: { type: GraphQLInt },
books: {
type: new GraphQLList(BOOKTYPE)
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment