Skip to content

Commit

Permalink
standardize error messages prior to introducing schema coordinates
Browse files Browse the repository at this point in the history
extracted from graphql#3808
  • Loading branch information
yaacovCR committed Aug 23, 2024
1 parent 5c7d4d1 commit ccc3dcc
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 131 deletions.
13 changes: 7 additions & 6 deletions src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Argument "input" has invalid value ["foo", "bar", "baz"].',
'Argument "input" of type "TestInputObject" has invalid value ["foo", "bar", "baz"].',
path: ['fieldWithObjectInput'],
locations: [{ line: 3, column: 41 }],
},
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('Execute: Handles inputs', () => {
errors: [
{
message:
'Argument "input" has invalid value { c: "foo", e: "bar" }.',
'Argument "input" of type "TestInputObject" has invalid value { c: "foo", e: "bar" }.',
path: ['fieldWithObjectInput'],
locations: [{ line: 3, column: 41 }],
},
Expand Down Expand Up @@ -462,7 +462,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 "TestInputObject.c" of required type "String!" was not provided.',
locations: [{ line: 2, column: 16 }],
},
],
Expand All @@ -481,12 +481,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 "TestInputObject.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 "TestNestedInputObject.nb" of required type "String!" was not provided.',
locations: [{ line: 2, column: 18 }],
},
],
Expand Down Expand Up @@ -1042,7 +1042,8 @@ describe('Execute: Handles inputs', () => {
},
errors: [
{
message: 'Argument "input" has invalid value WRONG_TYPE.',
message:
'Argument "input" of type "String" has invalid value WRONG_TYPE.',
locations: [{ line: 3, column: 48 }],
path: ['fieldWithDefaultArgumentValue'],
},
Expand Down
4 changes: 3 additions & 1 deletion src/execution/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ export function getArgumentValues(
// execution. This is a runtime check to ensure execution does not
// continue with an invalid argument value.
throw new GraphQLError(
`Argument "${name}" has invalid value ${print(valueNode)}.`,
`Argument "${name}" of type "${inspect(
argType,
)}" has invalid value ${print(valueNode)}.`,
{ nodes: valueNode },
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/introspection-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ describe('Introspection', () => {
errors: [
{
message:
'Field "__type" argument "name" of type "String!" is required, but it was not provided.',
'Argument "__type(name:)" of type "String!" is required, but it was not provided.',
locations: [{ line: 3, column: 9 }],
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/type/__tests__/validation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ describe('Objects must adhere to Interface they implement', () => {
expectJSON(validateSchema(schema)).toDeepEqual([
{
message:
'Object field AnotherObject.field includes required argument requiredArg that is missing from the Interface field AnotherInterface.field.',
'Argument "AnotherObject.field(requiredArg:)" must not be required type "String!" if not provided by the Interface field "AnotherInterface.field".',
locations: [
{ line: 13, column: 11 },
{ line: 7, column: 9 },
Expand Down Expand Up @@ -2546,7 +2546,7 @@ describe('Interfaces must adhere to Interface they implement', () => {
expectJSON(validateSchema(schema)).toDeepEqual([
{
message:
'Object field ChildInterface.field includes required argument requiredArg that is missing from the Interface field ParentInterface.field.',
'Argument "ChildInterface.field(requiredArg:)" must not be required type "String!" if not provided by the Interface field "ParentInterface.field".',
locations: [
{ line: 13, column: 11 },
{ line: 7, column: 9 },
Expand Down
8 changes: 7 additions & 1 deletion src/type/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,13 @@ function validateTypeImplementsInterface(
const ifaceArg = ifaceField.args.find((arg) => arg.name === argName);
if (!ifaceArg && isRequiredArgument(typeArg)) {
context.reportError(
`Object field ${type.name}.${fieldName} includes required argument ${argName} that is missing from the Interface field ${iface.name}.${fieldName}.`,
`Argument "${
type.name
}.${fieldName}(${argName}:)" must not be required type "${inspect(
typeArg.type,
)}" if not provided by the Interface field "${
iface.name
}.${fieldName}".`,
[typeArg.astNode, ifaceField.astNode],
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__tests__/coerceInputValue-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,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 "TestInputObject.foo" of required type "Int!" was not provided.',
path: [],
value: { bar: 123 },
},
Expand Down
Loading

0 comments on commit ccc3dcc

Please sign in to comment.