Skip to content

Commit

Permalink
GraphQLScalarType: default 'parseLiteral' should handle variables (#2696
Browse files Browse the repository at this point in the history
)

Motivation #2657
  • Loading branch information
IvanGoncharov authored Jul 10, 2020
1 parent 9da7d35 commit e3727fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/type/__tests__/definition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e3727fc

Please sign in to comment.