1
+ const tools = require ( './arangodb-tools' ) ;
2
+
3
+ module . exports = {
4
+ get : function ( ) {
5
+ return resolvers ;
6
+ }
7
+ } ;
8
+
9
+ const resolvers = {
10
+ Query : {
11
+ droid : async ( parent , args , context , info ) =>
12
+ await tools . get ( args . id , info . returnType , info . schema ) ,
13
+ human : async ( parent , args , context , info ) =>
14
+ await tools . get ( args . id , info . returnType , info . schema ) ,
15
+ planet : async ( parent , args , context , info ) =>
16
+ await tools . get ( args . id , info . returnType , info . schema ) ,
17
+ species : async ( parent , args , context , info ) =>
18
+ await tools . get ( args . id , info . returnType , info . schema ) ,
19
+ starship : async ( parent , args , context , info ) =>
20
+ await tools . get ( args . id , info . returnType , info . schema ) ,
21
+
22
+ listOfDroids : async ( parent , args , context , info ) =>
23
+ await tools . getList ( args , info ) ,
24
+ listOfHumans : async ( parent , args , context , info ) =>
25
+ await tools . getList ( args , info ) ,
26
+ listOfPlanets : async ( parent , args , context , info ) =>
27
+ await tools . getList ( args , info ) ,
28
+ listOfSpeciess : async ( parent , args , context , info ) =>
29
+ await tools . getList ( args , info ) ,
30
+ listOfStarships : async ( parent , args , context , info ) =>
31
+ await tools . getList ( args , info ) ,
32
+
33
+ listOfCharacters : async ( parent , args , context , info ) => await tools . getList ( args , info ) ,
34
+ } ,
35
+
36
+ Mutation : {
37
+ createDroid : ( parent , args , context , info ) =>
38
+ tools . create ( true , context , args . data , info . schema . getType ( 'Droid' ) , info ) ,
39
+ createHuman : ( parent , args , context , info ) =>
40
+ tools . create ( true , context , args . data , info . schema . getType ( 'Human' ) , info ) ,
41
+ createPlanet : ( parent , args , context , info ) =>
42
+ tools . create ( true , context , args . data , info . schema . getType ( 'Planet' ) , info ) ,
43
+ createSpecies : ( parent , args , context , info ) =>
44
+ tools . create ( true , context , args . data , info . schema . getType ( 'Species' ) , info ) ,
45
+ createStarship : ( parent , args , context , info ) =>
46
+ tools . create ( true , context , args . data , info . schema . getType ( 'Starship' ) , info ) ,
47
+
48
+ createFriendsEdgeFromDroid : async ( parent , args , context , info ) =>
49
+ await tools . createEdge (
50
+ true ,
51
+ context ,
52
+ args . data . sourceID ,
53
+ info . schema . getType ( 'Droid' ) ,
54
+ 'friends' ,
55
+ args . data . targetID ,
56
+ info . schema . getType ( 'Character' ) ,
57
+ args . data . annotations ,
58
+ info ) ,
59
+ createFriendsEdgeFromHuman : async ( parent , args , context , info ) =>
60
+ await tools . createEdge (
61
+ true ,
62
+ context ,
63
+ args . data . sourceID ,
64
+ info . schema . getType ( 'Human' ) ,
65
+ 'friends' ,
66
+ args . data . targetID ,
67
+ info . schema . getType ( 'Character' ) ,
68
+ args . data . annotations ,
69
+ info ) ,
70
+ createStarshipsEdgeFromHuman : async ( parent , args , context , info ) =>
71
+ await tools . createEdge (
72
+ true ,
73
+ context ,
74
+ args . data . sourceID ,
75
+ info . schema . getType ( 'Human' ) ,
76
+ 'starships' ,
77
+ args . data . targetID ,
78
+ info . schema . getType ( 'Starship' ) ,
79
+ args . data . annotations ,
80
+ info ) ,
81
+ createOriginEdgeFromSpecies : async ( parent , args , context , info ) =>
82
+ await tools . createEdge (
83
+ true ,
84
+ context ,
85
+ args . data . sourceID ,
86
+ info . schema . getType ( 'Species' ) ,
87
+ 'origin' ,
88
+ args . data . targetID ,
89
+ info . schema . getType ( 'Planet' ) ,
90
+ args . data . annotations ,
91
+ info ) ,
92
+
93
+ updateDroid : async ( parent , args , context , info ) =>
94
+ tools . update (
95
+ true ,
96
+ context ,
97
+ args . id ,
98
+ args . data ,
99
+ info . schema . getType ( 'Droid' ) ,
100
+ info ) ,
101
+ updateHuman : async ( parent , args , context , info ) =>
102
+ tools . update (
103
+ true ,
104
+ context ,
105
+ args . id ,
106
+ args . data ,
107
+ info . schema . getType ( 'Human' ) ,
108
+ info ) ,
109
+ updatePlanet : async ( parent , args , context , info ) =>
110
+ tools . update (
111
+ true ,
112
+ context ,
113
+ args . id ,
114
+ args . data ,
115
+ info . schema . getType ( 'Planet' ) ,
116
+ info ) ,
117
+ updateSpecies : async ( parent , args , context , info ) =>
118
+ tools . update (
119
+ true ,
120
+ context ,
121
+ args . id ,
122
+ args . data ,
123
+ info . schema . getType ( 'Species' ) ,
124
+ info ) ,
125
+ updateStarship : async ( parent , args , context , info ) =>
126
+ tools . update (
127
+ true ,
128
+ context ,
129
+ args . id ,
130
+ args . data ,
131
+ info . schema . getType ( 'Starship' ) ,
132
+ info ) ,
133
+ } ,
134
+
135
+ Droid : {
136
+ id : ( parent , args , context , info ) => parent . _id ,
137
+ friends : async ( parent , args , context , info ) =>
138
+ await tools . getEdge ( parent , args , info ) ,
139
+ _friendsFromDroid : async ( parent , args , context , info ) =>
140
+ await tools . getEdge ( parent , args , info ) ,
141
+ _friendsFromCharacter : async ( parent , args , context , info ) =>
142
+ await tools . getEdge ( parent , args , info ) ,
143
+ _friendsFromHuman : async ( parent , args , context , info ) =>
144
+ await tools . getEdge ( parent , args , info ) ,
145
+ } ,
146
+ Human : {
147
+ id : ( parent , args , context , info ) => parent . _id ,
148
+ friends : async ( parent , args , context , info ) =>
149
+ await tools . getEdge ( parent , args , info ) ,
150
+ starships : async ( parent , args , context , info ) =>
151
+ await tools . getEdge ( parent , args , info ) ,
152
+ _friendsFromDroid : async ( parent , args , context , info ) =>
153
+ await tools . getEdge ( parent , args , info ) ,
154
+ _friendsFromCharacter : async ( parent , args , context , info ) =>
155
+ await tools . getEdge ( parent , args , info ) ,
156
+ _friendsFromHuman : async ( parent , args , context , info ) =>
157
+ await tools . getEdge ( parent , args , info ) ,
158
+ } ,
159
+ Planet : {
160
+ id : ( parent , args , context , info ) => parent . _id ,
161
+ _homeWorldFromCharacter : async ( parent , args , context , info ) =>
162
+ await tools . getEdge ( parent , args , info ) ,
163
+ _originFromSpecies : async ( parent , args , context , info ) =>
164
+ await tools . getEdge ( parent , args , info ) ,
165
+ } ,
166
+ Species : {
167
+ id : ( parent , args , context , info ) => parent . _id ,
168
+ origin : async ( parent , args , context , info ) =>
169
+ await tools . getEdge ( parent , args , info ) ,
170
+ _speciesFromCharacter : async ( parent , args , context , info ) =>
171
+ await tools . getEdge ( parent , args , info ) ,
172
+ } ,
173
+ Starship : {
174
+ id : ( parent , args , context , info ) => parent . _id ,
175
+ _starshipsFromHuman : async ( parent , args , context , info ) =>
176
+ await tools . getEdge ( parent , args , info ) ,
177
+ } ,
178
+
179
+ _ListOfDroids : {
180
+ totalCount : async ( parent , args , context , info ) =>
181
+ await tools . getTotalCount ( parent , args , info ) ,
182
+ isEndOfWholeList : async ( parent , args , context , info ) =>
183
+ await tools . isEndOfList ( parent , args , info ) ,
184
+ } ,
185
+ _ListOfHumans : {
186
+ totalCount : async ( parent , args , context , info ) =>
187
+ await tools . getTotalCount ( parent , args , info ) ,
188
+ isEndOfWholeList : async ( parent , args , context , info ) =>
189
+ await tools . isEndOfList ( parent , args , info ) ,
190
+ } ,
191
+ _ListOfPlanets : {
192
+ totalCount : async ( parent , args , context , info ) =>
193
+ await tools . getTotalCount ( parent , args , info ) ,
194
+ isEndOfWholeList : async ( parent , args , context , info ) =>
195
+ await tools . isEndOfList ( parent , args , info ) ,
196
+ } ,
197
+ _ListOfSpeciess : {
198
+ totalCount : async ( parent , args , context , info ) =>
199
+ await tools . getTotalCount ( parent , args , info ) ,
200
+ isEndOfWholeList : async ( parent , args , context , info ) =>
201
+ await tools . isEndOfList ( parent , args , info ) ,
202
+ } ,
203
+ _ListOfStarships : {
204
+ totalCount : async ( parent , args , context , info ) =>
205
+ await tools . getTotalCount ( parent , args , info ) ,
206
+ isEndOfWholeList : async ( parent , args , context , info ) =>
207
+ await tools . isEndOfList ( parent , args , info ) ,
208
+ } ,
209
+
210
+ _FriendsEdgeFromDroid : {
211
+ id : ( parent , args , context , info ) => parent . _id ,
212
+ source : async ( parent , args , context , info ) =>
213
+ await tools . get ( parent . _from , info . schema . getType ( 'Droid' ) , info . schema ) ,
214
+ target : async ( parent , args , context , info ) =>
215
+ await tools . get ( parent . _to , info . schema . getType ( 'Character' ) , info . schema ) ,
216
+ } ,
217
+ _FriendsEdgeFromHuman : {
218
+ id : ( parent , args , context , info ) => parent . _id ,
219
+ source : async ( parent , args , context , info ) =>
220
+ await tools . get ( parent . _from , info . schema . getType ( 'Human' ) , info . schema ) ,
221
+ target : async ( parent , args , context , info ) =>
222
+ await tools . get ( parent . _to , info . schema . getType ( 'Character' ) , info . schema ) ,
223
+ } ,
224
+ _StarshipsEdgeFromHuman : {
225
+ id : ( parent , args , context , info ) => parent . _id ,
226
+ source : async ( parent , args , context , info ) =>
227
+ await tools . get ( parent . _from , info . schema . getType ( 'Human' ) , info . schema ) ,
228
+ target : async ( parent , args , context , info ) =>
229
+ await tools . get ( parent . _to , info . schema . getType ( 'Starship' ) , info . schema ) ,
230
+ } ,
231
+ _OriginEdgeFromSpecies : {
232
+ id : ( parent , args , context , info ) => parent . _id ,
233
+ source : async ( parent , args , context , info ) =>
234
+ await tools . get ( parent . _from , info . schema . getType ( 'Species' ) , info . schema ) ,
235
+ target : async ( parent , args , context , info ) =>
236
+ await tools . get ( parent . _to , info . schema . getType ( 'Planet' ) , info . schema ) ,
237
+ } ,
238
+
239
+ Character : {
240
+ __resolveType : ( parent , args , context , info ) =>
241
+ parent . _id . split ( '/' ) [ 0 ]
242
+ } ,
243
+ }
0 commit comments