mirror of
https://github.com/seigler/graphql-playground
synced 2025-07-27 01:26:10 +00:00
41 lines
849 B
JavaScript
41 lines
849 B
JavaScript
const graphql = require('graphql');
|
|
const _ = require('lodash');
|
|
|
|
const {
|
|
GraphQLObjectType,
|
|
GraphQLString,
|
|
GraphQLSchema
|
|
} = graphql;
|
|
|
|
// temp data
|
|
const books = [
|
|
{ name: 'Name of the Wind', genre: 'Fantasy', id: '1' },
|
|
{ name: 'The Final Empire', genre: 'Fantasy', id: '2' },
|
|
{ name: 'The Long Earth', genre: 'Sci-Fi', id: '3' }
|
|
];
|
|
|
|
const BookType = new GraphQLObjectType({
|
|
name: 'Book',
|
|
fields: () => ({
|
|
id: { type: GraphQLString },
|
|
name: { type: GraphQLString },
|
|
genre: { type: GraphQLString }
|
|
})
|
|
});
|
|
|
|
const RootQuery = new GraphQLObjectType({
|
|
name: 'RootQueryType',
|
|
fields: {
|
|
book: {
|
|
type: BookType,
|
|
args: { id: { type: GraphQLString } },
|
|
resolve (parent, { id }) {
|
|
return _.find(books, { id });
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
module.exports = new GraphQLSchema({
|
|
query: RootQuery
|
|
});
|