-
Notifications
You must be signed in to change notification settings - Fork 5
/
Pokemon.js
97 lines (90 loc) · 2.27 KB
/
Pokemon.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import Parse from 'parse/node';
import {
GraphQLID,
GraphQLObjectType,
GraphQLString,
GraphQLNonNull,
GraphQLList,
GraphQLBoolean,
} from 'graphql';
const Pokemon = Parse.Object.extend('Pokemon');
const PokemonType = new GraphQLObjectType({
name: 'Pokemon',
description: 'A concise description of what Pokemon is',
fields: () => ({
id: {
type: GraphQLID,
},
name: {
type: GraphQLString,
resolve: pokemon => pokemon.get('name'),
},
pokenumber: {
type: GraphQLID,
resolve: pokemon => pokemon.get('pokenumber'),
},
preview_url: {
type: GraphQLString,
resolve: pokemon => pokemon.get('preview_url'),
},
marker_url: {
type: GraphQLString,
resolve: pokemon => pokemon.get('marker_url'),
},
seen_in_afternoon: {
type: GraphQLBoolean,
resolve: pokemon => pokemon.get('seen_in_afternoon'),
},
seen_in_morning: {
type: GraphQLBoolean,
resolve: pokemon => pokemon.get('seen_in_morning'),
},
seen_in_evening: {
type: GraphQLBoolean,
resolve: pokemon => pokemon.get('seen_in_evening'),
},
kinds: {
type: new GraphQLList(GraphQLString),
resolve: pokemon => pokemon.get('kinds').split(','),
},
}),
});
Pokemon.SchemaType = PokemonType;
Pokemon.RootQuery = {
type: new GraphQLList(Pokemon.SchemaType),
resolve: (_, args, { Query }) => {
const query = new Query(Pokemon);
return query.find();
},
};
Pokemon.Mutations = {
addPokemon: {
type: Pokemon.SchemaType,
description: 'Create a new instance of Pokemon',
args: {
text: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: (_, { text }, { Query, user }) => {
const pokemon = new Query(Pokemon).create({ text });
if (user) {
pokemon.setACL(new Parse.ACL(user));
}
return pokemon.save().then(td => td);
},
},
deletePokemon: {
type: Pokemon.SchemaType,
description: 'Delete an instance of Pokemon',
args: {
id: { type: new GraphQLNonNull(GraphQLID) },
},
resolve: (_, { id }, { Query }) =>
new Query(Pokemon).get(id).then((pokemon) => {
if (pokemon) {
return pokemon.destroy();
}
return pokemon;
}),
},
};
export default Pokemon;