From c82ad62e18dfa2a027a5c74952d8a0267c7cf81e Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Sat, 13 Jun 2020 17:38:03 +0300 Subject: [PATCH] Fix root level transforms --- packages/mergers/federation/src/index.ts | 12 +++++++----- packages/mergers/stitching/package.json | 2 +- packages/mergers/stitching/src/index.ts | 19 +++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/mergers/federation/src/index.ts b/packages/mergers/federation/src/index.ts index 90bc8ac46dd57..8c6097d18c0f5 100644 --- a/packages/mergers/federation/src/index.ts +++ b/packages/mergers/federation/src/index.ts @@ -45,6 +45,7 @@ const mergeUsingFederation: MergerFn = async function ({ }, }); const { schema, executor: gatewayExecutor } = await gateway.load(); + const schemaHash: any = printSchemaWithDirectives(schema); let remoteSchema = wrapSchema({ schema, executor: ({ document, info, variables, context }): any => { @@ -54,8 +55,8 @@ const mergeUsingFederation: MergerFn = async function ({ return gatewayExecutor({ document, request: { - operationName, query: documentStr, + operationName, variables, }, operationName, @@ -67,7 +68,7 @@ const mergeUsingFederation: MergerFn = async function ({ source: documentStr, operation, schema, - schemaHash: printSchemaWithDirectives(schema) as any, + schemaHash, }); }, transforms, @@ -83,9 +84,10 @@ const mergeUsingFederation: MergerFn = async function ({ updateResolversInPlace: true, }); } - remoteSchema.extensions = { - sourceMap, - }; + remoteSchema.extensions = remoteSchema.extensions || {}; + Object.defineProperty(remoteSchema.extensions, 'sourceMap', { + get: () => sourceMap, + }); return remoteSchema; }; diff --git a/packages/mergers/stitching/package.json b/packages/mergers/stitching/package.json index fb11219436af3..6ebd47e573a36 100644 --- a/packages/mergers/stitching/package.json +++ b/packages/mergers/stitching/package.json @@ -16,7 +16,7 @@ "@graphql-mesh/types": "0.2.10", "fetchache": "0.0.3", "@graphql-tools/stitch": "6.0.9", - "@graphql-tools/utils": "6.0.9" + "@graphql-tools/wrap": "6.0.9" }, "publishConfig": { "access": "public", diff --git a/packages/mergers/stitching/src/index.ts b/packages/mergers/stitching/src/index.ts index c05ab84d43004..dfbbbe7a1b91c 100644 --- a/packages/mergers/stitching/src/index.ts +++ b/packages/mergers/stitching/src/index.ts @@ -1,21 +1,20 @@ import { MergerFn } from '@graphql-mesh/types'; -import { GraphQLSchema } from 'graphql'; import { stitchSchemas } from '@graphql-tools/stitch'; -import { applySchemaTransforms } from '@graphql-tools/utils'; +import { wrapSchema } from '@graphql-tools/wrap'; -const mergeUsingStitching: MergerFn = async function ({ - rawSources, - typeDefs, - resolvers, - transforms, -}): Promise { +const mergeUsingStitching: MergerFn = async function ({ rawSources, typeDefs, resolvers, transforms }) { const unifiedSchema = stitchSchemas({ subschemas: rawSources, typeDefs, resolvers, - schemaTransforms: [schema => applySchemaTransforms(schema, transforms)], }); - (unifiedSchema.extensions as any).sourceMap = unifiedSchema.extensions.stitchingInfo.transformedSchemas; + unifiedSchema.extensions = unifiedSchema.extensions || {}; + Object.defineProperty(unifiedSchema.extensions, 'sourceMap', { + get: () => unifiedSchema.extensions.stitchingInfo.transformedSchemas, + }); + if (transforms?.length) { + return wrapSchema(unifiedSchema, transforms); + } return unifiedSchema; };