-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c63f84d
commit c8372d5
Showing
6 changed files
with
724 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const graphql = require('graphql'); | ||
const _ = require('lodash'); | ||
|
||
const { GraphQLObjectType, GraphQLString, GraphQLSchema } = graphql; | ||
|
||
// dummy data | ||
var 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, args) { | ||
// code to get data from db / other source | ||
return _.find(books, { id: args.id }); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
module.exports = new GraphQLSchema({ | ||
query: RootQuery | ||
}); |
Oops, something went wrong.