-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmutation.js
More file actions
49 lines (41 loc) · 1.35 KB
/
mutation.js
File metadata and controls
49 lines (41 loc) · 1.35 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
const { GraphQLObjectType
} = require('graphql');
const _ = require('lodash');
const {movieType,directorType} = require('./types.js');
const {inputMovieType,inputDirectorType} = require('./inputtypes.js');
let {movies,directors} = require('./data.js');
const mutationType = new GraphQLObjectType({
name: 'Mutation',
fields: {
addMovie: {
type: movieType,
args: {
input: { type: inputMovieType }
},
resolve: function (source, args) {
let movie = {
id: args.input.id,
name: args.input.name,
year: args.input.year,
directorId: args.input.directorId};
movies.push(movie);
return _.find(movies, { id: args.input.id });
}
},
addDirector: {
type: directorType,
args: {
input: { type: inputDirectorType }
},
resolve: function (source, args) {
let director = {
id: args.input.id,
name: args.input.name,
age: args.input.age};
directors.push(director);
return _.find(directors, { id: args.input.id });
}
}
}
});
exports.mutationType = mutationType;