@@ -200,7 +200,7 @@ class ParseGraphQLSchema {
200
200
if ( typeof this . graphQLCustomTypeDefs . getTypeMap === 'function' ) {
201
201
const customGraphQLSchemaTypeMap = this . graphQLCustomTypeDefs . getTypeMap ( ) ;
202
202
Object . values ( customGraphQLSchemaTypeMap ) . forEach (
203
- customGraphQLSchemaType => {
203
+ ( customGraphQLSchemaType ) => {
204
204
if (
205
205
! customGraphQLSchemaType ||
206
206
! customGraphQLSchemaType . name ||
@@ -215,40 +215,45 @@ class ParseGraphQLSchema {
215
215
autoGraphQLSchemaType &&
216
216
typeof customGraphQLSchemaType . getFields === 'function'
217
217
) {
218
- const findAndAddLastType = type => {
219
- if ( type . name ) {
220
- if ( ! this . graphQLAutoSchema . getType ( type ) ) {
221
- // To avoid schema stitching (Unknow type) bug on variables
222
- // transfer the final type to the Auto Schema
223
- this . graphQLAutoSchema . _typeMap [ type . name ] = type ;
218
+ const findAndReplaceLastType = ( parent , key ) => {
219
+ if ( parent [ key ] . name ) {
220
+ if (
221
+ this . graphQLAutoSchema . getType ( parent [ key ] . name ) &&
222
+ this . graphQLAutoSchema . getType ( parent [ key ] . name ) !==
223
+ parent [ key ]
224
+ ) {
225
+ // To avoid unresolved field on overloaded schema
226
+ // replace the final type with the auto schema one
227
+ parent [ key ] = this . graphQLAutoSchema . getType (
228
+ parent [ key ] . name
229
+ ) ;
224
230
}
225
231
} else {
226
- if ( type . ofType ) {
227
- findAndAddLastType ( type . ofType ) ;
232
+ if ( parent [ key ] . ofType ) {
233
+ findAndReplaceLastType ( parent [ key ] , ' ofType' ) ;
228
234
}
229
235
}
230
236
} ;
237
+
231
238
Object . values ( customGraphQLSchemaType . getFields ( ) ) . forEach (
232
- field => {
233
- findAndAddLastType ( field . type ) ;
234
- if ( field . args ) {
235
- field . args . forEach ( arg => {
236
- findAndAddLastType ( arg . type ) ;
237
- } ) ;
238
- }
239
+ ( field ) => {
240
+ findAndReplaceLastType ( field , 'type' ) ;
239
241
}
240
242
) ;
241
243
autoGraphQLSchemaType . _fields = {
242
- ...autoGraphQLSchemaType . _fields ,
243
- ...customGraphQLSchemaType . _fields ,
244
+ ...autoGraphQLSchemaType . getFields ( ) ,
245
+ ...customGraphQLSchemaType . getFields ( ) ,
244
246
} ;
247
+ } else {
248
+ this . graphQLAutoSchema . _typeMap [
249
+ customGraphQLSchemaType . name
250
+ ] = customGraphQLSchemaType ;
245
251
}
246
252
}
247
253
) ;
248
254
this . graphQLSchema = mergeSchemas ( {
249
255
schemas : [
250
256
this . graphQLSchemaDirectivesDefinitions ,
251
- this . graphQLCustomTypeDefs ,
252
257
this . graphQLAutoSchema ,
253
258
] ,
254
259
mergeDirectives : true ,
@@ -271,24 +276,24 @@ class ParseGraphQLSchema {
271
276
}
272
277
273
278
const graphQLSchemaTypeMap = this . graphQLSchema . getTypeMap ( ) ;
274
- Object . keys ( graphQLSchemaTypeMap ) . forEach ( graphQLSchemaTypeName => {
279
+ Object . keys ( graphQLSchemaTypeMap ) . forEach ( ( graphQLSchemaTypeName ) => {
275
280
const graphQLSchemaType = graphQLSchemaTypeMap [ graphQLSchemaTypeName ] ;
276
281
if (
277
282
typeof graphQLSchemaType . getFields === 'function' &&
278
283
this . graphQLCustomTypeDefs . definitions
279
284
) {
280
285
const graphQLCustomTypeDef = this . graphQLCustomTypeDefs . definitions . find (
281
- definition => definition . name . value === graphQLSchemaTypeName
286
+ ( definition ) => definition . name . value === graphQLSchemaTypeName
282
287
) ;
283
288
if ( graphQLCustomTypeDef ) {
284
289
const graphQLSchemaTypeFieldMap = graphQLSchemaType . getFields ( ) ;
285
290
Object . keys ( graphQLSchemaTypeFieldMap ) . forEach (
286
- graphQLSchemaTypeFieldName => {
291
+ ( graphQLSchemaTypeFieldName ) => {
287
292
const graphQLSchemaTypeField =
288
293
graphQLSchemaTypeFieldMap [ graphQLSchemaTypeFieldName ] ;
289
294
if ( ! graphQLSchemaTypeField . astNode ) {
290
295
const astNode = graphQLCustomTypeDef . fields . find (
291
- field => field . name . value === graphQLSchemaTypeFieldName
296
+ ( field ) => field . name . value === graphQLSchemaTypeFieldName
292
297
) ;
293
298
if ( astNode ) {
294
299
graphQLSchemaTypeField . astNode = astNode ;
@@ -319,7 +324,9 @@ class ParseGraphQLSchema {
319
324
) {
320
325
if (
321
326
( ! ignoreReserved && RESERVED_GRAPHQL_TYPE_NAMES . includes ( type . name ) ) ||
322
- this . graphQLTypes . find ( existingType => existingType . name === type . name ) ||
327
+ this . graphQLTypes . find (
328
+ ( existingType ) => existingType . name === type . name
329
+ ) ||
323
330
( ! ignoreConnection && type . name . endsWith ( 'Connection' ) )
324
331
) {
325
332
const message = `Type ${type . name } could not be added to the auto schema because it collided with an existing type . `;
@@ -409,20 +416,20 @@ class ParseGraphQLSchema {
409
416
if (Array.isArray(enabledForClasses) || Array.isArray(disabledForClasses)) {
410
417
let includedClasses = allClasses;
411
418
if (enabledForClasses) {
412
- includedClasses = allClasses.filter(clazz => {
419
+ includedClasses = allClasses.filter(( clazz) => {
413
420
return enabledForClasses.includes(clazz.className);
414
421
});
415
422
}
416
423
if (disabledForClasses) {
417
424
// Classes included in ` enabledForClasses ` that
418
425
// are also present in ` disabledForClasses ` will
419
426
// still be filtered out
420
- includedClasses = includedClasses.filter(clazz => {
427
+ includedClasses = includedClasses.filter(( clazz) => {
421
428
return !disabledForClasses.includes(clazz.className);
422
429
});
423
430
}
424
431
425
- this.isUsersClassDisabled = !includedClasses.some(clazz => {
432
+ this.isUsersClassDisabled = !includedClasses.some(( clazz) => {
426
433
return clazz.className === '_User';
427
434
});
428
435
@@ -467,19 +474,19 @@ class ParseGraphQLSchema {
467
474
}
468
475
};
469
476
470
- return parseClasses.sort(sortClasses).map(parseClass => {
477
+ return parseClasses.sort(sortClasses).map(( parseClass) => {
471
478
let parseClassConfig;
472
479
if (classConfigs) {
473
480
parseClassConfig = classConfigs.find(
474
- c => c.className === parseClass.className
481
+ (c) => c.className === parseClass.className
475
482
);
476
483
}
477
484
return [parseClass, parseClassConfig];
478
485
});
479
486
}
480
487
481
488
async _getFunctionNames() {
482
- return await getFunctionNames(this.appId).filter(functionName => {
489
+ return await getFunctionNames(this.appId).filter(( functionName) => {
483
490
if (/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(functionName)) {
484
491
return true;
485
492
} else {
0 commit comments