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
{ | |
book(id: "1") { | |
id | |
name | |
genre | |
} | |
} |
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
$ npm start | |
> server-graphql@1.0.0 start /Users/zegnus/Development/graph-ql-end-to-end-android/server-express-graphql | |
> nodemon server.js | |
[nodemon] 1.18.6 | |
[nodemon] to restart at any time, enter `rs` | |
[nodemon] watching: *.* | |
[nodemon] starting `node server.js` | |
listening requests on 4000 |
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
npm start |
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
module.exports = new GraphQLSchema({ | |
query: RootQuery | |
}) |
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
book(id: "2") { | |
name | |
genre | |
} |
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
RootQuery = new GraphQLObjectType({ | |
name: 'RootQueryType', | |
fields: { | |
book: { | |
type: BookType, | |
args: { id: { type: GraphQLString } }, | |
resolve(parent, args) { | |
// find data | |
return lodash.find(books, {id: args.id}) | |
} |
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
lodash = require('lodash') | |
var books = [ | |
{ name: "Book 1", genre: 'Fantasy', id: '1' }, | |
{ name: "Book 2", genre: 'Fantasy', id: '2' }, | |
{ name: "Book 3", genre: 'Sci-Fi', id: '3' }, | |
] |
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
BookType = new GraphQLObjectType({ | |
name: 'Book', | |
fields: () => ({ | |
id: { type: GraphQLString }, | |
name: { type: GraphQLString }, | |
genre: { type: GraphQLString } | |
}) | |
}) |
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
graphql = require('graphql') | |
const { | |
GraphQLObjectType, | |
GraphQLString, | |
GraphQLSchema | |
} = graphql; |
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
# Install node.js from https://nodejs.org/en/ | |
mkdir server | |
cd server | |
npm init # yes to everything | |
npm install express | |
npm install nodemon # will restart the server automatically on any file change | |
npm install graphql express-graphql | |
npm install lodash # this will help with our in-memory database queries |