Skip to content

Commit 45dac20

Browse files
committed
adding authors & books type of list before init mlab DB
1 parent d473ba2 commit 45dac20

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

server/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const express = require('express');
2-
2+
// const graphiql = require('graphql')
33
const graphqlHTTP = require('express-graphql');
44
const schema = require('./schema/schema')
55

66
const app = express();
77

88
app.use('/graphql', graphqlHTTP({
99
schema,
10-
graphiql
10+
// graphiql
1111
}))
1212
app.listen(4000, ()=> {
1313
console.log('object')

server/schema/schema.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
1-
const {GraphQLString , GraphQLObjectType , GraphQLID , GraphQLSchema, GraphQLInt} = require('graphql');
1+
const {GraphQLString , GraphQLObjectType , GraphQLID , GraphQLSchema, GraphQLInt, GraphQLList} = require('graphql');
22
const _ = require('lodash');
33

44
const books = [
55
{
66
id: '1',
77
name: 'test 1',
8-
genre: 'test'
8+
genre: 'test',
9+
authorid: '2'
910
},
1011
{
1112
id: '3',
1213
name: 'test 2',
13-
genre: 'test'
14+
genre: 'test',
15+
authorid: '2'
1416
},
1517
{
1618
id: '3',
1719
name: 'test 3',
18-
genre: 'test'
20+
genre: 'test',
21+
authorid: '2'
1922
},
2023
];
2124

2225
const authors = [
2326
{
2427
id: '1',
2528
name: 'test 4',
26-
age: ''
29+
age:66
2730
},
2831
{
29-
id: '3',
32+
id: '2',
3033
name: 'test 5',
31-
genre: 'test'
34+
age: 43
3235
},
3336
{
3437
id: '3',
3538
name: 'test 6',
36-
genre: 'test'
39+
age: 34
3740
},
3841
];
3942

@@ -53,6 +56,12 @@ const authorType = new GraphQLObjectType({
5356
id : {type : GraphQLID},
5457
name: {type : GraphQLString},
5558
age: {type: GraphQLInt},
59+
books: {
60+
type : new GraphQLList(bookType),
61+
resolve(parent, args){
62+
return null
63+
}
64+
}
5665

5766
})
5867
})
@@ -70,13 +79,26 @@ const rootQuery = new GraphQLObjectType({
7079
},
7180
resolve(parent, args){
7281
// GET data from db
82+
console.log(parent)
7383
}
7484
},
7585
author:{
7686
type : authorType,
7787
args:{
7888

7989
}
90+
},
91+
books: {
92+
type : new GraphQLList(bookType),
93+
resolve(parent, args){
94+
return books
95+
}
96+
},
97+
authors: {
98+
type: new GraphQLList(authorType),
99+
resolve(){
100+
return authors
101+
}
80102
}
81103
}
82104
})

0 commit comments

Comments
 (0)