Skip to content

Commit 10b8e95

Browse files
committed
Unify rest of error messages (#2161)
Continuation of #2160
1 parent 39bcf2b commit 10b8e95

File tree

10 files changed

+52
-48
lines changed

10 files changed

+52
-48
lines changed

src/execution/__tests__/abstract-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ describe('Execute: Handles execution of abstract types', () => {
417417
errors: [
418418
{
419419
message:
420-
'Abstract type FooInterface must resolve to an Object type at runtime for field Query.foo with value "dummy", received "[]". Either the FooInterface type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.',
420+
'Abstract type "FooInterface" must resolve to an Object type at runtime for field "Query.foo" with value "dummy", received "[]". Either the "FooInterface" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.',
421421
locations: [{ line: 1, column: 3 }],
422422
path: ['foo'],
423423
},

src/execution/__tests__/lists-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('Execute: Accepts any iterable as list value', () => {
8989
errors: [
9090
{
9191
message:
92-
'Expected Iterable, but did not find one for field DataType.test.',
92+
'Expected Iterable, but did not find one for field "DataType.test".',
9393
locations: [{ line: 1, column: 10 }],
9494
path: ['nest', 'test'],
9595
},

src/execution/__tests__/variables-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ describe('Execute: Handles inputs', () => {
372372
errors: [
373373
{
374374
message:
375-
'Variable "$input" got invalid value null at "input.c"; Expected non-nullable type String! not to be null.',
375+
'Variable "$input" got invalid value null at "input.c"; Expected non-nullable type "String!" not to be null.',
376376
locations: [{ line: 2, column: 16 }],
377377
},
378378
],
@@ -386,7 +386,7 @@ describe('Execute: Handles inputs', () => {
386386
errors: [
387387
{
388388
message:
389-
'Variable "$input" got invalid value "foo bar"; Expected type TestInputObject to be an object.',
389+
'Variable "$input" got invalid value "foo bar"; Expected type "TestInputObject" to be an object.',
390390
locations: [{ line: 2, column: 16 }],
391391
},
392392
],
@@ -400,7 +400,7 @@ describe('Execute: Handles inputs', () => {
400400
errors: [
401401
{
402402
message:
403-
'Variable "$input" got invalid value { a: "foo", b: "bar" }; Field c of required type String! was not provided.',
403+
'Variable "$input" got invalid value { a: "foo", b: "bar" }; Field "c" of required type "String!" was not provided.',
404404
locations: [{ line: 2, column: 16 }],
405405
},
406406
],
@@ -419,12 +419,12 @@ describe('Execute: Handles inputs', () => {
419419
errors: [
420420
{
421421
message:
422-
'Variable "$input" got invalid value { a: "foo" } at "input.na"; Field c of required type String! was not provided.',
422+
'Variable "$input" got invalid value { a: "foo" } at "input.na"; Field "c" of required type "String!" was not provided.',
423423
locations: [{ line: 2, column: 18 }],
424424
},
425425
{
426426
message:
427-
'Variable "$input" got invalid value { na: { a: "foo" } }; Field nb of required type String! was not provided.',
427+
'Variable "$input" got invalid value { na: { a: "foo" } }; Field "nb" of required type "String!" was not provided.',
428428
locations: [{ line: 2, column: 18 }],
429429
},
430430
],
@@ -441,7 +441,7 @@ describe('Execute: Handles inputs', () => {
441441
errors: [
442442
{
443443
message:
444-
'Variable "$input" got invalid value { a: "foo", b: "bar", c: "baz", extra: "dog" }; Field "extra" is not defined by type TestInputObject.',
444+
'Variable "$input" got invalid value { a: "foo", b: "bar", c: "baz", extra: "dog" }; Field "extra" is not defined by type "TestInputObject".',
445445
locations: [{ line: 2, column: 16 }],
446446
},
447447
],
@@ -687,7 +687,7 @@ describe('Execute: Handles inputs', () => {
687687
errors: [
688688
{
689689
message:
690-
'Variable "$value" got invalid value [1, 2, 3]; Expected type String. String cannot represent a non string value: [1, 2, 3]',
690+
'Variable "$value" got invalid value [1, 2, 3]; Expected type "String". String cannot represent a non string value: [1, 2, 3]',
691691
locations: [{ line: 2, column: 16 }],
692692
},
693693
],
@@ -833,7 +833,7 @@ describe('Execute: Handles inputs', () => {
833833
errors: [
834834
{
835835
message:
836-
'Variable "$input" got invalid value null at "input[1]"; Expected non-nullable type String! not to be null.',
836+
'Variable "$input" got invalid value null at "input[1]"; Expected non-nullable type "String!" not to be null.',
837837
locations: [{ line: 2, column: 16 }],
838838
},
839839
],
@@ -882,7 +882,7 @@ describe('Execute: Handles inputs', () => {
882882
errors: [
883883
{
884884
message:
885-
'Variable "$input" got invalid value null at "input[1]"; Expected non-nullable type String! not to be null.',
885+
'Variable "$input" got invalid value null at "input[1]"; Expected non-nullable type "String!" not to be null.',
886886
locations: [{ line: 2, column: 16 }],
887887
},
888888
],
@@ -1006,7 +1006,7 @@ describe('Execute: Handles inputs', () => {
10061006

10071007
function invalidValueError(value, index) {
10081008
return {
1009-
message: `Variable "$input" got invalid value ${value} at "input[${index}]"; Expected type String. String cannot represent a non string value: ${value}`,
1009+
message: `Variable "$input" got invalid value ${value} at "input[${index}]"; Expected type "String". String cannot represent a non string value: ${value}`,
10101010
locations: [{ line: 2, column: 14 }],
10111011
};
10121012
}

src/execution/execute.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ function completeListValue(
887887
): PromiseOrValue<$ReadOnlyArray<mixed>> {
888888
if (!isCollection(result)) {
889889
throw new GraphQLError(
890-
`Expected Iterable, but did not find one for field ${info.parentType.name}.${info.fieldName}.`,
890+
`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
891891
);
892892
}
893893

@@ -1001,9 +1001,9 @@ function ensureValidRuntimeType(
10011001

10021002
if (!isObjectType(runtimeType)) {
10031003
throw new GraphQLError(
1004-
`Abstract type ${returnType.name} must resolve to an Object type at runtime for field ${info.parentType.name}.${info.fieldName} with ` +
1004+
`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
10051005
`value ${inspect(result)}, received "${inspect(runtimeType)}". ` +
1006-
`Either the ${returnType.name} type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
1006+
`Either the "${returnType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
10071007
fieldNodes,
10081008
);
10091009
}

src/subscription/__tests__/subscribe-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ describe('Subscription Initialization Phase', () => {
528528
errors: [
529529
{
530530
message:
531-
'Variable "$priority" got invalid value "meow"; Expected type Int. Int cannot represent non-integer value: "meow"',
531+
'Variable "$priority" got invalid value "meow"; Expected type "Int". Int cannot represent non-integer value: "meow"',
532532
locations: [{ line: 2, column: 21 }],
533533
},
534534
],

src/type/__tests__/enumType-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe('Type System: Enum Values', () => {
267267
errors: [
268268
{
269269
message:
270-
'Variable "$color" got invalid value 2; Expected type Color.',
270+
'Variable "$color" got invalid value 2; Expected type "Color".',
271271
locations: [{ line: 1, column: 8 }],
272272
},
273273
],

src/utilities/__tests__/coerceInputValue-test.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('coerceInputValue', () => {
4949
const result = coerceValue(undefined, TestNonNull);
5050
expectErrors(result).to.deep.equal([
5151
{
52-
error: 'Expected non-nullable type Int! not to be null.',
52+
error: 'Expected non-nullable type "Int!" not to be null.',
5353
path: [],
5454
value: undefined,
5555
},
@@ -60,7 +60,7 @@ describe('coerceInputValue', () => {
6060
const result = coerceValue(null, TestNonNull);
6161
expectErrors(result).to.deep.equal([
6262
{
63-
error: 'Expected non-nullable type Int! not to be null.',
63+
error: 'Expected non-nullable type "Int!" not to be null.',
6464
path: [],
6565
value: null,
6666
},
@@ -99,7 +99,7 @@ describe('coerceInputValue', () => {
9999
const result = coerceValue({ value: undefined }, TestScalar);
100100
expectErrors(result).to.deep.equal([
101101
{
102-
error: 'Expected type TestScalar.',
102+
error: 'Expected type "TestScalar".',
103103
path: [],
104104
value: { value: undefined },
105105
},
@@ -111,7 +111,7 @@ describe('coerceInputValue', () => {
111111
const result = coerceValue(inputValue, TestScalar);
112112
expectErrors(result).to.deep.equal([
113113
{
114-
error: 'Expected type TestScalar. Some error message',
114+
error: 'Expected type "TestScalar". Some error message',
115115
path: [],
116116
value: { error: 'Some error message' },
117117
},
@@ -140,7 +140,7 @@ describe('coerceInputValue', () => {
140140
const result = coerceValue('foo', TestEnum);
141141
expectErrors(result).to.deep.equal([
142142
{
143-
error: 'Expected type TestEnum. Did you mean FOO?',
143+
error: 'Expected type "TestEnum". Did you mean the enum value "FOO"?',
144144
path: [],
145145
value: 'foo',
146146
},
@@ -151,7 +151,7 @@ describe('coerceInputValue', () => {
151151
const result1 = coerceValue(123, TestEnum);
152152
expectErrors(result1).to.deep.equal([
153153
{
154-
error: 'Expected type TestEnum.',
154+
error: 'Expected type "TestEnum".',
155155
path: [],
156156
value: 123,
157157
},
@@ -160,7 +160,7 @@ describe('coerceInputValue', () => {
160160
const result2 = coerceValue({ field: 'value' }, TestEnum);
161161
expectErrors(result2).to.deep.equal([
162162
{
163-
error: 'Expected type TestEnum.',
163+
error: 'Expected type "TestEnum".',
164164
path: [],
165165
value: { field: 'value' },
166166
},
@@ -186,7 +186,7 @@ describe('coerceInputValue', () => {
186186
const result = coerceValue(123, TestInputObject);
187187
expectErrors(result).to.deep.equal([
188188
{
189-
error: 'Expected type TestInputObject to be an object.',
189+
error: 'Expected type "TestInputObject" to be an object.',
190190
path: [],
191191
value: 123,
192192
},
@@ -198,7 +198,7 @@ describe('coerceInputValue', () => {
198198
expectErrors(result).to.deep.equal([
199199
{
200200
error:
201-
'Expected type Int. Int cannot represent non-integer value: NaN',
201+
'Expected type "Int". Int cannot represent non-integer value: NaN',
202202
path: ['foo'],
203203
value: NaN,
204204
},
@@ -210,13 +210,13 @@ describe('coerceInputValue', () => {
210210
expectErrors(result).to.deep.equal([
211211
{
212212
error:
213-
'Expected type Int. Int cannot represent non-integer value: "abc"',
213+
'Expected type "Int". Int cannot represent non-integer value: "abc"',
214214
path: ['foo'],
215215
value: 'abc',
216216
},
217217
{
218218
error:
219-
'Expected type Int. Int cannot represent non-integer value: "def"',
219+
'Expected type "Int". Int cannot represent non-integer value: "def"',
220220
path: ['bar'],
221221
value: 'def',
222222
},
@@ -227,7 +227,7 @@ describe('coerceInputValue', () => {
227227
const result = coerceValue({ bar: 123 }, TestInputObject);
228228
expectErrors(result).to.deep.equal([
229229
{
230-
error: 'Field foo of required type Int! was not provided.',
230+
error: 'Field "foo" of required type "Int!" was not provided.',
231231
path: [],
232232
value: { bar: 123 },
233233
},
@@ -241,7 +241,8 @@ describe('coerceInputValue', () => {
241241
);
242242
expectErrors(result).to.deep.equal([
243243
{
244-
error: 'Field "unknownField" is not defined by type TestInputObject.',
244+
error:
245+
'Field "unknownField" is not defined by type "TestInputObject".',
245246
path: [],
246247
value: { foo: 123, unknownField: 123 },
247248
},
@@ -253,7 +254,7 @@ describe('coerceInputValue', () => {
253254
expectErrors(result).to.deep.equal([
254255
{
255256
error:
256-
'Field "bart" is not defined by type TestInputObject. Did you mean bar?',
257+
'Field "bart" is not defined by type "TestInputObject". Did you mean "bar"?',
257258
path: [],
258259
value: { foo: 123, bart: 123 },
259260
},
@@ -309,13 +310,13 @@ describe('coerceInputValue', () => {
309310
expectErrors(result).to.deep.equal([
310311
{
311312
error:
312-
'Expected type Int. Int cannot represent non-integer value: "b"',
313+
'Expected type "Int". Int cannot represent non-integer value: "b"',
313314
path: [1],
314315
value: 'b',
315316
},
316317
{
317318
error:
318-
'Expected type Int. Int cannot represent non-integer value: true',
319+
'Expected type "Int". Int cannot represent non-integer value: true',
319320
path: [2],
320321
value: true,
321322
},
@@ -332,7 +333,7 @@ describe('coerceInputValue', () => {
332333
expectErrors(result).to.deep.equal([
333334
{
334335
error:
335-
'Expected type Int. Int cannot represent non-integer value: "INVALID"',
336+
'Expected type "Int". Int cannot represent non-integer value: "INVALID"',
336337
path: [],
337338
value: 'INVALID',
338339
},
@@ -377,15 +378,15 @@ describe('coerceInputValue', () => {
377378
describe('with default onError', () => {
378379
it('throw error without path', () => {
379380
expect(() => coerceInputValue(null, GraphQLNonNull(GraphQLInt))).to.throw(
380-
'Invalid value null: Expected non-nullable type Int! not to be null.',
381+
'Invalid value null: Expected non-nullable type "Int!" not to be null.',
381382
);
382383
});
383384

384385
it('throw error with path', () => {
385386
expect(() =>
386387
coerceInputValue([null], GraphQLList(GraphQLNonNull(GraphQLInt))),
387388
).to.throw(
388-
'Invalid value null at "value[0]": : Expected non-nullable type Int! not to be null.',
389+
'Invalid value null at "value[0]": : Expected non-nullable type "Int!" not to be null.',
389390
);
390391
});
391392
});

src/utilities/__tests__/findDeprecatedUsages-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('findDeprecatedUsages', () => {
3939
const errorMessages = errors.map(err => err.message);
4040

4141
expect(errorMessages).to.deep.equal([
42-
'The field Query.deprecatedField is deprecated. Some field reason.',
42+
'The field "Query.deprecatedField" is deprecated. Some field reason.',
4343
]);
4444
});
4545

@@ -52,7 +52,7 @@ describe('findDeprecatedUsages', () => {
5252
const errorMessages = errors.map(err => err.message);
5353

5454
expect(errorMessages).to.deep.equal([
55-
'The enum value EnumType.TWO is deprecated. Some enum reason.',
55+
'The enum value "EnumType.TWO" is deprecated. Some enum reason.',
5656
]);
5757
});
5858
});

src/utilities/coerceInputValue.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function coerceInputValueImpl(
6666
pathToArray(path),
6767
inputValue,
6868
new GraphQLError(
69-
`Expected non-nullable type ${inspect(type)} not to be null.`,
69+
`Expected non-nullable type "${inspect(type)}" not to be null.`,
7070
),
7171
);
7272
return;
@@ -102,7 +102,7 @@ function coerceInputValueImpl(
102102
onError(
103103
pathToArray(path),
104104
inputValue,
105-
new GraphQLError(`Expected type ${type.name} to be an object.`),
105+
new GraphQLError(`Expected type "${type.name}" to be an object.`),
106106
);
107107
return;
108108
}
@@ -122,7 +122,7 @@ function coerceInputValueImpl(
122122
pathToArray(path),
123123
inputValue,
124124
new GraphQLError(
125-
`Field ${field.name} of required type ${typeStr} was not provided.`,
125+
`Field "${field.name}" of required type "${typeStr}" was not provided.`,
126126
),
127127
);
128128
}
@@ -148,8 +148,8 @@ function coerceInputValueImpl(
148148
pathToArray(path),
149149
inputValue,
150150
new GraphQLError(
151-
`Field "${fieldName}" is not defined by type ${type.name}.` +
152-
didYouMean(suggestions),
151+
`Field "${fieldName}" is not defined by type "${type.name}".` +
152+
didYouMean(suggestions.map(x => `"${x}"`)),
153153
),
154154
);
155155
}
@@ -170,7 +170,7 @@ function coerceInputValueImpl(
170170
pathToArray(path),
171171
inputValue,
172172
new GraphQLError(
173-
`Expected type ${type.name}. ` + error.message,
173+
`Expected type "${type.name}". ` + error.message,
174174
undefined,
175175
undefined,
176176
undefined,
@@ -184,7 +184,7 @@ function coerceInputValueImpl(
184184
onError(
185185
pathToArray(path),
186186
inputValue,
187-
new GraphQLError(`Expected type ${type.name}.`),
187+
new GraphQLError(`Expected type "${type.name}".`),
188188
);
189189
}
190190
return parseResult;
@@ -204,7 +204,10 @@ function coerceInputValueImpl(
204204
onError(
205205
pathToArray(path),
206206
inputValue,
207-
new GraphQLError(`Expected type ${type.name}.` + didYouMean(suggestions)),
207+
new GraphQLError(
208+
`Expected type "${type.name}".` +
209+
didYouMean('the enum value', suggestions.map(x => `"${x}"`)),
210+
),
208211
);
209212
return;
210213
}

0 commit comments

Comments
 (0)