Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify rest of error messages #2161

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/execution/__tests__/abstract-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ describe('Execute: Handles execution of abstract types', () => {
errors: [
{
message:
'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.',
'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.',
locations: [{ line: 1, column: 3 }],
path: ['foo'],
},
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/lists-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('Execute: Accepts any iterable as list value', () => {
errors: [
{
message:
'Expected Iterable, but did not find one for field DataType.test.',
'Expected Iterable, but did not find one for field "DataType.test".',
locations: [{ line: 1, column: 10 }],
path: ['nest', 'test'],
},
Expand Down
20 changes: 10 additions & 10 deletions src/execution/__tests__/variables-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" got invalid value null at "input.c"; Expected non-nullable type String! not to be null.',
'Variable "$input" got invalid value null at "input.c"; Expected non-nullable type "String!" not to be null.',
locations: [{ line: 2, column: 16 }],
},
],
Expand All @@ -386,7 +386,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" got invalid value "foo bar"; Expected type TestInputObject to be an object.',
'Variable "$input" got invalid value "foo bar"; Expected type "TestInputObject" to be an object.',
locations: [{ line: 2, column: 16 }],
},
],
Expand All @@ -400,7 +400,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" got invalid value { a: "foo", b: "bar" }; Field c of required type String! was not provided.',
'Variable "$input" got invalid value { a: "foo", b: "bar" }; Field "c" of required type "String!" was not provided.',
locations: [{ line: 2, column: 16 }],
},
],
Expand All @@ -419,12 +419,12 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" got invalid value { a: "foo" } at "input.na"; Field c of required type String! was not provided.',
'Variable "$input" got invalid value { a: "foo" } at "input.na"; Field "c" of required type "String!" was not provided.',
locations: [{ line: 2, column: 18 }],
},
{
message:
'Variable "$input" got invalid value { na: { a: "foo" } }; Field nb of required type String! was not provided.',
'Variable "$input" got invalid value { na: { a: "foo" } }; Field "nb" of required type "String!" was not provided.',
locations: [{ line: 2, column: 18 }],
},
],
Expand All @@ -441,7 +441,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" got invalid value { a: "foo", b: "bar", c: "baz", extra: "dog" }; Field "extra" is not defined by type TestInputObject.',
'Variable "$input" got invalid value { a: "foo", b: "bar", c: "baz", extra: "dog" }; Field "extra" is not defined by type "TestInputObject".',
locations: [{ line: 2, column: 16 }],
},
],
Expand Down Expand Up @@ -687,7 +687,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$value" got invalid value [1, 2, 3]; Expected type String. String cannot represent a non string value: [1, 2, 3]',
'Variable "$value" got invalid value [1, 2, 3]; Expected type "String". String cannot represent a non string value: [1, 2, 3]',
locations: [{ line: 2, column: 16 }],
},
],
Expand Down Expand Up @@ -833,7 +833,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" got invalid value null at "input[1]"; Expected non-nullable type String! not to be null.',
'Variable "$input" got invalid value null at "input[1]"; Expected non-nullable type "String!" not to be null.',
locations: [{ line: 2, column: 16 }],
},
],
Expand Down Expand Up @@ -882,7 +882,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Variable "$input" got invalid value null at "input[1]"; Expected non-nullable type String! not to be null.',
'Variable "$input" got invalid value null at "input[1]"; Expected non-nullable type "String!" not to be null.',
locations: [{ line: 2, column: 16 }],
},
],
Expand Down Expand Up @@ -1006,7 +1006,7 @@ describe('Execute: Handles inputs', () => {

function invalidValueError(value, index) {
return {
message: `Variable "$input" got invalid value ${value} at "input[${index}]"; Expected type String. String cannot represent a non string value: ${value}`,
message: `Variable "$input" got invalid value ${value} at "input[${index}]"; Expected type "String". String cannot represent a non string value: ${value}`,
locations: [{ line: 2, column: 14 }],
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ function completeListValue(
): PromiseOrValue<$ReadOnlyArray<mixed>> {
if (!isCollection(result)) {
throw new GraphQLError(
`Expected Iterable, but did not find one for field ${info.parentType.name}.${info.fieldName}.`,
`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
);
}

Expand Down Expand Up @@ -1001,9 +1001,9 @@ function ensureValidRuntimeType(

if (!isObjectType(runtimeType)) {
throw new GraphQLError(
`Abstract type ${returnType.name} must resolve to an Object type at runtime for field ${info.parentType.name}.${info.fieldName} with ` +
`Abstract type "${returnType.name}" must resolve to an Object type at runtime for field "${info.parentType.name}.${info.fieldName}" with ` +
`value ${inspect(result)}, received "${inspect(runtimeType)}". ` +
`Either the ${returnType.name} type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
`Either the "${returnType.name}" type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
fieldNodes,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/subscription/__tests__/subscribe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ describe('Subscription Initialization Phase', () => {
errors: [
{
message:
'Variable "$priority" got invalid value "meow"; Expected type Int. Int cannot represent non-integer value: "meow"',
'Variable "$priority" got invalid value "meow"; Expected type "Int". Int cannot represent non-integer value: "meow"',
locations: [{ line: 2, column: 21 }],
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/enumType-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe('Type System: Enum Values', () => {
errors: [
{
message:
'Variable "$color" got invalid value 2; Expected type Color.',
'Variable "$color" got invalid value 2; Expected type "Color".',
locations: [{ line: 1, column: 8 }],
},
],
Expand Down
39 changes: 20 additions & 19 deletions src/utilities/__tests__/coerceInputValue-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('coerceInputValue', () => {
const result = coerceValue(undefined, TestNonNull);
expectErrors(result).to.deep.equal([
{
error: 'Expected non-nullable type Int! not to be null.',
error: 'Expected non-nullable type "Int!" not to be null.',
path: [],
value: undefined,
},
Expand All @@ -60,7 +60,7 @@ describe('coerceInputValue', () => {
const result = coerceValue(null, TestNonNull);
expectErrors(result).to.deep.equal([
{
error: 'Expected non-nullable type Int! not to be null.',
error: 'Expected non-nullable type "Int!" not to be null.',
path: [],
value: null,
},
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('coerceInputValue', () => {
const result = coerceValue({ value: undefined }, TestScalar);
expectErrors(result).to.deep.equal([
{
error: 'Expected type TestScalar.',
error: 'Expected type "TestScalar".',
path: [],
value: { value: undefined },
},
Expand All @@ -111,7 +111,7 @@ describe('coerceInputValue', () => {
const result = coerceValue(inputValue, TestScalar);
expectErrors(result).to.deep.equal([
{
error: 'Expected type TestScalar. Some error message',
error: 'Expected type "TestScalar". Some error message',
path: [],
value: { error: 'Some error message' },
},
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('coerceInputValue', () => {
const result = coerceValue('foo', TestEnum);
expectErrors(result).to.deep.equal([
{
error: 'Expected type TestEnum. Did you mean FOO?',
error: 'Expected type "TestEnum". Did you mean the enum value "FOO"?',
path: [],
value: 'foo',
},
Expand All @@ -151,7 +151,7 @@ describe('coerceInputValue', () => {
const result1 = coerceValue(123, TestEnum);
expectErrors(result1).to.deep.equal([
{
error: 'Expected type TestEnum.',
error: 'Expected type "TestEnum".',
path: [],
value: 123,
},
Expand All @@ -160,7 +160,7 @@ describe('coerceInputValue', () => {
const result2 = coerceValue({ field: 'value' }, TestEnum);
expectErrors(result2).to.deep.equal([
{
error: 'Expected type TestEnum.',
error: 'Expected type "TestEnum".',
path: [],
value: { field: 'value' },
},
Expand All @@ -186,7 +186,7 @@ describe('coerceInputValue', () => {
const result = coerceValue(123, TestInputObject);
expectErrors(result).to.deep.equal([
{
error: 'Expected type TestInputObject to be an object.',
error: 'Expected type "TestInputObject" to be an object.',
path: [],
value: 123,
},
Expand All @@ -198,7 +198,7 @@ describe('coerceInputValue', () => {
expectErrors(result).to.deep.equal([
{
error:
'Expected type Int. Int cannot represent non-integer value: NaN',
'Expected type "Int". Int cannot represent non-integer value: NaN',
path: ['foo'],
value: NaN,
},
Expand All @@ -210,13 +210,13 @@ describe('coerceInputValue', () => {
expectErrors(result).to.deep.equal([
{
error:
'Expected type Int. Int cannot represent non-integer value: "abc"',
'Expected type "Int". Int cannot represent non-integer value: "abc"',
path: ['foo'],
value: 'abc',
},
{
error:
'Expected type Int. Int cannot represent non-integer value: "def"',
'Expected type "Int". Int cannot represent non-integer value: "def"',
path: ['bar'],
value: 'def',
},
Expand All @@ -227,7 +227,7 @@ describe('coerceInputValue', () => {
const result = coerceValue({ bar: 123 }, TestInputObject);
expectErrors(result).to.deep.equal([
{
error: 'Field foo of required type Int! was not provided.',
error: 'Field "foo" of required type "Int!" was not provided.',
path: [],
value: { bar: 123 },
},
Expand All @@ -241,7 +241,8 @@ describe('coerceInputValue', () => {
);
expectErrors(result).to.deep.equal([
{
error: 'Field "unknownField" is not defined by type TestInputObject.',
error:
'Field "unknownField" is not defined by type "TestInputObject".',
path: [],
value: { foo: 123, unknownField: 123 },
},
Expand All @@ -253,7 +254,7 @@ describe('coerceInputValue', () => {
expectErrors(result).to.deep.equal([
{
error:
'Field "bart" is not defined by type TestInputObject. Did you mean bar?',
'Field "bart" is not defined by type "TestInputObject". Did you mean "bar"?',
path: [],
value: { foo: 123, bart: 123 },
},
Expand Down Expand Up @@ -309,13 +310,13 @@ describe('coerceInputValue', () => {
expectErrors(result).to.deep.equal([
{
error:
'Expected type Int. Int cannot represent non-integer value: "b"',
'Expected type "Int". Int cannot represent non-integer value: "b"',
path: [1],
value: 'b',
},
{
error:
'Expected type Int. Int cannot represent non-integer value: true',
'Expected type "Int". Int cannot represent non-integer value: true',
path: [2],
value: true,
},
Expand All @@ -332,7 +333,7 @@ describe('coerceInputValue', () => {
expectErrors(result).to.deep.equal([
{
error:
'Expected type Int. Int cannot represent non-integer value: "INVALID"',
'Expected type "Int". Int cannot represent non-integer value: "INVALID"',
path: [],
value: 'INVALID',
},
Expand Down Expand Up @@ -377,15 +378,15 @@ describe('coerceInputValue', () => {
describe('with default onError', () => {
it('throw error without path', () => {
expect(() => coerceInputValue(null, GraphQLNonNull(GraphQLInt))).to.throw(
'Invalid value null: Expected non-nullable type Int! not to be null.',
'Invalid value null: Expected non-nullable type "Int!" not to be null.',
);
});

it('throw error with path', () => {
expect(() =>
coerceInputValue([null], GraphQLList(GraphQLNonNull(GraphQLInt))),
).to.throw(
'Invalid value null at "value[0]": : Expected non-nullable type Int! not to be null.',
'Invalid value null at "value[0]": : Expected non-nullable type "Int!" not to be null.',
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/__tests__/findDeprecatedUsages-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('findDeprecatedUsages', () => {
const errorMessages = errors.map(err => err.message);

expect(errorMessages).to.deep.equal([
'The field Query.deprecatedField is deprecated. Some field reason.',
'The field "Query.deprecatedField" is deprecated. Some field reason.',
]);
});

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

expect(errorMessages).to.deep.equal([
'The enum value EnumType.TWO is deprecated. Some enum reason.',
'The enum value "EnumType.TWO" is deprecated. Some enum reason.',
]);
});
});
19 changes: 11 additions & 8 deletions src/utilities/coerceInputValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function coerceInputValueImpl(
pathToArray(path),
inputValue,
new GraphQLError(
`Expected non-nullable type ${inspect(type)} not to be null.`,
`Expected non-nullable type "${inspect(type)}" not to be null.`,
),
);
return;
Expand Down Expand Up @@ -102,7 +102,7 @@ function coerceInputValueImpl(
onError(
pathToArray(path),
inputValue,
new GraphQLError(`Expected type ${type.name} to be an object.`),
new GraphQLError(`Expected type "${type.name}" to be an object.`),
);
return;
}
Expand All @@ -122,7 +122,7 @@ function coerceInputValueImpl(
pathToArray(path),
inputValue,
new GraphQLError(
`Field ${field.name} of required type ${typeStr} was not provided.`,
`Field "${field.name}" of required type "${typeStr}" was not provided.`,
),
);
}
Expand All @@ -148,8 +148,8 @@ function coerceInputValueImpl(
pathToArray(path),
inputValue,
new GraphQLError(
`Field "${fieldName}" is not defined by type ${type.name}.` +
didYouMean(suggestions),
`Field "${fieldName}" is not defined by type "${type.name}".` +
didYouMean(suggestions.map(x => `"${x}"`)),
),
);
}
Expand All @@ -170,7 +170,7 @@ function coerceInputValueImpl(
pathToArray(path),
inputValue,
new GraphQLError(
`Expected type ${type.name}. ` + error.message,
`Expected type "${type.name}". ` + error.message,
undefined,
undefined,
undefined,
Expand All @@ -184,7 +184,7 @@ function coerceInputValueImpl(
onError(
pathToArray(path),
inputValue,
new GraphQLError(`Expected type ${type.name}.`),
new GraphQLError(`Expected type "${type.name}".`),
);
}
return parseResult;
Expand All @@ -204,7 +204,10 @@ function coerceInputValueImpl(
onError(
pathToArray(path),
inputValue,
new GraphQLError(`Expected type ${type.name}.` + didYouMean(suggestions)),
new GraphQLError(
`Expected type "${type.name}".` +
didYouMean('the enum value', suggestions.map(x => `"${x}"`)),
),
);
return;
}
Expand Down
Loading