diff --git a/src/execution/values.ts b/src/execution/values.ts index 1d5b346381..12bab5cb6b 100644 --- a/src/execution/values.ts +++ b/src/execution/values.ts @@ -84,8 +84,8 @@ function coerceVariableValues( const { name: varName, type: varType } = varSignature; if (!Object.hasOwn(inputs, varName)) { - if (varSignature.hasDefaultValue) { - coercedValues[varName] = varSignature.getDefaultValue(); + if (varDefNode.defaultValue) { + coercedValues[varName] = varSignature.defaultValue; } else if (isNonNullType(varType)) { const varTypeStr = inspect(varType); onError( diff --git a/src/utilities/getVariableSignature.ts b/src/utilities/getVariableSignature.ts index ec531ce914..4ff7e977e4 100644 --- a/src/utilities/getVariableSignature.ts +++ b/src/utilities/getVariableSignature.ts @@ -5,43 +5,18 @@ import { print } from '../language/printer.js'; import type { GraphQLInputType, GraphQLSchema } from '../type/index.js'; import { isInputType } from '../type/index.js'; -import type { ConstValueNode, VariableDefinitionNode } from '../index.js'; +import type { VariableDefinitionNode } from '../index.js'; import { typeFromAST } from './typeFromAST.js'; import { valueFromAST } from './valueFromAST.js'; /** * A GraphQLVariableSignature is required to coerce a variable value. - * - * @internal * */ -export class GraphQLVariableSignature { +export interface GraphQLVariableSignature { name: string; type: GraphQLInputType; - hasDefaultValue: boolean; - _defaultValue: unknown; - - constructor( - name: string, - type: GraphQLInputType, - defaultValueNode: ConstValueNode | undefined, - ) { - this.name = name; - this.type = type; - if (defaultValueNode) { - this.hasDefaultValue = true; - this._defaultValue = () => valueFromAST(defaultValueNode, type); - } else { - this.hasDefaultValue = false; - } - } - - getDefaultValue(): unknown { - if (typeof this._defaultValue === 'function') { - this._defaultValue = this._defaultValue(); - } - return this._defaultValue; - } + defaultValue: unknown; } export function getVariableSignature( @@ -61,9 +36,9 @@ export function getVariableSignature( ); } - return new GraphQLVariableSignature( - varName, - varType, - varDefNode.defaultValue, - ); + return { + name: varName, + type: varType, + defaultValue: valueFromAST(varDefNode.defaultValue, varType), + }; }