@@ -197,19 +197,60 @@ class ParseGraphQLSchema {
197
197
if ( this . graphQLCustomTypeDefs ) {
198
198
schemaDirectives . load ( this ) ;
199
199
200
- this . graphQLSchema = mergeSchemas ( {
201
- schemas : [
202
- this . graphQLSchemaDirectivesDefinitions ,
203
- this . graphQLAutoSchema ,
204
- this . graphQLCustomTypeDefs ,
205
- ] ,
206
- mergeDirectives : true ,
207
- } ) ;
200
+ if ( typeof this . graphQLCustomTypeDefs . getTypeMap === 'function' ) {
201
+ const customGraphQLSchemaTypeMap = this . graphQLCustomTypeDefs . getTypeMap ( ) ;
202
+ Object . values ( customGraphQLSchemaTypeMap ) . forEach (
203
+ customGraphQLSchemaType => {
204
+ if (
205
+ ! customGraphQLSchemaType ||
206
+ ! customGraphQLSchemaType . name ||
207
+ customGraphQLSchemaType . name . startsWith ( '__' )
208
+ ) {
209
+ return ;
210
+ }
211
+ const autoGraphQLSchemaType = this . graphQLAutoSchema . getType (
212
+ customGraphQLSchemaType . name
213
+ ) ;
214
+ if ( autoGraphQLSchemaType ) {
215
+ autoGraphQLSchemaType . _fields = {
216
+ ...autoGraphQLSchemaType . _fields ,
217
+ ...customGraphQLSchemaType . _fields ,
218
+ } ;
219
+ }
220
+ }
221
+ ) ;
222
+ this . graphQLSchema = mergeSchemas ( {
223
+ schemas : [
224
+ this . graphQLSchemaDirectivesDefinitions ,
225
+ this . graphQLCustomTypeDefs ,
226
+ this . graphQLAutoSchema ,
227
+ ] ,
228
+ mergeDirectives : true ,
229
+ } ) ;
230
+ } else if ( typeof this . graphQLCustomTypeDefs === 'function' ) {
231
+ this . graphQLSchema = await this . graphQLCustomTypeDefs ( {
232
+ directivesDefinitionsSchema : this . graphQLSchemaDirectivesDefinitions ,
233
+ autoSchema : this . graphQLAutoSchema ,
234
+ mergeSchemas,
235
+ } ) ;
236
+ } else {
237
+ this . graphQLSchema = mergeSchemas ( {
238
+ schemas : [
239
+ this . graphQLSchemaDirectivesDefinitions ,
240
+ this . graphQLAutoSchema ,
241
+ this . graphQLCustomTypeDefs ,
242
+ ] ,
243
+ mergeDirectives : true ,
244
+ } ) ;
245
+ }
208
246
209
247
const graphQLSchemaTypeMap = this . graphQLSchema . getTypeMap ( ) ;
210
248
Object . keys ( graphQLSchemaTypeMap ) . forEach ( graphQLSchemaTypeName => {
211
249
const graphQLSchemaType = graphQLSchemaTypeMap [ graphQLSchemaTypeName ] ;
212
- if ( typeof graphQLSchemaType . getFields === 'function' ) {
250
+ if (
251
+ typeof graphQLSchemaType . getFields === 'function' &&
252
+ this . graphQLCustomTypeDefs . definitions
253
+ ) {
213
254
const graphQLCustomTypeDef = this . graphQLCustomTypeDefs . definitions . find (
214
255
definition => definition . name . value === graphQLSchemaTypeName
215
256
) ;
0 commit comments