-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.js
More file actions
61 lines (51 loc) · 1.3 KB
/
schema.js
File metadata and controls
61 lines (51 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var {GraphQLObjectType, GraphQLString, GraphQLSchema, GraphQLID, GraphQLList} = require('graphql');
var Genre = require('./models/genre')
var GenreType = new GraphQLObjectType({
name: 'Genre',
fields :() => ({
id : {type : GraphQLString},
title: {type :GraphQLString},
date: { type:GraphQLString}
})
})
var RootQuery = new GraphQLObjectType({
name : 'RootQueryType',
fields: {
genres :{
type : new GraphQLList(GenreType),
resolve(parent , args){
return Genre.find({})
}
},
genre : {
type : GenreType,
args : {
id : {type : GraphQLString}
},
resolve(parent, args){
return Genre.findById(args.id)
}
}
}
})
var Mutation = new GraphQLObjectType({
name : 'Mutation',
fields: {
addGenre :{
type : GenreType,
args : {
title : {type :GraphQLString}
},
resolve(parent , args){
var genre = new Genre({
title : args.title
})
return genre.save()
}
}
}
})
module.exports = new GraphQLSchema({
query : RootQuery,
mutation: Mutation
})