mirror of
https://github.com/seigler/graphql-playground
synced 2025-07-27 09:36:09 +00:00
feat(server): add dummy data
This commit is contained in:
parent
0bd76ac5dc
commit
27a5900978
1 changed files with 9 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
const graphql = require('graphql');
|
const graphql = require('graphql');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
GraphQLObjectType,
|
GraphQLObjectType,
|
||||||
|
@ -6,6 +7,13 @@ const {
|
||||||
GraphQLSchema
|
GraphQLSchema
|
||||||
} = graphql;
|
} = 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({
|
const BookType = new GraphQLObjectType({
|
||||||
name: 'Book',
|
name: 'Book',
|
||||||
fields: () => ({
|
fields: () => ({
|
||||||
|
@ -22,7 +30,7 @@ const RootQuery = new GraphQLObjectType({
|
||||||
type: BookType,
|
type: BookType,
|
||||||
args: { id: { GraphQLString } },
|
args: { id: { GraphQLString } },
|
||||||
resolve (parent, { id }) {
|
resolve (parent, { id }) {
|
||||||
// code to retrieve data from db or other source
|
return _.find(books, { id });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue