Skip to content

Commit bd3afde

Browse files
committed
rename parseConstValue method to coerceInputLiteral
following convention suggested in #2357
1 parent 0ea9241 commit bd3afde

File tree

9 files changed

+121
-117
lines changed

9 files changed

+121
-117
lines changed

integrationTests/ts/kitchenSink-test.ts

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

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

src/execution/__tests__/variables-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const TestFaultyScalar = new GraphQLScalarType({
4747
parseValue() {
4848
throw TestFaultyScalarGraphQLError;
4949
},
50-
parseConstLiteral() {
50+
coerceInputLiteral() {
5151
throw TestFaultyScalarGraphQLError;
5252
},
5353
});
@@ -58,7 +58,7 @@ const TestComplexScalar = new GraphQLScalarType({
5858
expect(value).to.equal('SerializedValue');
5959
return 'DeserializedValue';
6060
},
61-
parseConstLiteral(ast) {
61+
coerceInputLiteral(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 parseConstLiteral on complex scalar types', () => {
284+
it('properly runs coerceInputLiteral on complex scalar types', () => {
285285
const result = executeQuery(`
286286
{
287287
fieldWithObjectInput(input: {c: "foo", d: "SerializedValue"})

src/type/__tests__/definition-test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Type System: Scalars', () => {
6060
serialize: someScalar.serialize,
6161
parseValue: someScalar.parseValue,
6262
parseLiteral: someScalar.parseLiteral,
63-
parseConstLiteral: undefined,
63+
coerceInputLiteral: undefined,
6464
valueToLiteral: undefined,
6565
extensions: {},
6666
astNode: undefined,
@@ -76,7 +76,7 @@ describe('Type System: Scalars', () => {
7676
serialize: passThroughFunc,
7777
parseValue: passThroughFunc,
7878
parseLiteral: passThroughFunc,
79-
parseConstLiteral: passThroughFunc,
79+
coerceInputLiteral: passThroughFunc,
8080
valueToLiteral: passThroughFunc,
8181
extensions: { someExtension: 'extension' },
8282
astNode: dummyAny,
@@ -93,7 +93,7 @@ describe('Type System: Scalars', () => {
9393
expect(scalar.parseValue).to.equal(identityFunc);
9494
expect(scalar.parseLiteral).to.be.a('function');
9595
/* default will be provided in v18 when parseLiteral is removed */
96-
// expect(scalar.parseConstLiteral).to.be.a('function');
96+
// expect(scalar.coerceInputLiteral).to.be.a('function');
9797
});
9898

9999
it('use parseValue for parsing literals if parseLiteral omitted', () => {
@@ -124,15 +124,15 @@ describe('Type System: Scalars', () => {
124124
);
125125
});
126126

127-
it('rejects a Scalar type defining parseConstLiteral but not parseValue', () => {
127+
it('rejects a Scalar type defining coerceInputLiteral but not parseValue', () => {
128128
expect(
129129
() =>
130130
new GraphQLScalarType({
131131
name: 'SomeScalar',
132-
parseConstLiteral: passThroughFunc,
132+
coerceInputLiteral: passThroughFunc,
133133
}),
134134
).to.throw(
135-
'SomeScalar must provide both "parseValue" and "parseConstLiteral" functions.',
135+
'SomeScalar must provide both "parseValue" and "coerceInputLiteral" functions.',
136136
);
137137
});
138138
});

src/type/__tests__/scalars-test.ts

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -64,45 +64,45 @@ describe('Type System: Specified scalar types', () => {
6464
);
6565
});
6666

67-
it('parseConstLiteral', () => {
68-
function parseConstLiteral(str: string) {
67+
it('coerceInputLiteral', () => {
68+
function coerceInputLiteral(str: string) {
6969
/* @ts-expect-error to be removed in v18 when all custom scalars will have default method */
70-
return GraphQLInt.parseConstLiteral(parseConstValue(str));
70+
return GraphQLInt.coerceInputLiteral(parseConstValue(str));
7171
}
7272

73-
expect(parseConstLiteral('1')).to.equal(1);
74-
expect(parseConstLiteral('0')).to.equal(0);
75-
expect(parseConstLiteral('-1')).to.equal(-1);
73+
expect(coerceInputLiteral('1')).to.equal(1);
74+
expect(coerceInputLiteral('0')).to.equal(0);
75+
expect(coerceInputLiteral('-1')).to.equal(-1);
7676

77-
expect(() => parseConstLiteral('9876504321')).to.throw(
77+
expect(() => coerceInputLiteral('9876504321')).to.throw(
7878
'Int cannot represent non 32-bit signed integer value: 9876504321',
7979
);
80-
expect(() => parseConstLiteral('-9876504321')).to.throw(
80+
expect(() => coerceInputLiteral('-9876504321')).to.throw(
8181
'Int cannot represent non 32-bit signed integer value: -9876504321',
8282
);
8383

84-
expect(() => parseConstLiteral('1.0')).to.throw(
84+
expect(() => coerceInputLiteral('1.0')).to.throw(
8585
'Int cannot represent non-integer value: 1.0',
8686
);
87-
expect(() => parseConstLiteral('null')).to.throw(
87+
expect(() => coerceInputLiteral('null')).to.throw(
8888
'Int cannot represent non-integer value: null',
8989
);
90-
expect(() => parseConstLiteral('""')).to.throw(
90+
expect(() => coerceInputLiteral('""')).to.throw(
9191
'Int cannot represent non-integer value: ""',
9292
);
93-
expect(() => parseConstLiteral('"123"')).to.throw(
93+
expect(() => coerceInputLiteral('"123"')).to.throw(
9494
'Int cannot represent non-integer value: "123"',
9595
);
96-
expect(() => parseConstLiteral('false')).to.throw(
96+
expect(() => coerceInputLiteral('false')).to.throw(
9797
'Int cannot represent non-integer value: false',
9898
);
99-
expect(() => parseConstLiteral('[1]')).to.throw(
99+
expect(() => coerceInputLiteral('[1]')).to.throw(
100100
'Int cannot represent non-integer value: [1]',
101101
);
102-
expect(() => parseConstLiteral('{ value: 1 }')).to.throw(
102+
expect(() => coerceInputLiteral('{ value: 1 }')).to.throw(
103103
'Int cannot represent non-integer value: { value: 1 }',
104104
);
105-
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
105+
expect(() => coerceInputLiteral('ENUM_VALUE')).to.throw(
106106
'Int cannot represent non-integer value: ENUM_VALUE',
107107
);
108108
});
@@ -227,40 +227,40 @@ describe('Type System: Specified scalar types', () => {
227227
);
228228
});
229229

230-
it('parseConstLiteral', () => {
231-
function parseConstLiteral(str: string) {
230+
it('coerceInputLiteral', () => {
231+
function coerceInputLiteral(str: string) {
232232
/* @ts-expect-error to be removed in v18 when all custom scalars will have default method */
233-
return GraphQLFloat.parseConstLiteral(parseConstValue(str));
233+
return GraphQLFloat.coerceInputLiteral(parseConstValue(str));
234234
}
235235

236-
expect(parseConstLiteral('1')).to.equal(1);
237-
expect(parseConstLiteral('0')).to.equal(0);
238-
expect(parseConstLiteral('-1')).to.equal(-1);
239-
expect(parseConstLiteral('0.1')).to.equal(0.1);
240-
expect(parseConstLiteral(Math.PI.toString())).to.equal(Math.PI);
236+
expect(coerceInputLiteral('1')).to.equal(1);
237+
expect(coerceInputLiteral('0')).to.equal(0);
238+
expect(coerceInputLiteral('-1')).to.equal(-1);
239+
expect(coerceInputLiteral('0.1')).to.equal(0.1);
240+
expect(coerceInputLiteral(Math.PI.toString())).to.equal(Math.PI);
241241

242-
expect(() => parseConstLiteral('null')).to.throw(
242+
expect(() => coerceInputLiteral('null')).to.throw(
243243
'Float cannot represent non numeric value: null',
244244
);
245-
expect(() => parseConstLiteral('""')).to.throw(
245+
expect(() => coerceInputLiteral('""')).to.throw(
246246
'Float cannot represent non numeric value: ""',
247247
);
248-
expect(() => parseConstLiteral('"123"')).to.throw(
248+
expect(() => coerceInputLiteral('"123"')).to.throw(
249249
'Float cannot represent non numeric value: "123"',
250250
);
251-
expect(() => parseConstLiteral('"123.5"')).to.throw(
251+
expect(() => coerceInputLiteral('"123.5"')).to.throw(
252252
'Float cannot represent non numeric value: "123.5"',
253253
);
254-
expect(() => parseConstLiteral('false')).to.throw(
254+
expect(() => coerceInputLiteral('false')).to.throw(
255255
'Float cannot represent non numeric value: false',
256256
);
257-
expect(() => parseConstLiteral('[0.1]')).to.throw(
257+
expect(() => coerceInputLiteral('[0.1]')).to.throw(
258258
'Float cannot represent non numeric value: [0.1]',
259259
);
260-
expect(() => parseConstLiteral('{ value: 0.1 }')).to.throw(
260+
expect(() => coerceInputLiteral('{ value: 0.1 }')).to.throw(
261261
'Float cannot represent non numeric value: { value: 0.1 }',
262262
);
263-
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
263+
expect(() => coerceInputLiteral('ENUM_VALUE')).to.throw(
264264
'Float cannot represent non numeric value: ENUM_VALUE',
265265
);
266266
});
@@ -338,34 +338,34 @@ describe('Type System: Specified scalar types', () => {
338338
);
339339
});
340340

341-
it('parseConstLiteral', () => {
342-
function parseConstLiteral(str: string) {
341+
it('coerceInputLiteral', () => {
342+
function coerceInputLiteral(str: string) {
343343
/* @ts-expect-error to be removed in v18 when all custom scalars will have default method */
344-
return GraphQLString.parseConstLiteral(parseConstValue(str));
344+
return GraphQLString.coerceInputLiteral(parseConstValue(str));
345345
}
346346

347-
expect(parseConstLiteral('"foo"')).to.equal('foo');
348-
expect(parseConstLiteral('"""bar"""')).to.equal('bar');
347+
expect(coerceInputLiteral('"foo"')).to.equal('foo');
348+
expect(coerceInputLiteral('"""bar"""')).to.equal('bar');
349349

350-
expect(() => parseConstLiteral('null')).to.throw(
350+
expect(() => coerceInputLiteral('null')).to.throw(
351351
'String cannot represent a non string value: null',
352352
);
353-
expect(() => parseConstLiteral('1')).to.throw(
353+
expect(() => coerceInputLiteral('1')).to.throw(
354354
'String cannot represent a non string value: 1',
355355
);
356-
expect(() => parseConstLiteral('0.1')).to.throw(
356+
expect(() => coerceInputLiteral('0.1')).to.throw(
357357
'String cannot represent a non string value: 0.1',
358358
);
359-
expect(() => parseConstLiteral('false')).to.throw(
359+
expect(() => coerceInputLiteral('false')).to.throw(
360360
'String cannot represent a non string value: false',
361361
);
362-
expect(() => parseConstLiteral('["foo"]')).to.throw(
362+
expect(() => coerceInputLiteral('["foo"]')).to.throw(
363363
'String cannot represent a non string value: ["foo"]',
364364
);
365-
expect(() => parseConstLiteral('{ value: "foo" }')).to.throw(
365+
expect(() => coerceInputLiteral('{ value: "foo" }')).to.throw(
366366
'String cannot represent a non string value: { value: "foo" }',
367367
);
368-
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
368+
expect(() => coerceInputLiteral('ENUM_VALUE')).to.throw(
369369
'String cannot represent a non string value: ENUM_VALUE',
370370
);
371371
});
@@ -448,40 +448,40 @@ describe('Type System: Specified scalar types', () => {
448448
);
449449
});
450450

451-
it('parseConstLiteral', () => {
452-
function parseConstLiteral(str: string) {
451+
it('coerceInputLiteral', () => {
452+
function coerceInputLiteral(str: string) {
453453
/* @ts-expect-error to be removed in v18 when all custom scalars will have default method */
454-
return GraphQLBoolean.parseConstLiteral(parseConstValue(str));
454+
return GraphQLBoolean.coerceInputLiteral(parseConstValue(str));
455455
}
456456

457-
expect(parseConstLiteral('true')).to.equal(true);
458-
expect(parseConstLiteral('false')).to.equal(false);
457+
expect(coerceInputLiteral('true')).to.equal(true);
458+
expect(coerceInputLiteral('false')).to.equal(false);
459459

460-
expect(() => parseConstLiteral('null')).to.throw(
460+
expect(() => coerceInputLiteral('null')).to.throw(
461461
'Boolean cannot represent a non boolean value: null',
462462
);
463-
expect(() => parseConstLiteral('0')).to.throw(
463+
expect(() => coerceInputLiteral('0')).to.throw(
464464
'Boolean cannot represent a non boolean value: 0',
465465
);
466-
expect(() => parseConstLiteral('1')).to.throw(
466+
expect(() => coerceInputLiteral('1')).to.throw(
467467
'Boolean cannot represent a non boolean value: 1',
468468
);
469-
expect(() => parseConstLiteral('0.1')).to.throw(
469+
expect(() => coerceInputLiteral('0.1')).to.throw(
470470
'Boolean cannot represent a non boolean value: 0.1',
471471
);
472-
expect(() => parseConstLiteral('""')).to.throw(
472+
expect(() => coerceInputLiteral('""')).to.throw(
473473
'Boolean cannot represent a non boolean value: ""',
474474
);
475-
expect(() => parseConstLiteral('"false"')).to.throw(
475+
expect(() => coerceInputLiteral('"false"')).to.throw(
476476
'Boolean cannot represent a non boolean value: "false"',
477477
);
478-
expect(() => parseConstLiteral('[false]')).to.throw(
478+
expect(() => coerceInputLiteral('[false]')).to.throw(
479479
'Boolean cannot represent a non boolean value: [false]',
480480
);
481-
expect(() => parseConstLiteral('{ value: false }')).to.throw(
481+
expect(() => coerceInputLiteral('{ value: false }')).to.throw(
482482
'Boolean cannot represent a non boolean value: { value: false }',
483483
);
484-
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
484+
expect(() => coerceInputLiteral('ENUM_VALUE')).to.throw(
485485
'Boolean cannot represent a non boolean value: ENUM_VALUE',
486486
);
487487
});
@@ -561,44 +561,44 @@ describe('Type System: Specified scalar types', () => {
561561
);
562562
});
563563

564-
it('parseConstLiteral', () => {
565-
function parseConstLiteral(str: string) {
564+
it('coerceInputLiteral', () => {
565+
function coerceInputLiteral(str: string) {
566566
/* @ts-expect-error to be removed in v18 when all custom scalars will have default method */
567-
return GraphQLID.parseConstLiteral(parseConstValue(str));
567+
return GraphQLID.coerceInputLiteral(parseConstValue(str));
568568
}
569569

570-
expect(parseConstLiteral('""')).to.equal('');
571-
expect(parseConstLiteral('"1"')).to.equal('1');
572-
expect(parseConstLiteral('"foo"')).to.equal('foo');
573-
expect(parseConstLiteral('"""foo"""')).to.equal('foo');
574-
expect(parseConstLiteral('1')).to.equal('1');
575-
expect(parseConstLiteral('0')).to.equal('0');
576-
expect(parseConstLiteral('-1')).to.equal('-1');
570+
expect(coerceInputLiteral('""')).to.equal('');
571+
expect(coerceInputLiteral('"1"')).to.equal('1');
572+
expect(coerceInputLiteral('"foo"')).to.equal('foo');
573+
expect(coerceInputLiteral('"""foo"""')).to.equal('foo');
574+
expect(coerceInputLiteral('1')).to.equal('1');
575+
expect(coerceInputLiteral('0')).to.equal('0');
576+
expect(coerceInputLiteral('-1')).to.equal('-1');
577577

578578
// Support arbitrary long numbers even if they can't be represented in JS
579-
expect(parseConstLiteral('90071992547409910')).to.equal(
579+
expect(coerceInputLiteral('90071992547409910')).to.equal(
580580
'90071992547409910',
581581
);
582-
expect(parseConstLiteral('-90071992547409910')).to.equal(
582+
expect(coerceInputLiteral('-90071992547409910')).to.equal(
583583
'-90071992547409910',
584584
);
585585

586-
expect(() => parseConstLiteral('null')).to.throw(
586+
expect(() => coerceInputLiteral('null')).to.throw(
587587
'ID cannot represent a non-string and non-integer value: null',
588588
);
589-
expect(() => parseConstLiteral('0.1')).to.throw(
589+
expect(() => coerceInputLiteral('0.1')).to.throw(
590590
'ID cannot represent a non-string and non-integer value: 0.1',
591591
);
592-
expect(() => parseConstLiteral('false')).to.throw(
592+
expect(() => coerceInputLiteral('false')).to.throw(
593593
'ID cannot represent a non-string and non-integer value: false',
594594
);
595-
expect(() => parseConstLiteral('["1"]')).to.throw(
595+
expect(() => coerceInputLiteral('["1"]')).to.throw(
596596
'ID cannot represent a non-string and non-integer value: ["1"]',
597597
);
598-
expect(() => parseConstLiteral('{ value: "1" }')).to.throw(
598+
expect(() => coerceInputLiteral('{ value: "1" }')).to.throw(
599599
'ID cannot represent a non-string and non-integer value: { value: "1" }',
600600
);
601-
expect(() => parseConstLiteral('ENUM_VALUE')).to.throw(
601+
expect(() => coerceInputLiteral('ENUM_VALUE')).to.throw(
602602
'ID cannot represent a non-string and non-integer value: ENUM_VALUE',
603603
);
604604
});

0 commit comments

Comments
 (0)