@@ -200,6 +200,41 @@ class ParseGraphQLSchema {
200200
201201 if ( typeof this . graphQLCustomTypeDefs . getTypeMap === 'function' ) {
202202 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+ ) ;
203238 Object . values ( customGraphQLSchemaTypeMap ) . forEach (
204239 ( customGraphQLSchemaType ) => {
205240 if (
@@ -212,30 +247,11 @@ class ParseGraphQLSchema {
212247 const autoGraphQLSchemaType = this . graphQLAutoSchema . getType (
213248 customGraphQLSchemaType . name
214249 ) ;
250+
215251 if (
216252 autoGraphQLSchemaType &&
217253 typeof customGraphQLSchemaType . getFields === 'function'
218254 ) {
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-
239255 Object . values ( customGraphQLSchemaType . getFields ( ) ) . forEach (
240256 ( field ) => {
241257 findAndReplaceLastType ( field , 'type' ) ;
@@ -245,10 +261,6 @@ class ParseGraphQLSchema {
245261 ...autoGraphQLSchemaType . getFields ( ) ,
246262 ...customGraphQLSchemaType . getFields ( ) ,
247263 } ;
248- } else {
249- this . graphQLAutoSchema . _typeMap [
250- customGraphQLSchemaType . name
251- ] = customGraphQLSchemaType ;
252264 }
253265 }
254266 ) ;
0 commit comments