From 1d19845f4c4687ddaf72d146d6fd2ca5bb3a2d58 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Tue, 26 Nov 2024 23:29:25 +0200 Subject: [PATCH] adjust GraphQLResolveInfo to remove breaking change from v16 #3811 internally preserved the sources of variable values so that we could properly replace variables within complex scalars, but it also exposed this within the GraphQLResolveInfo interface available to resolvers in a breaking manner, by changing the type of the `variableValues` property. This PR reverts the change to the `variableValues` property, but exposed the extended variable information under a new `variableValuesWithSources` property. --- src/execution/__tests__/executor-test.ts | 4 +++- src/execution/execute.ts | 3 ++- src/type/definition.ts | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/execution/__tests__/executor-test.ts b/src/execution/__tests__/executor-test.ts index 173dcc9483..232852b7a2 100644 --- a/src/execution/__tests__/executor-test.ts +++ b/src/execution/__tests__/executor-test.ts @@ -222,6 +222,7 @@ describe('Execute: Handles basic execution tasks', () => { 'rootValue', 'operation', 'variableValues', + 'variableValuesWithSources', ); const operation = document.definitions[0]; @@ -240,7 +241,8 @@ describe('Execute: Handles basic execution tasks', () => { expect(resolvedInfo).to.deep.include({ fieldNodes: [field], path: { prev: undefined, key: 'result', typename: 'Test' }, - variableValues: { + variableValues: { var: 'abc' }, + variableValuesWithSources: { sources: { var: { signature: { diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 00f0e7b1ae..19fa5fb4ff 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -955,7 +955,8 @@ export function buildResolveInfo( fragments: fragmentDefinitions, rootValue, operation, - variableValues, + variableValues: variableValues.coerced, + variableValuesWithSources: variableValues, }; } diff --git a/src/type/definition.ts b/src/type/definition.ts index 8d51201070..2d5450deaf 100644 --- a/src/type/definition.ts +++ b/src/type/definition.ts @@ -1003,7 +1003,8 @@ export interface GraphQLResolveInfo { readonly fragments: ObjMap; readonly rootValue: unknown; readonly operation: OperationDefinitionNode; - readonly variableValues: VariableValues; + readonly variableValues: { [variable: string]: unknown }; + readonly variableValuesWithSources: VariableValues; } /**