Skip to content

Commit 4c94747

Browse files
committed
retain old parseLiteral, rename new version to parseConstLiteral
1 parent 1b56a83 commit 4c94747

File tree

10 files changed

+162
-107
lines changed

10 files changed

+162
-107
lines changed

integrationTests/ts/kitchenSink-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ new GraphQLScalarType({
88
name: 'SomeScalar',
99
serialize: undefined,
1010
parseValue: undefined,
11-
parseLiteral: undefined,
11+
parseConstLiteral: undefined,
1212
});
1313

1414
new GraphQLError('test', { nodes: undefined });

src/execution/__tests__/variables-test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const TestFaultyScalar = new GraphQLScalarType({
4747
parseValue() {
4848
throw TestFaultyScalarGraphQLError;
4949
},
50-
parseLiteral() {
50+
parseConstLiteral() {
5151
throw TestFaultyScalarGraphQLError;
5252
},
5353
});
@@ -58,7 +58,7 @@ const TestComplexScalar = new GraphQLScalarType({
5858
expect(value).to.equal('SerializedValue');
5959
return 'DeserializedValue';
6060
},
61-
parseLiteral(ast) {
61+
parseConstLiteral(ast) {
6262
expect(ast).to.include({ kind: 'StringValue', value: 'SerializedValue' });
6363
return 'DeserializedValue';
6464
},
@@ -281,7 +281,7 @@ describe('Execute: Handles inputs', () => {
281281
});
282282
});
283283

284-
it('properly runs parseLiteral on complex scalar types', () => {
284+
it('properly runs parseConstLiteral on complex scalar types', () => {
285285
const result = executeQuery(`
286286
{
287287
fieldWithObjectInput(input: {c: "foo", d: "SerializedValue"})

src/type/__tests__/definition-test.ts

+20-7
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ describe('Type System: Scalars', () => {
5555
).not.to.throw();
5656
});
5757

58-
it('accepts a Scalar type defining parseValue and parseLiteral', () => {
58+
it('accepts a Scalar type defining parseValue and parseConstLiteral', () => {
5959
expect(
6060
() =>
6161
new GraphQLScalarType({
6262
name: 'SomeScalar',
6363
parseValue: dummyFunc,
64-
parseLiteral: dummyFunc,
64+
parseConstLiteral: dummyFunc,
6565
}),
6666
).to.not.throw();
6767
});
@@ -72,22 +72,23 @@ describe('Type System: Scalars', () => {
7272
expect(scalar.serialize).to.equal(identityFunc);
7373
expect(scalar.parseValue).to.equal(identityFunc);
7474
expect(scalar.parseLiteral).to.be.a('function');
75+
expect(scalar.parseConstLiteral).to.be.a('function');
7576
});
7677

77-
it('use parseValue for parsing literals if parseLiteral omitted', () => {
78+
it('use parseValue for parsing literals if parseConstLiteral omitted', () => {
7879
const scalar = new GraphQLScalarType({
7980
name: 'Foo',
8081
parseValue(value) {
8182
return 'parseValue: ' + inspect(value);
8283
},
8384
});
8485

85-
expect(scalar.parseLiteral(parseConstValue('null'))).to.equal(
86+
expect(scalar.parseConstLiteral(parseConstValue('null'))).to.equal(
8687
'parseValue: null',
8788
);
88-
expect(scalar.parseLiteral(parseConstValue('{ foo: "bar" }'))).to.equal(
89-
'parseValue: { foo: "bar" }',
90-
);
89+
expect(
90+
scalar.parseConstLiteral(parseConstValue('{ foo: "bar" }')),
91+
).to.equal('parseValue: { foo: "bar" }');
9192
});
9293

9394
it('rejects a Scalar type defining parseLiteral but not parseValue', () => {
@@ -101,6 +102,18 @@ describe('Type System: Scalars', () => {
101102
'SomeScalar must provide both "parseValue" and "parseLiteral" functions.',
102103
);
103104
});
105+
106+
it('rejects a Scalar type defining parseConstLiteral but not parseValue', () => {
107+
expect(
108+
() =>
109+
new GraphQLScalarType({
110+
name: 'SomeScalar',
111+
parseConstLiteral: dummyFunc,
112+
}),
113+
).to.throw(
114+
'SomeScalar must provide both "parseValue" and "parseConstLiteral" functions.',
115+
);
116+
});
104117
});
105118

106119
describe('Type System: Objects', () => {

src/type/__tests__/scalars-test.ts

+80-76
Original file line numberDiff line numberDiff line change
@@ -64,44 +64,44 @@ describe('Type System: Specified scalar types', () => {
6464
);
6565
});
6666

67-
it('parseLiteral', () => {
68-
function parseLiteral(str: string) {
69-
return GraphQLInt.parseLiteral(parseConstValue(str));
67+
it('parseConstLiteral', () => {
68+
function parseConstLiteral(str: string) {
69+
return GraphQLInt.parseConstLiteral(parseConstValue(str));
7070
}
7171

72-
expect(parseLiteral('1')).to.equal(1);
73-
expect(parseLiteral('0')).to.equal(0);
74-
expect(parseLiteral('-1')).to.equal(-1);
72+
expect(parseConstLiteral('1')).to.equal(1);
73+
expect(parseConstLiteral('0')).to.equal(0);
74+
expect(parseConstLiteral('-1')).to.equal(-1);
7575

76-
expect(() => parseLiteral('9876504321')).to.throw(
76+
expect(() => parseConstLiteral('9876504321')).to.throw(
7777
'Int cannot represent non 32-bit signed integer value: 9876504321',
7878
);
79-
expect(() => parseLiteral('-9876504321')).to.throw(
79+
expect(() => parseConstLiteral('-9876504321')).to.throw(
8080
'Int cannot represent non 32-bit signed integer value: -9876504321',
8181
);
8282

83-
expect(() => parseLiteral('1.0')).to.throw(
83+
expect(() => parseConstLiteral('1.0')).to.throw(
8484
'Int cannot represent non-integer value: 1.0',
8585
);
86-
expect(() => parseLiteral('null')).to.throw(
86+
expect(() => parseConstLiteral('null')).to.throw(
8787
'Int cannot represent non-integer value: null',
8888
);
89-
expect(() => parseLiteral('""')).to.throw(
89+
expect(() => parseConstLiteral('""')).to.throw(
9090
'Int cannot represent non-integer value: ""',
9191
);
92-
expect(() => parseLiteral('"123"')).to.throw(
92+
expect(() => parseConstLiteral('"123"')).to.throw(
9393
'Int cannot represent non-integer value: "123"',
9494
);
95-
expect(() => parseLiteral('false')).to.throw(
95+
expect(() => parseConstLiteral('false')).to.throw(
9696
'Int cannot represent non-integer value: false',
9797
);
98-
expect(() => parseLiteral('[1]')).to.throw(
98+
expect(() => parseConstLiteral('[1]')).to.throw(
9999
'Int cannot represent non-integer value: [1]',
100100
);
101-
expect(() => parseLiteral('{ value: 1 }')).to.throw(
101+
expect(() => parseConstLiteral('{ value: 1 }')).to.throw(
102102
'Int cannot represent non-integer value: { value: 1 }',
103103
);
104-
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
104+
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
105105
'Int cannot represent non-integer value: ENUM_VALUE',
106106
);
107107
});
@@ -226,39 +226,39 @@ describe('Type System: Specified scalar types', () => {
226226
);
227227
});
228228

229-
it('parseLiteral', () => {
230-
function parseLiteral(str: string) {
231-
return GraphQLFloat.parseLiteral(parseConstValue(str));
229+
it('parseConstLiteral', () => {
230+
function parseConstLiteral(str: string) {
231+
return GraphQLFloat.parseConstLiteral(parseConstValue(str));
232232
}
233233

234-
expect(parseLiteral('1')).to.equal(1);
235-
expect(parseLiteral('0')).to.equal(0);
236-
expect(parseLiteral('-1')).to.equal(-1);
237-
expect(parseLiteral('0.1')).to.equal(0.1);
238-
expect(parseLiteral(Math.PI.toString())).to.equal(Math.PI);
234+
expect(parseConstLiteral('1')).to.equal(1);
235+
expect(parseConstLiteral('0')).to.equal(0);
236+
expect(parseConstLiteral('-1')).to.equal(-1);
237+
expect(parseConstLiteral('0.1')).to.equal(0.1);
238+
expect(parseConstLiteral(Math.PI.toString())).to.equal(Math.PI);
239239

240-
expect(() => parseLiteral('null')).to.throw(
240+
expect(() => parseConstLiteral('null')).to.throw(
241241
'Float cannot represent non numeric value: null',
242242
);
243-
expect(() => parseLiteral('""')).to.throw(
243+
expect(() => parseConstLiteral('""')).to.throw(
244244
'Float cannot represent non numeric value: ""',
245245
);
246-
expect(() => parseLiteral('"123"')).to.throw(
246+
expect(() => parseConstLiteral('"123"')).to.throw(
247247
'Float cannot represent non numeric value: "123"',
248248
);
249-
expect(() => parseLiteral('"123.5"')).to.throw(
249+
expect(() => parseConstLiteral('"123.5"')).to.throw(
250250
'Float cannot represent non numeric value: "123.5"',
251251
);
252-
expect(() => parseLiteral('false')).to.throw(
252+
expect(() => parseConstLiteral('false')).to.throw(
253253
'Float cannot represent non numeric value: false',
254254
);
255-
expect(() => parseLiteral('[0.1]')).to.throw(
255+
expect(() => parseConstLiteral('[0.1]')).to.throw(
256256
'Float cannot represent non numeric value: [0.1]',
257257
);
258-
expect(() => parseLiteral('{ value: 0.1 }')).to.throw(
258+
expect(() => parseConstLiteral('{ value: 0.1 }')).to.throw(
259259
'Float cannot represent non numeric value: { value: 0.1 }',
260260
);
261-
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
261+
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
262262
'Float cannot represent non numeric value: ENUM_VALUE',
263263
);
264264
});
@@ -336,33 +336,33 @@ describe('Type System: Specified scalar types', () => {
336336
);
337337
});
338338

339-
it('parseLiteral', () => {
340-
function parseLiteral(str: string) {
341-
return GraphQLString.parseLiteral(parseConstValue(str));
339+
it('parseConstLiteral', () => {
340+
function parseConstLiteral(str: string) {
341+
return GraphQLString.parseConstLiteral(parseConstValue(str));
342342
}
343343

344-
expect(parseLiteral('"foo"')).to.equal('foo');
345-
expect(parseLiteral('"""bar"""')).to.equal('bar');
344+
expect(parseConstLiteral('"foo"')).to.equal('foo');
345+
expect(parseConstLiteral('"""bar"""')).to.equal('bar');
346346

347-
expect(() => parseLiteral('null')).to.throw(
347+
expect(() => parseConstLiteral('null')).to.throw(
348348
'String cannot represent a non string value: null',
349349
);
350-
expect(() => parseLiteral('1')).to.throw(
350+
expect(() => parseConstLiteral('1')).to.throw(
351351
'String cannot represent a non string value: 1',
352352
);
353-
expect(() => parseLiteral('0.1')).to.throw(
353+
expect(() => parseConstLiteral('0.1')).to.throw(
354354
'String cannot represent a non string value: 0.1',
355355
);
356-
expect(() => parseLiteral('false')).to.throw(
356+
expect(() => parseConstLiteral('false')).to.throw(
357357
'String cannot represent a non string value: false',
358358
);
359-
expect(() => parseLiteral('["foo"]')).to.throw(
359+
expect(() => parseConstLiteral('["foo"]')).to.throw(
360360
'String cannot represent a non string value: ["foo"]',
361361
);
362-
expect(() => parseLiteral('{ value: "foo" }')).to.throw(
362+
expect(() => parseConstLiteral('{ value: "foo" }')).to.throw(
363363
'String cannot represent a non string value: { value: "foo" }',
364364
);
365-
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
365+
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
366366
'String cannot represent a non string value: ENUM_VALUE',
367367
);
368368
});
@@ -445,39 +445,39 @@ describe('Type System: Specified scalar types', () => {
445445
);
446446
});
447447

448-
it('parseLiteral', () => {
449-
function parseLiteral(str: string) {
450-
return GraphQLBoolean.parseLiteral(parseConstValue(str));
448+
it('parseConstLiteral', () => {
449+
function parseConstLiteral(str: string) {
450+
return GraphQLBoolean.parseConstLiteral(parseConstValue(str));
451451
}
452452

453-
expect(parseLiteral('true')).to.equal(true);
454-
expect(parseLiteral('false')).to.equal(false);
453+
expect(parseConstLiteral('true')).to.equal(true);
454+
expect(parseConstLiteral('false')).to.equal(false);
455455

456-
expect(() => parseLiteral('null')).to.throw(
456+
expect(() => parseConstLiteral('null')).to.throw(
457457
'Boolean cannot represent a non boolean value: null',
458458
);
459-
expect(() => parseLiteral('0')).to.throw(
459+
expect(() => parseConstLiteral('0')).to.throw(
460460
'Boolean cannot represent a non boolean value: 0',
461461
);
462-
expect(() => parseLiteral('1')).to.throw(
462+
expect(() => parseConstLiteral('1')).to.throw(
463463
'Boolean cannot represent a non boolean value: 1',
464464
);
465-
expect(() => parseLiteral('0.1')).to.throw(
465+
expect(() => parseConstLiteral('0.1')).to.throw(
466466
'Boolean cannot represent a non boolean value: 0.1',
467467
);
468-
expect(() => parseLiteral('""')).to.throw(
468+
expect(() => parseConstLiteral('""')).to.throw(
469469
'Boolean cannot represent a non boolean value: ""',
470470
);
471-
expect(() => parseLiteral('"false"')).to.throw(
471+
expect(() => parseConstLiteral('"false"')).to.throw(
472472
'Boolean cannot represent a non boolean value: "false"',
473473
);
474-
expect(() => parseLiteral('[false]')).to.throw(
474+
expect(() => parseConstLiteral('[false]')).to.throw(
475475
'Boolean cannot represent a non boolean value: [false]',
476476
);
477-
expect(() => parseLiteral('{ value: false }')).to.throw(
477+
expect(() => parseConstLiteral('{ value: false }')).to.throw(
478478
'Boolean cannot represent a non boolean value: { value: false }',
479479
);
480-
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
480+
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
481481
'Boolean cannot represent a non boolean value: ENUM_VALUE',
482482
);
483483
});
@@ -557,39 +557,43 @@ describe('Type System: Specified scalar types', () => {
557557
);
558558
});
559559

560-
it('parseLiteral', () => {
561-
function parseLiteral(str: string) {
562-
return GraphQLID.parseLiteral(parseConstValue(str));
560+
it('parseConstLiteral', () => {
561+
function parseConstLiteral(str: string) {
562+
return GraphQLID.parseConstLiteral(parseConstValue(str));
563563
}
564564

565-
expect(parseLiteral('""')).to.equal('');
566-
expect(parseLiteral('"1"')).to.equal('1');
567-
expect(parseLiteral('"foo"')).to.equal('foo');
568-
expect(parseLiteral('"""foo"""')).to.equal('foo');
569-
expect(parseLiteral('1')).to.equal('1');
570-
expect(parseLiteral('0')).to.equal('0');
571-
expect(parseLiteral('-1')).to.equal('-1');
565+
expect(parseConstLiteral('""')).to.equal('');
566+
expect(parseConstLiteral('"1"')).to.equal('1');
567+
expect(parseConstLiteral('"foo"')).to.equal('foo');
568+
expect(parseConstLiteral('"""foo"""')).to.equal('foo');
569+
expect(parseConstLiteral('1')).to.equal('1');
570+
expect(parseConstLiteral('0')).to.equal('0');
571+
expect(parseConstLiteral('-1')).to.equal('-1');
572572

573573
// Support arbitrary long numbers even if they can't be represented in JS
574-
expect(parseLiteral('90071992547409910')).to.equal('90071992547409910');
575-
expect(parseLiteral('-90071992547409910')).to.equal('-90071992547409910');
574+
expect(parseConstLiteral('90071992547409910')).to.equal(
575+
'90071992547409910',
576+
);
577+
expect(parseConstLiteral('-90071992547409910')).to.equal(
578+
'-90071992547409910',
579+
);
576580

577-
expect(() => parseLiteral('null')).to.throw(
581+
expect(() => parseConstLiteral('null')).to.throw(
578582
'ID cannot represent a non-string and non-integer value: null',
579583
);
580-
expect(() => parseLiteral('0.1')).to.throw(
584+
expect(() => parseConstLiteral('0.1')).to.throw(
581585
'ID cannot represent a non-string and non-integer value: 0.1',
582586
);
583-
expect(() => parseLiteral('false')).to.throw(
587+
expect(() => parseConstLiteral('false')).to.throw(
584588
'ID cannot represent a non-string and non-integer value: false',
585589
);
586-
expect(() => parseLiteral('["1"]')).to.throw(
590+
expect(() => parseConstLiteral('["1"]')).to.throw(
587591
'ID cannot represent a non-string and non-integer value: ["1"]',
588592
);
589-
expect(() => parseLiteral('{ value: "1" }')).to.throw(
593+
expect(() => parseConstLiteral('{ value: "1" }')).to.throw(
590594
'ID cannot represent a non-string and non-integer value: { value: "1" }',
591595
);
592-
expect(() => parseLiteral('ENUM_VALUE')).to.throw(
596+
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
593597
'ID cannot represent a non-string and non-integer value: ENUM_VALUE',
594598
);
595599
});

0 commit comments

Comments
 (0)