diff --git a/src/execution/__tests__/abstract-test.js b/src/execution/__tests__/abstract-test.js index 047677847b..be4159e79a 100644 --- a/src/execution/__tests__/abstract-test.js +++ b/src/execution/__tests__/abstract-test.js @@ -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'], }, diff --git a/src/execution/__tests__/lists-test.js b/src/execution/__tests__/lists-test.js index a3a4089be1..8165ee63f6 100644 --- a/src/execution/__tests__/lists-test.js +++ b/src/execution/__tests__/lists-test.js @@ -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'], }, diff --git a/src/execution/__tests__/variables-test.js b/src/execution/__tests__/variables-test.js index de1c95d092..b3fbc2ad8e 100644 --- a/src/execution/__tests__/variables-test.js +++ b/src/execution/__tests__/variables-test.js @@ -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 }], }, ], @@ -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 }], }, ], @@ -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 }], }, ], @@ -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 }], }, ], @@ -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 }], }, ], @@ -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 }], }, ], @@ -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 }], }, ], @@ -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 }], }, ], @@ -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 }], }; } diff --git a/src/execution/execute.js b/src/execution/execute.js index e772d93843..9ea2faa6c5 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -887,7 +887,7 @@ function completeListValue( ): PromiseOrValue<$ReadOnlyArray> { 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}".`, ); } @@ -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, ); } diff --git a/src/subscription/__tests__/subscribe-test.js b/src/subscription/__tests__/subscribe-test.js index 606c7eae35..a168e12b30 100644 --- a/src/subscription/__tests__/subscribe-test.js +++ b/src/subscription/__tests__/subscribe-test.js @@ -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 }], }, ], diff --git a/src/type/__tests__/enumType-test.js b/src/type/__tests__/enumType-test.js index 0d2dae138f..80b1f2a17f 100644 --- a/src/type/__tests__/enumType-test.js +++ b/src/type/__tests__/enumType-test.js @@ -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 }], }, ], diff --git a/src/utilities/__tests__/coerceInputValue-test.js b/src/utilities/__tests__/coerceInputValue-test.js index 646e13bc2f..7a42843025 100644 --- a/src/utilities/__tests__/coerceInputValue-test.js +++ b/src/utilities/__tests__/coerceInputValue-test.js @@ -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, }, @@ -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, }, @@ -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 }, }, @@ -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' }, }, @@ -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', }, @@ -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, }, @@ -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' }, }, @@ -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, }, @@ -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, }, @@ -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', }, @@ -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 }, }, @@ -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 }, }, @@ -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 }, }, @@ -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, }, @@ -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', }, @@ -377,7 +378,7 @@ 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.', ); }); @@ -385,7 +386,7 @@ describe('coerceInputValue', () => { 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.', ); }); }); diff --git a/src/utilities/__tests__/findDeprecatedUsages-test.js b/src/utilities/__tests__/findDeprecatedUsages-test.js index 73a5b4f5ea..044da5b68c 100644 --- a/src/utilities/__tests__/findDeprecatedUsages-test.js +++ b/src/utilities/__tests__/findDeprecatedUsages-test.js @@ -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.', ]); }); @@ -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.', ]); }); }); diff --git a/src/utilities/coerceInputValue.js b/src/utilities/coerceInputValue.js index cd2fe88701..08fe4e48a5 100644 --- a/src/utilities/coerceInputValue.js +++ b/src/utilities/coerceInputValue.js @@ -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; @@ -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; } @@ -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.`, ), ); } @@ -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}"`)), ), ); } @@ -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, @@ -184,7 +184,7 @@ function coerceInputValueImpl( onError( pathToArray(path), inputValue, - new GraphQLError(`Expected type ${type.name}.`), + new GraphQLError(`Expected type "${type.name}".`), ); } return parseResult; @@ -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; } diff --git a/src/utilities/findDeprecatedUsages.js b/src/utilities/findDeprecatedUsages.js index bc3dbaadc8..694937ff58 100644 --- a/src/utilities/findDeprecatedUsages.js +++ b/src/utilities/findDeprecatedUsages.js @@ -33,7 +33,7 @@ export function findDeprecatedUsages( const reason = fieldDef.deprecationReason; errors.push( new GraphQLError( - `The field ${parentType.name}.${fieldDef.name} is deprecated.` + + `The field "${parentType.name}.${fieldDef.name}" is deprecated.` + (reason ? ' ' + reason : ''), node, ), @@ -49,7 +49,7 @@ export function findDeprecatedUsages( const reason = enumVal.deprecationReason; errors.push( new GraphQLError( - `The enum value ${type.name}.${enumVal.name} is deprecated.` + + `The enum value "${type.name}.${enumVal.name}" is deprecated.` + (reason ? ' ' + reason : ''), node, ),