From 90279f45c89c605e98051423b596c339f41e3995 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 10 Jul 2020 03:06:45 +0300 Subject: [PATCH] GraphQLScalarType: default 'parseLiteral' should handle variables Motivation #2657 --- src/type/__tests__/definition-test.js | 3 +++ src/type/definition.js | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/type/__tests__/definition-test.js b/src/type/__tests__/definition-test.js index c54b589611..2ce2bcf7ef 100644 --- a/src/type/__tests__/definition-test.js +++ b/src/type/__tests__/definition-test.js @@ -91,6 +91,9 @@ describe('Type System: Scalars', () => { expect(scalar.parseLiteral(parseValue('{ foo: "bar" }'))).to.equal( 'parseValue: { foo: "bar" }', ); + expect( + scalar.parseLiteral(parseValue('{ foo: { bar: $var } }'), { var: 'baz' }), + ).to.equal('parseValue: { foo: { bar: "baz" } }'); }); it('rejects a Scalar type without name', () => { diff --git a/src/type/definition.js b/src/type/definition.js index ab94313263..4ad1a15717 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -591,7 +591,8 @@ export class GraphQLScalarType { this.serialize = config.serialize ?? identityFunc; this.parseValue = parseValue; this.parseLiteral = - config.parseLiteral ?? ((node) => parseValue(valueFromASTUntyped(node))); + config.parseLiteral ?? + ((node, variables) => parseValue(valueFromASTUntyped(node, variables))); this.extensions = config.extensions && toObjMap(config.extensions); this.astNode = config.astNode; this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes);