From 359da614219cefd639b262eaa1dec54216db58fb Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Mon, 13 Jan 2025 16:16:37 +0300 Subject: [PATCH] fix(transform-hive): filter non-existing delegated argument --- .changeset/pink-crews-fix.md | 5 ++++ packages/legacy/transforms/hive/src/index.ts | 29 ++++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 .changeset/pink-crews-fix.md diff --git a/.changeset/pink-crews-fix.md b/.changeset/pink-crews-fix.md new file mode 100644 index 0000000000000..6815c6e768361 --- /dev/null +++ b/.changeset/pink-crews-fix.md @@ -0,0 +1,5 @@ +--- +'@graphql-mesh/transform-hive': patch +--- + +Remove non-existing delegated argument from the document while reporting to Hive diff --git a/packages/legacy/transforms/hive/src/index.ts b/packages/legacy/transforms/hive/src/index.ts index 013d6862a8269..9fbe248da266d 100644 --- a/packages/legacy/transforms/hive/src/index.ts +++ b/packages/legacy/transforms/hive/src/index.ts @@ -1,9 +1,9 @@ -import { Kind, visit, type ExecutionResult, type GraphQLSchema } from 'graphql'; +import { Kind, visit, visitWithTypeInfo, type ExecutionResult, type GraphQLSchema } from 'graphql'; import { createHive, type HiveClient, type HivePluginOptions } from '@graphql-hive/core'; import { process } from '@graphql-mesh/cross-helpers'; import { stringInterpolator } from '@graphql-mesh/string-interpolation'; import type { MeshTransform, MeshTransformOptions, YamlConfig } from '@graphql-mesh/types'; -import type { DelegationContext } from '@graphql-tools/delegate'; +import { getTypeInfo, type DelegationContext } from '@graphql-tools/delegate'; import { mapMaybePromise, type ExecutionRequest } from '@graphql-tools/utils'; interface TransformationContext { @@ -88,7 +88,7 @@ export default class HiveTransform implements MeshTransform { transformRequest( request: ExecutionRequest, - delegationContext: DelegationContext, + _delegationContext: DelegationContext, transformationContext: TransformationContext, ) { try { @@ -102,25 +102,26 @@ export default class HiveTransform implements MeshTransform { transformResult( result: ExecutionResult, - delegationContext: DelegationContext, + _delegationContext: DelegationContext, transformationContext: TransformationContext, ) { // eslint-disable-next-line @typescript-eslint/no-floating-promises -- we dont really care about usage reporting result try { + const typeInfo = getTypeInfo(this.schema); transformationContext .collectUsageCallback?.( { schema: this.schema, - document: visit(transformationContext.request.document, { - [Kind.FIELD](node) { - if (!node.arguments) { - return { - ...node, - arguments: [], - }; - } - }, - }), + document: visit( + transformationContext.request.document, + visitWithTypeInfo(typeInfo, { + Argument: () => { + if (!typeInfo.getArgument()) { + return null; + } + }, + }), + ), rootValue: transformationContext.request.rootValue, contextValue: transformationContext.request.context, variableValues: transformationContext.request.variables,