|
1 | 1 | import Parse from 'parse/node'; |
2 | 2 | import { GraphQLSchema, GraphQLObjectType, DocumentNode, GraphQLNamedType } from 'graphql'; |
3 | | -import { stitchSchemas } from '@graphql-tools/stitch'; |
| 3 | +import { mergeSchemas } from '@graphql-tools/schema'; |
| 4 | +import { mergeTypeDefs } from '@graphql-tools/merge'; |
4 | 5 | import { isDeepStrictEqual } from 'util'; |
5 | | -import { SchemaDirectiveVisitor } from '@graphql-tools/utils'; |
6 | 6 | import requiredParameter from '../requiredParameter'; |
7 | 7 | import * as defaultGraphQLTypes from './loaders/defaultGraphQLTypes'; |
8 | 8 | import * as parseClassTypes from './loaders/parseClassTypes'; |
@@ -203,9 +203,8 @@ class ParseGraphQLSchema { |
203 | 203 |
|
204 | 204 | if (this.graphQLCustomTypeDefs) { |
205 | 205 | schemaDirectives.load(this); |
206 | | - |
207 | 206 | if (typeof this.graphQLCustomTypeDefs.getTypeMap === 'function') { |
208 | | - // In following code we use underscore attr to avoid js var un ref |
| 207 | + // In following code we use underscore attr to keep the direct variable reference |
209 | 208 | const customGraphQLSchemaTypeMap = this.graphQLCustomTypeDefs._typeMap; |
210 | 209 | const findAndReplaceLastType = (parent, key) => { |
211 | 210 | if (parent[key].name) { |
@@ -280,51 +279,18 @@ class ParseGraphQLSchema { |
280 | 279 | this.graphQLSchema = await this.graphQLCustomTypeDefs({ |
281 | 280 | directivesDefinitionsSchema: this.graphQLSchemaDirectivesDefinitions, |
282 | 281 | autoSchema: this.graphQLAutoSchema, |
283 | | - stitchSchemas, |
| 282 | + graphQLSchemaDirectives: this.graphQLSchemaDirectives, |
284 | 283 | }); |
285 | 284 | } else { |
286 | | - this.graphQLSchema = stitchSchemas({ |
287 | | - schemas: [ |
288 | | - this.graphQLSchemaDirectivesDefinitions, |
289 | | - this.graphQLAutoSchema, |
| 285 | + this.graphQLSchema = mergeSchemas({ |
| 286 | + schemas: [this.graphQLAutoSchema], |
| 287 | + typeDefs: mergeTypeDefs([ |
290 | 288 | this.graphQLCustomTypeDefs, |
291 | | - ], |
292 | | - mergeDirectives: true, |
| 289 | + this.graphQLSchemaDirectivesDefinitions, |
| 290 | + ]), |
293 | 291 | }); |
| 292 | + this.graphQLSchema = this.graphQLSchemaDirectives(this.graphQLSchema); |
294 | 293 | } |
295 | | - |
296 | | - // Only merge directive when string schema provided |
297 | | - const graphQLSchemaTypeMap = this.graphQLSchema.getTypeMap(); |
298 | | - Object.keys(graphQLSchemaTypeMap).forEach(graphQLSchemaTypeName => { |
299 | | - const graphQLSchemaType = graphQLSchemaTypeMap[graphQLSchemaTypeName]; |
300 | | - if ( |
301 | | - typeof graphQLSchemaType.getFields === 'function' && |
302 | | - this.graphQLCustomTypeDefs.definitions |
303 | | - ) { |
304 | | - const graphQLCustomTypeDef = this.graphQLCustomTypeDefs.definitions.find( |
305 | | - definition => definition.name.value === graphQLSchemaTypeName |
306 | | - ); |
307 | | - if (graphQLCustomTypeDef) { |
308 | | - const graphQLSchemaTypeFieldMap = graphQLSchemaType.getFields(); |
309 | | - Object.keys(graphQLSchemaTypeFieldMap).forEach(graphQLSchemaTypeFieldName => { |
310 | | - const graphQLSchemaTypeField = graphQLSchemaTypeFieldMap[graphQLSchemaTypeFieldName]; |
311 | | - if (!graphQLSchemaTypeField.astNode) { |
312 | | - const astNode = graphQLCustomTypeDef.fields.find( |
313 | | - field => field.name.value === graphQLSchemaTypeFieldName |
314 | | - ); |
315 | | - if (astNode) { |
316 | | - graphQLSchemaTypeField.astNode = astNode; |
317 | | - } |
318 | | - } |
319 | | - }); |
320 | | - } |
321 | | - } |
322 | | - }); |
323 | | - |
324 | | - SchemaDirectiveVisitor.visitSchemaDirectives( |
325 | | - this.graphQLSchema, |
326 | | - this.graphQLSchemaDirectives |
327 | | - ); |
328 | 294 | } else { |
329 | 295 | this.graphQLSchema = this.graphQLAutoSchema; |
330 | 296 | } |
|
0 commit comments