@@ -12,7 +12,11 @@ import {
12
12
useAuthDirective ,
13
13
isCypherField
14
14
} from '../../directives' ;
15
- import { getPrimaryKey } from './selection' ;
15
+ import {
16
+ getPrimaryKey ,
17
+ buildNodeSelectionInputType ,
18
+ buildNodeSelectionInputTypes
19
+ } from './selection' ;
16
20
import { shouldAugmentType } from '../../augment' ;
17
21
import { OperationType } from '../../types/types' ;
18
22
import {
@@ -48,6 +52,7 @@ export const augmentNodeMutationAPI = ({
48
52
propertyInputValues,
49
53
generatedTypeMap,
50
54
operationTypeMap,
55
+ typeDefinitionMap,
51
56
typeExtensionDefinitionMap,
52
57
config
53
58
} ) => {
@@ -78,89 +83,28 @@ export const augmentNodeMutationAPI = ({
78
83
} ) ;
79
84
} ) ;
80
85
}
81
- return [ operationTypeMap , generatedTypeMap ] ;
82
- } ;
83
-
84
- /**
85
- * Given the results of augmentNodeTypeFields, builds the AST
86
- * definition for a Mutation operation field of a given
87
- * NodeMutation name
88
- */
89
- const buildNodeMutationField = ( {
90
- mutationType,
91
- mutationAction = '' ,
92
- primaryKey,
93
- typeName,
94
- propertyInputValues,
95
- operationTypeMap,
96
- typeExtensionDefinitionMap,
97
- config
98
- } ) => {
99
- const mutationFields = mutationType . fields ;
100
- const mutationName = `${ mutationAction } ${ typeName } ` ;
101
- const mutationTypeName = mutationType ? mutationType . name . value : '' ;
102
- const mutationTypeExtensions = typeExtensionDefinitionMap [ mutationTypeName ] ;
103
- if (
104
- ! getFieldDefinition ( {
105
- fields : mutationFields ,
106
- name : mutationName
107
- } ) &&
108
- ! getTypeExtensionFieldDefinition ( {
109
- typeExtensions : mutationTypeExtensions ,
110
- name : typeName
111
- } )
112
- ) {
113
- const mutationConfig = {
114
- name : buildName ( { name : mutationName } ) ,
115
- args : buildNodeMutationArguments ( {
116
- operationName : mutationAction ,
117
- primaryKey,
118
- args : propertyInputValues
119
- } ) ,
120
- type : buildNamedType ( {
121
- name : typeName
122
- } ) ,
123
- directives : buildNodeMutationDirectives ( {
124
- mutationAction,
125
- typeName,
126
- config
127
- } )
128
- } ;
129
- let mutationField = undefined ;
130
- let mutationDescriptionUrl = '' ;
131
- if ( mutationAction === NodeMutation . CREATE ) {
132
- mutationField = mutationConfig ;
133
- mutationDescriptionUrl =
134
- '[creating](https://neo4j.com/docs/cypher-manual/4.1/clauses/create/#create-nodes)' ;
135
- } else if ( mutationAction === NodeMutation . UPDATE ) {
136
- if ( primaryKey && mutationConfig . args . length > 1 ) {
137
- mutationField = mutationConfig ;
138
- mutationDescriptionUrl =
139
- '[updating](https://neo4j.com/docs/cypher-manual/4.1/clauses/set/#set-update-a-property)' ;
140
- }
141
- } else if ( mutationAction === NodeMutation . MERGE ) {
142
- if ( primaryKey ) {
143
- mutationField = mutationConfig ;
144
- mutationDescriptionUrl =
145
- '[merging](https://neo4j.com/docs/cypher-manual/4.1/clauses/merge/#query-merge-node-derived)' ;
146
- }
147
- } else if ( mutationAction === NodeMutation . DELETE ) {
148
- if ( primaryKey ) {
149
- mutationField = mutationConfig ;
150
- mutationDescriptionUrl =
151
- '[deleting](https://neo4j.com/docs/cypher-manual/4.1/clauses/delete/#delete-delete-single-node)' ;
152
- }
153
- }
154
- if ( mutationField ) {
155
- mutationField . description = buildDescription ( {
156
- value : `[Generated mutation](${ GRANDSTACK_DOCS_SCHEMA_AUGMENTATION } /#${ mutationAction . toLowerCase ( ) } ) for ${ mutationDescriptionUrl } a ${ typeName } node.` ,
157
- config
158
- } ) ;
159
- mutationFields . push ( buildField ( mutationField ) ) ;
160
- }
161
- operationTypeMap [ OperationType . MUTATION ] . fields = mutationFields ;
86
+ if ( config . experimental === true ) {
87
+ generatedTypeMap = buildNodeSelectionInputTypes ( {
88
+ definition,
89
+ typeName,
90
+ propertyInputValues,
91
+ generatedTypeMap,
92
+ typeDefinitionMap,
93
+ typeExtensionDefinitionMap,
94
+ config
95
+ } ) ;
96
+ } else {
97
+ generatedTypeMap = buildNodeSelectionInputType ( {
98
+ definition,
99
+ typeName,
100
+ propertyInputValues,
101
+ generatedTypeMap,
102
+ typeDefinitionMap,
103
+ typeExtensionDefinitionMap,
104
+ config
105
+ } ) ;
162
106
}
163
- return operationTypeMap ;
107
+ return [ operationTypeMap , generatedTypeMap ] ;
164
108
} ;
165
109
166
110
/**
@@ -258,6 +202,145 @@ const buildNodeMutationArguments = ({
258
202
) ;
259
203
} ;
260
204
205
+ const buildNodeMutationObjectArguments = ( { typeName, operationName = '' } ) => {
206
+ const args = [ ] ;
207
+ const nodeSelectionConfig = {
208
+ name : 'where' ,
209
+ type : {
210
+ name : `_${ typeName } Where` ,
211
+ wrappers : {
212
+ [ TypeWrappers . NON_NULL_NAMED_TYPE ] : true
213
+ }
214
+ }
215
+ } ;
216
+ const propertyInputConfig = {
217
+ name : 'data' ,
218
+ type : {
219
+ name : `_${ typeName } Data` ,
220
+ wrappers : {
221
+ [ TypeWrappers . NON_NULL_NAMED_TYPE ] : true
222
+ }
223
+ }
224
+ } ;
225
+ if ( operationName === NodeMutation . CREATE ) {
226
+ args . push ( propertyInputConfig ) ;
227
+ } else if ( operationName === NodeMutation . UPDATE ) {
228
+ args . push ( nodeSelectionConfig ) ;
229
+ args . push ( propertyInputConfig ) ;
230
+ } else if ( operationName === NodeMutation . MERGE ) {
231
+ const keySelectionInputConfig = {
232
+ name : 'where' ,
233
+ type : {
234
+ name : `_${ typeName } Keys` ,
235
+ wrappers : {
236
+ [ TypeWrappers . NON_NULL_NAMED_TYPE ] : true
237
+ }
238
+ }
239
+ } ;
240
+ args . push ( keySelectionInputConfig ) ;
241
+ args . push ( propertyInputConfig ) ;
242
+ } else if ( operationName === NodeMutation . DELETE ) {
243
+ args . push ( nodeSelectionConfig ) ;
244
+ }
245
+ return args . map ( arg =>
246
+ buildInputValue ( {
247
+ name : buildName ( { name : arg . name } ) ,
248
+ type : buildNamedType ( arg . type )
249
+ } )
250
+ ) ;
251
+ } ;
252
+
253
+ /**
254
+ * Given the results of augmentNodeTypeFields, builds the AST
255
+ * definition for a Mutation operation field of a given
256
+ * NodeMutation name
257
+ */
258
+ const buildNodeMutationField = ( {
259
+ mutationType,
260
+ mutationAction = '' ,
261
+ primaryKey,
262
+ typeName,
263
+ propertyInputValues,
264
+ operationTypeMap,
265
+ typeExtensionDefinitionMap,
266
+ config
267
+ } ) => {
268
+ const mutationFields = mutationType . fields ;
269
+ const mutationName = `${ mutationAction } ${ typeName } ` ;
270
+ const mutationTypeName = mutationType ? mutationType . name . value : '' ;
271
+ const mutationTypeExtensions = typeExtensionDefinitionMap [ mutationTypeName ] ;
272
+ if (
273
+ ! getFieldDefinition ( {
274
+ fields : mutationFields ,
275
+ name : mutationName
276
+ } ) &&
277
+ ! getTypeExtensionFieldDefinition ( {
278
+ typeExtensions : mutationTypeExtensions ,
279
+ name : typeName
280
+ } )
281
+ ) {
282
+ let mutationArgs = [ ] ;
283
+ if ( config . experimental === true ) {
284
+ mutationArgs = buildNodeMutationObjectArguments ( {
285
+ typeName,
286
+ operationName : mutationAction
287
+ } ) ;
288
+ } else {
289
+ mutationArgs = buildNodeMutationArguments ( {
290
+ operationName : mutationAction ,
291
+ primaryKey,
292
+ args : propertyInputValues
293
+ } ) ;
294
+ }
295
+ const mutationConfig = {
296
+ name : buildName ( { name : mutationName } ) ,
297
+ args : mutationArgs ,
298
+ type : buildNamedType ( {
299
+ name : typeName
300
+ } ) ,
301
+ directives : buildNodeMutationDirectives ( {
302
+ mutationAction,
303
+ typeName,
304
+ config
305
+ } )
306
+ } ;
307
+ let mutationField = undefined ;
308
+ let mutationDescriptionUrl = '' ;
309
+ if ( mutationAction === NodeMutation . CREATE ) {
310
+ mutationField = mutationConfig ;
311
+ mutationDescriptionUrl =
312
+ '[creating](https://neo4j.com/docs/cypher-manual/4.1/clauses/create/#create-nodes)' ;
313
+ } else if ( mutationAction === NodeMutation . UPDATE ) {
314
+ if ( primaryKey && mutationConfig . args . length > 1 ) {
315
+ mutationField = mutationConfig ;
316
+ mutationDescriptionUrl =
317
+ '[updating](https://neo4j.com/docs/cypher-manual/4.1/clauses/set/#set-update-a-property)' ;
318
+ }
319
+ } else if ( mutationAction === NodeMutation . MERGE ) {
320
+ if ( primaryKey ) {
321
+ mutationField = mutationConfig ;
322
+ mutationDescriptionUrl =
323
+ '[merging](https://neo4j.com/docs/cypher-manual/4.1/clauses/merge/#query-merge-node-derived)' ;
324
+ }
325
+ } else if ( mutationAction === NodeMutation . DELETE ) {
326
+ if ( primaryKey ) {
327
+ mutationField = mutationConfig ;
328
+ mutationDescriptionUrl =
329
+ '[deleting](https://neo4j.com/docs/cypher-manual/4.1/clauses/delete/#delete-delete-single-node)' ;
330
+ }
331
+ }
332
+ if ( mutationField ) {
333
+ mutationField . description = buildDescription ( {
334
+ value : `[Generated mutation](${ GRANDSTACK_DOCS_SCHEMA_AUGMENTATION } /#${ mutationAction . toLowerCase ( ) } ) for ${ mutationDescriptionUrl } a ${ typeName } node.` ,
335
+ config
336
+ } ) ;
337
+ mutationFields . push ( buildField ( mutationField ) ) ;
338
+ }
339
+ operationTypeMap [ OperationType . MUTATION ] . fields = mutationFields ;
340
+ }
341
+ return operationTypeMap ;
342
+ } ;
343
+
261
344
/**
262
345
* Builds the AST definitions for directive instances used by
263
346
* generated node Mutation fields of NodeMutation names
0 commit comments