@@ -200,6 +200,41 @@ class ParseGraphQLSchema {
200
200
201
201
if ( typeof this . graphQLCustomTypeDefs . getTypeMap === 'function' ) {
202
202
const customGraphQLSchemaTypeMap = this . graphQLCustomTypeDefs . getTypeMap ( ) ;
203
+ const findAndReplaceLastType = ( parent , key ) = > {
204
+ if ( parent [ key ] . name ) {
205
+ if (
206
+ this . graphQLAutoSchema . getType ( parent [ key ] . name ) &&
207
+ this . graphQLAutoSchema . getType ( parent [ key ] . name ) !== parent [ key ]
208
+ ) {
209
+ // To avoid unresolved field on overloaded schema
210
+ // replace the final type with the auto schema one
211
+ parent [ key ] = this . graphQLAutoSchema . getType ( parent [ key ] . name ) ;
212
+ }
213
+ } else {
214
+ if ( parent [ key ] . ofType ) {
215
+ findAndReplaceLastType ( parent [ key ] , 'ofType' ) ;
216
+ }
217
+ }
218
+ } ;
219
+ Object . values ( customGraphQLSchemaTypeMap ) . forEach (
220
+ ( customGraphQLSchemaType ) => {
221
+ if (
222
+ ! customGraphQLSchemaType ||
223
+ ! customGraphQLSchemaType . name ||
224
+ customGraphQLSchemaType . name . startsWith ( '__' )
225
+ ) {
226
+ return ;
227
+ }
228
+ const autoGraphQLSchemaType = this . graphQLAutoSchema . getType (
229
+ customGraphQLSchemaType . name
230
+ ) ;
231
+ if ( ! autoGraphQLSchemaType ) {
232
+ this . graphQLAutoSchema . _typeMap [
233
+ customGraphQLSchemaType . name
234
+ ] = customGraphQLSchemaType ;
235
+ }
236
+ }
237
+ ) ;
203
238
Object . values ( customGraphQLSchemaTypeMap ) . forEach (
204
239
( customGraphQLSchemaType ) => {
205
240
if (
@@ -212,30 +247,11 @@ class ParseGraphQLSchema {
212
247
const autoGraphQLSchemaType = this . graphQLAutoSchema . getType (
213
248
customGraphQLSchemaType . name
214
249
) ;
250
+
215
251
if (
216
252
autoGraphQLSchemaType &&
217
253
typeof customGraphQLSchemaType . getFields === 'function'
218
254
) {
219
- const findAndReplaceLastType = ( parent , key ) => {
220
- if ( parent [ key ] . name ) {
221
- if (
222
- this . graphQLAutoSchema . getType ( parent [ key ] . name ) &&
223
- this . graphQLAutoSchema . getType ( parent [ key ] . name ) !==
224
- parent [ key ]
225
- ) {
226
- // To avoid unresolved field on overloaded schema
227
- // replace the final type with the auto schema one
228
- parent [ key ] = this . graphQLAutoSchema . getType (
229
- parent [ key ] . name
230
- ) ;
231
- }
232
- } else {
233
- if ( parent [ key ] . ofType ) {
234
- findAndReplaceLastType ( parent [ key ] , 'ofType' ) ;
235
- }
236
- }
237
- } ;
238
-
239
255
Object . values ( customGraphQLSchemaType . getFields ( ) ) . forEach (
240
256
( field ) => {
241
257
findAndReplaceLastType ( field , 'type' ) ;
@@ -245,10 +261,6 @@ class ParseGraphQLSchema {
245
261
...autoGraphQLSchemaType . getFields ( ) ,
246
262
...customGraphQLSchemaType . getFields ( ) ,
247
263
} ;
248
- } else {
249
- this . graphQLAutoSchema . _typeMap [
250
- customGraphQLSchemaType . name
251
- ] = customGraphQLSchemaType ;
252
264
}
253
265
}
254
266
) ;
0 commit comments