Skip to content

Commit 939b79e

Browse files
committed
Added dummy data and lodash to return by id
1 parent e673cb3 commit 939b79e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"dependencies": {
1313
"express": "^4.17.1",
1414
"express-graphql": "^0.8.0",
15-
"graphql": "^14.4.2"
15+
"graphql": "^14.4.2",
16+
"lodash": "^4.17.11"
1617
},
1718
"devDependencies": {
1819
"nodemon": "^1.19.1"

schema/schema.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Require graph QL for the schema
22
const graphql = require('graphql');
3+
const _ = require('lodash');
34

45
// Start by describing the object types
56
// we want in our schema, the relationships
@@ -8,6 +9,13 @@ const graphql = require('graphql');
89
// Define object types
910
const { GraphQLObjectType, GraphQLString, GraphQLSchema } = graphql;
1011

12+
// Dummy Data
13+
const books = [
14+
{ name: 'Name of the Wind', genre: 'Fantasy', id: '1' },
15+
{ name: 'The Final Empire', genre: 'Fantasy', id: '2' },
16+
{ name: 'The Long Earth', genre: 'Sci-Fi', id: '3' },
17+
];
18+
1119
// Define the book type
1220
const BookType = GraphQLObjectType({
1321
name: 'Book',
@@ -31,6 +39,8 @@ const RootQuery = new GraphQLObjectType({
3139
resolve(parent, args) {
3240
// Code to get data from DB / other source
3341

42+
// For now return from dummy data
43+
return _.find(books, { id: args.id });
3444
}
3545
}
3646
}

0 commit comments

Comments
 (0)