diff --git a/integrationTests/ts/kitchenSink-test.ts b/integrationTests/ts/kitchenSink-test.ts index 8d27ec0e97..c182be287e 100644 --- a/integrationTests/ts/kitchenSink-test.ts +++ b/integrationTests/ts/kitchenSink-test.ts @@ -8,7 +8,7 @@ new GraphQLScalarType({ name: 'SomeScalar', serialize: undefined, parseValue: undefined, - parseLiteral: undefined, + parseConstLiteral: undefined, }); new GraphQLError('test', { nodes: undefined }); diff --git a/src/execution/__tests__/variables-test.ts b/src/execution/__tests__/variables-test.ts index 7fe5a8a10d..922a8b9e4f 100644 --- a/src/execution/__tests__/variables-test.ts +++ b/src/execution/__tests__/variables-test.ts @@ -47,7 +47,7 @@ const TestFaultyScalar = new GraphQLScalarType({ parseValue() { throw TestFaultyScalarGraphQLError; }, - parseLiteral() { + parseConstLiteral() { throw TestFaultyScalarGraphQLError; }, }); @@ -58,7 +58,7 @@ const TestComplexScalar = new GraphQLScalarType({ expect(value).to.equal('SerializedValue'); return 'DeserializedValue'; }, - parseLiteral(ast) { + parseConstLiteral(ast) { expect(ast).to.include({ kind: 'StringValue', value: 'SerializedValue' }); return 'DeserializedValue'; }, @@ -281,7 +281,7 @@ describe('Execute: Handles inputs', () => { }); }); - it('properly runs parseLiteral on complex scalar types', () => { + it('properly runs parseConstLiteral on complex scalar types', () => { const result = executeQuery(` { fieldWithObjectInput(input: {c: "foo", d: "SerializedValue"}) diff --git a/src/type/__tests__/definition-test.ts b/src/type/__tests__/definition-test.ts index 1f1d1999d3..1e82312660 100644 --- a/src/type/__tests__/definition-test.ts +++ b/src/type/__tests__/definition-test.ts @@ -55,13 +55,13 @@ describe('Type System: Scalars', () => { ).not.to.throw(); }); - it('accepts a Scalar type defining parseValue and parseLiteral', () => { + it('accepts a Scalar type defining parseValue and parseConstLiteral', () => { expect( () => new GraphQLScalarType({ name: 'SomeScalar', parseValue: dummyFunc, - parseLiteral: dummyFunc, + parseConstLiteral: dummyFunc, }), ).to.not.throw(); }); @@ -72,9 +72,10 @@ describe('Type System: Scalars', () => { expect(scalar.serialize).to.equal(identityFunc); expect(scalar.parseValue).to.equal(identityFunc); expect(scalar.parseLiteral).to.be.a('function'); + expect(scalar.parseConstLiteral).to.be.a('function'); }); - it('use parseValue for parsing literals if parseLiteral omitted', () => { + it('use parseValue for parsing literals if parseConstLiteral omitted', () => { const scalar = new GraphQLScalarType({ name: 'Foo', parseValue(value) { @@ -82,12 +83,12 @@ describe('Type System: Scalars', () => { }, }); - expect(scalar.parseLiteral(parseConstValue('null'))).to.equal( + expect(scalar.parseConstLiteral(parseConstValue('null'))).to.equal( 'parseValue: null', ); - expect(scalar.parseLiteral(parseConstValue('{ foo: "bar" }'))).to.equal( - 'parseValue: { foo: "bar" }', - ); + expect( + scalar.parseConstLiteral(parseConstValue('{ foo: "bar" }')), + ).to.equal('parseValue: { foo: "bar" }'); }); it('rejects a Scalar type defining parseLiteral but not parseValue', () => { @@ -101,6 +102,18 @@ describe('Type System: Scalars', () => { 'SomeScalar must provide both "parseValue" and "parseLiteral" functions.', ); }); + + it('rejects a Scalar type defining parseConstLiteral but not parseValue', () => { + expect( + () => + new GraphQLScalarType({ + name: 'SomeScalar', + parseConstLiteral: dummyFunc, + }), + ).to.throw( + 'SomeScalar must provide both "parseValue" and "parseConstLiteral" functions.', + ); + }); }); describe('Type System: Objects', () => { diff --git a/src/type/__tests__/scalars-test.ts b/src/type/__tests__/scalars-test.ts index 14afcc2bee..eff300918d 100644 --- a/src/type/__tests__/scalars-test.ts +++ b/src/type/__tests__/scalars-test.ts @@ -64,44 +64,44 @@ describe('Type System: Specified scalar types', () => { ); }); - it('parseLiteral', () => { - function parseLiteral(str: string) { - return GraphQLInt.parseLiteral(parseConstValue(str)); + it('parseConstLiteral', () => { + function parseConstLiteral(str: string) { + return GraphQLInt.parseConstLiteral(parseConstValue(str)); } - expect(parseLiteral('1')).to.equal(1); - expect(parseLiteral('0')).to.equal(0); - expect(parseLiteral('-1')).to.equal(-1); + expect(parseConstLiteral('1')).to.equal(1); + expect(parseConstLiteral('0')).to.equal(0); + expect(parseConstLiteral('-1')).to.equal(-1); - expect(() => parseLiteral('9876504321')).to.throw( + expect(() => parseConstLiteral('9876504321')).to.throw( 'Int cannot represent non 32-bit signed integer value: 9876504321', ); - expect(() => parseLiteral('-9876504321')).to.throw( + expect(() => parseConstLiteral('-9876504321')).to.throw( 'Int cannot represent non 32-bit signed integer value: -9876504321', ); - expect(() => parseLiteral('1.0')).to.throw( + expect(() => parseConstLiteral('1.0')).to.throw( 'Int cannot represent non-integer value: 1.0', ); - expect(() => parseLiteral('null')).to.throw( + expect(() => parseConstLiteral('null')).to.throw( 'Int cannot represent non-integer value: null', ); - expect(() => parseLiteral('""')).to.throw( + expect(() => parseConstLiteral('""')).to.throw( 'Int cannot represent non-integer value: ""', ); - expect(() => parseLiteral('"123"')).to.throw( + expect(() => parseConstLiteral('"123"')).to.throw( 'Int cannot represent non-integer value: "123"', ); - expect(() => parseLiteral('false')).to.throw( + expect(() => parseConstLiteral('false')).to.throw( 'Int cannot represent non-integer value: false', ); - expect(() => parseLiteral('[1]')).to.throw( + expect(() => parseConstLiteral('[1]')).to.throw( 'Int cannot represent non-integer value: [1]', ); - expect(() => parseLiteral('{ value: 1 }')).to.throw( + expect(() => parseConstLiteral('{ value: 1 }')).to.throw( 'Int cannot represent non-integer value: { value: 1 }', ); - expect(() => parseLiteral('ENUM_VALUE')).to.throw( + expect(() => parseConstLiteral('ENUM_VALUE')).to.throw( 'Int cannot represent non-integer value: ENUM_VALUE', ); }); @@ -226,39 +226,39 @@ describe('Type System: Specified scalar types', () => { ); }); - it('parseLiteral', () => { - function parseLiteral(str: string) { - return GraphQLFloat.parseLiteral(parseConstValue(str)); + it('parseConstLiteral', () => { + function parseConstLiteral(str: string) { + return GraphQLFloat.parseConstLiteral(parseConstValue(str)); } - expect(parseLiteral('1')).to.equal(1); - expect(parseLiteral('0')).to.equal(0); - expect(parseLiteral('-1')).to.equal(-1); - expect(parseLiteral('0.1')).to.equal(0.1); - expect(parseLiteral(Math.PI.toString())).to.equal(Math.PI); + expect(parseConstLiteral('1')).to.equal(1); + expect(parseConstLiteral('0')).to.equal(0); + expect(parseConstLiteral('-1')).to.equal(-1); + expect(parseConstLiteral('0.1')).to.equal(0.1); + expect(parseConstLiteral(Math.PI.toString())).to.equal(Math.PI); - expect(() => parseLiteral('null')).to.throw( + expect(() => parseConstLiteral('null')).to.throw( 'Float cannot represent non numeric value: null', ); - expect(() => parseLiteral('""')).to.throw( + expect(() => parseConstLiteral('""')).to.throw( 'Float cannot represent non numeric value: ""', ); - expect(() => parseLiteral('"123"')).to.throw( + expect(() => parseConstLiteral('"123"')).to.throw( 'Float cannot represent non numeric value: "123"', ); - expect(() => parseLiteral('"123.5"')).to.throw( + expect(() => parseConstLiteral('"123.5"')).to.throw( 'Float cannot represent non numeric value: "123.5"', ); - expect(() => parseLiteral('false')).to.throw( + expect(() => parseConstLiteral('false')).to.throw( 'Float cannot represent non numeric value: false', ); - expect(() => parseLiteral('[0.1]')).to.throw( + expect(() => parseConstLiteral('[0.1]')).to.throw( 'Float cannot represent non numeric value: [0.1]', ); - expect(() => parseLiteral('{ value: 0.1 }')).to.throw( + expect(() => parseConstLiteral('{ value: 0.1 }')).to.throw( 'Float cannot represent non numeric value: { value: 0.1 }', ); - expect(() => parseLiteral('ENUM_VALUE')).to.throw( + expect(() => parseConstLiteral('ENUM_VALUE')).to.throw( 'Float cannot represent non numeric value: ENUM_VALUE', ); }); @@ -336,33 +336,33 @@ describe('Type System: Specified scalar types', () => { ); }); - it('parseLiteral', () => { - function parseLiteral(str: string) { - return GraphQLString.parseLiteral(parseConstValue(str)); + it('parseConstLiteral', () => { + function parseConstLiteral(str: string) { + return GraphQLString.parseConstLiteral(parseConstValue(str)); } - expect(parseLiteral('"foo"')).to.equal('foo'); - expect(parseLiteral('"""bar"""')).to.equal('bar'); + expect(parseConstLiteral('"foo"')).to.equal('foo'); + expect(parseConstLiteral('"""bar"""')).to.equal('bar'); - expect(() => parseLiteral('null')).to.throw( + expect(() => parseConstLiteral('null')).to.throw( 'String cannot represent a non string value: null', ); - expect(() => parseLiteral('1')).to.throw( + expect(() => parseConstLiteral('1')).to.throw( 'String cannot represent a non string value: 1', ); - expect(() => parseLiteral('0.1')).to.throw( + expect(() => parseConstLiteral('0.1')).to.throw( 'String cannot represent a non string value: 0.1', ); - expect(() => parseLiteral('false')).to.throw( + expect(() => parseConstLiteral('false')).to.throw( 'String cannot represent a non string value: false', ); - expect(() => parseLiteral('["foo"]')).to.throw( + expect(() => parseConstLiteral('["foo"]')).to.throw( 'String cannot represent a non string value: ["foo"]', ); - expect(() => parseLiteral('{ value: "foo" }')).to.throw( + expect(() => parseConstLiteral('{ value: "foo" }')).to.throw( 'String cannot represent a non string value: { value: "foo" }', ); - expect(() => parseLiteral('ENUM_VALUE')).to.throw( + expect(() => parseConstLiteral('ENUM_VALUE')).to.throw( 'String cannot represent a non string value: ENUM_VALUE', ); }); @@ -445,39 +445,39 @@ describe('Type System: Specified scalar types', () => { ); }); - it('parseLiteral', () => { - function parseLiteral(str: string) { - return GraphQLBoolean.parseLiteral(parseConstValue(str)); + it('parseConstLiteral', () => { + function parseConstLiteral(str: string) { + return GraphQLBoolean.parseConstLiteral(parseConstValue(str)); } - expect(parseLiteral('true')).to.equal(true); - expect(parseLiteral('false')).to.equal(false); + expect(parseConstLiteral('true')).to.equal(true); + expect(parseConstLiteral('false')).to.equal(false); - expect(() => parseLiteral('null')).to.throw( + expect(() => parseConstLiteral('null')).to.throw( 'Boolean cannot represent a non boolean value: null', ); - expect(() => parseLiteral('0')).to.throw( + expect(() => parseConstLiteral('0')).to.throw( 'Boolean cannot represent a non boolean value: 0', ); - expect(() => parseLiteral('1')).to.throw( + expect(() => parseConstLiteral('1')).to.throw( 'Boolean cannot represent a non boolean value: 1', ); - expect(() => parseLiteral('0.1')).to.throw( + expect(() => parseConstLiteral('0.1')).to.throw( 'Boolean cannot represent a non boolean value: 0.1', ); - expect(() => parseLiteral('""')).to.throw( + expect(() => parseConstLiteral('""')).to.throw( 'Boolean cannot represent a non boolean value: ""', ); - expect(() => parseLiteral('"false"')).to.throw( + expect(() => parseConstLiteral('"false"')).to.throw( 'Boolean cannot represent a non boolean value: "false"', ); - expect(() => parseLiteral('[false]')).to.throw( + expect(() => parseConstLiteral('[false]')).to.throw( 'Boolean cannot represent a non boolean value: [false]', ); - expect(() => parseLiteral('{ value: false }')).to.throw( + expect(() => parseConstLiteral('{ value: false }')).to.throw( 'Boolean cannot represent a non boolean value: { value: false }', ); - expect(() => parseLiteral('ENUM_VALUE')).to.throw( + expect(() => parseConstLiteral('ENUM_VALUE')).to.throw( 'Boolean cannot represent a non boolean value: ENUM_VALUE', ); }); @@ -557,39 +557,43 @@ describe('Type System: Specified scalar types', () => { ); }); - it('parseLiteral', () => { - function parseLiteral(str: string) { - return GraphQLID.parseLiteral(parseConstValue(str)); + it('parseConstLiteral', () => { + function parseConstLiteral(str: string) { + return GraphQLID.parseConstLiteral(parseConstValue(str)); } - expect(parseLiteral('""')).to.equal(''); - expect(parseLiteral('"1"')).to.equal('1'); - expect(parseLiteral('"foo"')).to.equal('foo'); - expect(parseLiteral('"""foo"""')).to.equal('foo'); - expect(parseLiteral('1')).to.equal('1'); - expect(parseLiteral('0')).to.equal('0'); - expect(parseLiteral('-1')).to.equal('-1'); + expect(parseConstLiteral('""')).to.equal(''); + expect(parseConstLiteral('"1"')).to.equal('1'); + expect(parseConstLiteral('"foo"')).to.equal('foo'); + expect(parseConstLiteral('"""foo"""')).to.equal('foo'); + expect(parseConstLiteral('1')).to.equal('1'); + expect(parseConstLiteral('0')).to.equal('0'); + expect(parseConstLiteral('-1')).to.equal('-1'); // Support arbitrary long numbers even if they can't be represented in JS - expect(parseLiteral('90071992547409910')).to.equal('90071992547409910'); - expect(parseLiteral('-90071992547409910')).to.equal('-90071992547409910'); + expect(parseConstLiteral('90071992547409910')).to.equal( + '90071992547409910', + ); + expect(parseConstLiteral('-90071992547409910')).to.equal( + '-90071992547409910', + ); - expect(() => parseLiteral('null')).to.throw( + expect(() => parseConstLiteral('null')).to.throw( 'ID cannot represent a non-string and non-integer value: null', ); - expect(() => parseLiteral('0.1')).to.throw( + expect(() => parseConstLiteral('0.1')).to.throw( 'ID cannot represent a non-string and non-integer value: 0.1', ); - expect(() => parseLiteral('false')).to.throw( + expect(() => parseConstLiteral('false')).to.throw( 'ID cannot represent a non-string and non-integer value: false', ); - expect(() => parseLiteral('["1"]')).to.throw( + expect(() => parseConstLiteral('["1"]')).to.throw( 'ID cannot represent a non-string and non-integer value: ["1"]', ); - expect(() => parseLiteral('{ value: "1" }')).to.throw( + expect(() => parseConstLiteral('{ value: "1" }')).to.throw( 'ID cannot represent a non-string and non-integer value: { value: "1" }', ); - expect(() => parseLiteral('ENUM_VALUE')).to.throw( + expect(() => parseConstLiteral('ENUM_VALUE')).to.throw( 'ID cannot represent a non-string and non-integer value: ENUM_VALUE', ); }); diff --git a/src/type/definition.ts b/src/type/definition.ts index cfa95fb9d0..60771a9193 100644 --- a/src/type/definition.ts +++ b/src/type/definition.ts @@ -35,6 +35,7 @@ import type { ScalarTypeExtensionNode, UnionTypeDefinitionNode, UnionTypeExtensionNode, + ValueNode, } from '../language/ast.js'; import { Kind } from '../language/kinds.js'; import { print } from '../language/printer.js'; @@ -562,10 +563,15 @@ export interface GraphQLScalarTypeExtensions { * valid for this type. Returns undefined or throws an error to indicate * invalid values. * - * - parseLiteral(ast): Implements "Input Coercion" for literals. Given an - * GraphQL literal (AST) (for example, an argument value), produces an - * internal value valid for this type. Returns undefined or throws an error - * to indicate invalid values. + * - parseLiteral(ast): Implements "Input Coercion" for literals including + * non-specified replacement of variables embedded within complex scalars. + * This method will be removed in v18 favor of the combination of the + * `replaceVariables()` utility and the `parseConstLiteral()` method. + * + * - parseConstLiteral(ast): Implements "Input Coercion" for constant literals. + * Given an GraphQL literal (AST) (for example, an argument value), produces + * an internal value valid for this type. Returns undefined or throws an + * error to indicate invalid values. * * - valueToLiteral(value): Converts an external value to a GraphQL * literal (AST). Returns undefined or throws an error to indicate @@ -578,7 +584,9 @@ export class GraphQLScalarType { specifiedByURL: Maybe; serialize: GraphQLScalarSerializer; parseValue: GraphQLScalarValueParser; + /** @deprecated use `replaceVariables()` and `parseConstLiteral()` instead, `parseLiteral()` will be deprecated in v18 */ parseLiteral: GraphQLScalarLiteralParser; + parseConstLiteral: GraphQLScalarConstLiteralParser; valueToLiteral: GraphQLScalarValueToLiteral | undefined; extensions: Readonly; astNode: Maybe; @@ -596,7 +604,11 @@ export class GraphQLScalarType { config.serialize ?? (identityFunc as GraphQLScalarSerializer); this.parseValue = parseValue; this.parseLiteral = - config.parseLiteral ?? ((node) => parseValue(valueFromASTUntyped(node))); + config.parseLiteral ?? + ((node, variables) => parseValue(valueFromASTUntyped(node, variables))); + this.parseConstLiteral = + config.parseConstLiteral ?? + ((node) => parseValue(valueFromASTUntyped(node))); this.valueToLiteral = config.valueToLiteral; this.extensions = toObjMap(config.extensions); this.astNode = config.astNode; @@ -609,6 +621,14 @@ export class GraphQLScalarType { `${this.name} must provide both "parseValue" and "parseLiteral" functions.`, ); } + + if (config.parseConstLiteral) { + devAssert( + typeof config.parseValue === 'function' && + typeof config.parseConstLiteral === 'function', + `${this.name} must provide both "parseValue" and "parseConstLiteral" functions.`, + ); + } } get [Symbol.toStringTag]() { @@ -623,6 +643,7 @@ export class GraphQLScalarType { serialize: this.serialize, parseValue: this.parseValue, parseLiteral: this.parseLiteral, + parseConstLiteral: this.parseConstLiteral, valueToLiteral: this.valueToLiteral, extensions: this.extensions, astNode: this.astNode, @@ -648,6 +669,11 @@ export type GraphQLScalarValueParser = ( ) => TInternal; export type GraphQLScalarLiteralParser = ( + valueNode: ValueNode, + variables: Maybe>, +) => Maybe; + +export type GraphQLScalarConstLiteralParser = ( valueNode: ConstValueNode, ) => Maybe; @@ -664,7 +690,10 @@ export interface GraphQLScalarTypeConfig { /** Parses an externally provided value to use as an input. */ parseValue?: GraphQLScalarValueParser | undefined; /** Parses an externally provided literal value to use as an input. */ + /** @deprecated use `replaceVariables()` and `parseConstLiteral()` instead, `parseLiteral()` will be deprecated in v18 */ parseLiteral?: GraphQLScalarLiteralParser | undefined; + /** Parses an externally provided const literal value to use as an input. */ + parseConstLiteral?: GraphQLScalarConstLiteralParser | undefined; /** Translates an externally provided value to a literal (AST). */ valueToLiteral?: GraphQLScalarValueToLiteral | undefined; extensions?: Maybe>; @@ -677,6 +706,7 @@ interface GraphQLScalarTypeNormalizedConfig serialize: GraphQLScalarSerializer; parseValue: GraphQLScalarValueParser; parseLiteral: GraphQLScalarLiteralParser; + parseConstLiteral: GraphQLScalarConstLiteralParser; extensions: Readonly; extensionASTNodes: ReadonlyArray; } @@ -1411,8 +1441,16 @@ export class GraphQLEnumType /* */ { return enumValue.value; } - parseLiteral(valueNode: ConstValueNode): Maybe /* T */ { + /** @deprecated use `parseConstLiteral()` instead, `parseLiteral()` will be deprecated in v18 */ + parseLiteral( + valueNode: ValueNode, + _variables: Maybe>, + ): Maybe /* T */ { // Note: variables will be resolved to a value before calling this function. + return this.parseConstLiteral(valueNode as ConstValueNode); + } + + parseConstLiteral(valueNode: ConstValueNode): Maybe /* T */ { if (valueNode.kind !== Kind.ENUM) { const valueStr = print(valueNode); throw new GraphQLError( diff --git a/src/type/scalars.ts b/src/type/scalars.ts index 0568874387..a9003f7d54 100644 --- a/src/type/scalars.ts +++ b/src/type/scalars.ts @@ -68,7 +68,7 @@ export const GraphQLInt = new GraphQLScalarType({ return inputValue; }, - parseLiteral(valueNode) { + parseConstLiteral(valueNode) { if (valueNode.kind !== Kind.INT) { throw new GraphQLError( `Int cannot represent non-integer value: ${print(valueNode)}`, @@ -130,7 +130,7 @@ export const GraphQLFloat = new GraphQLScalarType({ return inputValue; }, - parseLiteral(valueNode) { + parseConstLiteral(valueNode) { if (valueNode.kind !== Kind.FLOAT && valueNode.kind !== Kind.INT) { throw new GraphQLError( `Float cannot represent non numeric value: ${print(valueNode)}`, @@ -180,7 +180,7 @@ export const GraphQLString = new GraphQLScalarType({ return inputValue; }, - parseLiteral(valueNode) { + parseConstLiteral(valueNode) { if (valueNode.kind !== Kind.STRING) { throw new GraphQLError( `String cannot represent a non string value: ${print(valueNode)}`, @@ -224,7 +224,7 @@ export const GraphQLBoolean = new GraphQLScalarType({ return inputValue; }, - parseLiteral(valueNode) { + parseConstLiteral(valueNode) { if (valueNode.kind !== Kind.BOOLEAN) { throw new GraphQLError( `Boolean cannot represent a non boolean value: ${print(valueNode)}`, @@ -270,7 +270,7 @@ export const GraphQLID = new GraphQLScalarType({ throw new GraphQLError(`ID cannot represent value: ${inspect(inputValue)}`); }, - parseLiteral(valueNode) { + parseConstLiteral(valueNode) { if (valueNode.kind !== Kind.STRING && valueNode.kind !== Kind.INT) { throw new GraphQLError( 'ID cannot represent a non-string and non-integer value: ' + diff --git a/src/utilities/__tests__/coerceInputValue-test.ts b/src/utilities/__tests__/coerceInputValue-test.ts index ef100ac584..e9bbcc94f7 100644 --- a/src/utilities/__tests__/coerceInputValue-test.ts +++ b/src/utilities/__tests__/coerceInputValue-test.ts @@ -610,10 +610,10 @@ describe('coerceInputLiteral', () => { test('123.456', GraphQLID, undefined); }); - it('convert using parseLiteral from a custom scalar type', () => { + it('convert using parseConstLiteral from a custom scalar type', () => { const passthroughScalar = new GraphQLScalarType({ name: 'PassthroughScalar', - parseLiteral(node) { + parseConstLiteral(node) { invariant(node.kind === 'StringValue'); return node.value; }, @@ -624,7 +624,7 @@ describe('coerceInputLiteral', () => { const printScalar = new GraphQLScalarType({ name: 'PrintScalar', - parseLiteral(node) { + parseConstLiteral(node) { return `~~~${print(node)}~~~`; }, parseValue: identityFunc, @@ -641,7 +641,7 @@ describe('coerceInputLiteral', () => { const throwScalar = new GraphQLScalarType({ name: 'ThrowScalar', - parseLiteral() { + parseConstLiteral() { throw new Error('Test'); }, parseValue: identityFunc, @@ -651,7 +651,7 @@ describe('coerceInputLiteral', () => { const returnUndefinedScalar = new GraphQLScalarType({ name: 'ReturnUndefinedScalar', - parseLiteral() { + parseConstLiteral() { return undefined; }, parseValue: identityFunc, diff --git a/src/utilities/coerceInputValue.ts b/src/utilities/coerceInputValue.ts index a6bdfe5166..3ea479a29b 100644 --- a/src/utilities/coerceInputValue.ts +++ b/src/utilities/coerceInputValue.ts @@ -378,7 +378,7 @@ export function coerceInputLiteral( ); try { - return leafType.parseLiteral(constValueNode); + return leafType.parseConstLiteral(constValueNode); } catch (_error) { // Invalid: ignore error and intentionally return no value. } diff --git a/src/utilities/valueFromAST.ts b/src/utilities/valueFromAST.ts index add9153680..e0ff5d8bf2 100644 --- a/src/utilities/valueFromAST.ts +++ b/src/utilities/valueFromAST.ts @@ -115,7 +115,7 @@ export function valueFromAST( const fieldNode = fieldNodes.get(field.name); if (fieldNode == null || isMissingVariable(fieldNode.value, variables)) { if (field.defaultValue !== undefined) { - coercedObj[field.name] = field.defaultValue; + coercedObj[field.name] = field.defaultValue.value; } else if (isNonNullType(field.type)) { return; // Invalid: intentionally return no value. } diff --git a/src/validation/rules/ValuesOfCorrectTypeRule.ts b/src/validation/rules/ValuesOfCorrectTypeRule.ts index 50d51b5ffa..d2b566823d 100644 --- a/src/validation/rules/ValuesOfCorrectTypeRule.ts +++ b/src/validation/rules/ValuesOfCorrectTypeRule.ts @@ -155,10 +155,10 @@ function isValidValueNode(context: ValidationContext, node: ValueNode): void { const constValueNode = replaceVariables(node); - // Scalars and Enums determine if a literal value is valid via parseLiteral(), + // Scalars and Enums determine if a literal value is valid via parseConstLiteral(), // which may throw or return undefined to indicate an invalid value. try { - const parseResult = type.parseLiteral(constValueNode); + const parseResult = type.parseConstLiteral(constValueNode); if (parseResult === undefined) { const typeStr = inspect(locationType); context.reportError(