Skip to content

Commit 5feb200

Browse files
committed
combine number of fields and nullability into uniform error message
1 parent 70e5c4f commit 5feb200

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

src/execution/__tests__/oneof-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
157157
{
158158
locations: [{ column: 16, line: 2 }],
159159
message:
160-
'Variable "$input" got invalid value { a: "abc", b: 123 }; Exactly one key must be specified for OneOf type "TestInputObject".',
160+
'Variable "$input" got invalid value { a: "abc", b: 123 }; Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
161161
},
162162
],
163163
});
@@ -181,7 +181,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
181181
{
182182
locations: [{ column: 16, line: 2 }],
183183
message:
184-
'Variable "$input" got invalid value { a: "abc", b: null }; Exactly one key must be specified for OneOf type "TestInputObject".',
184+
'Variable "$input" got invalid value { a: "abc", b: null }; Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
185185
},
186186
],
187187
});
@@ -205,7 +205,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
205205
{
206206
locations: [{ column: 16, line: 2 }],
207207
message:
208-
'Variable "$input" got invalid value { a: null, b: null }; Exactly one key must be specified for OneOf type "TestInputObject".',
208+
'Variable "$input" got invalid value { a: null, b: null }; Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
209209
},
210210
],
211211
});

src/utilities/__tests__/coerceInputValue-test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ describe('coerceInputValue', () => {
307307
expectErrors(result).to.deep.equal([
308308
{
309309
error:
310-
'Exactly one key must be specified for OneOf type "TestInputObject".',
310+
'Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
311311
path: [],
312312
value: { foo: 123, bar: 456 },
313313
},
@@ -319,7 +319,7 @@ describe('coerceInputValue', () => {
319319
expectErrors(result).to.deep.equal([
320320
{
321321
error:
322-
'Field "bar" of OneOf type "TestInputObject" must be non-null.',
322+
'Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
323323
path: ['bar'],
324324
value: null,
325325
},
@@ -331,7 +331,7 @@ describe('coerceInputValue', () => {
331331
expectErrors(result).to.deep.equal([
332332
{
333333
error:
334-
'Exactly one key must be specified for OneOf type "TestInputObject".',
334+
'Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
335335
path: [],
336336
value: { foo: null, bar: null },
337337
},
@@ -364,7 +364,7 @@ describe('coerceInputValue', () => {
364364
},
365365
{
366366
error:
367-
'Exactly one key must be specified for OneOf type "TestInputObject".',
367+
'Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
368368
path: [],
369369
value: { foo: 'abc', bar: 'def' },
370370
},
@@ -385,7 +385,7 @@ describe('coerceInputValue', () => {
385385
},
386386
{
387387
error:
388-
'Exactly one key must be specified for OneOf type "TestInputObject".',
388+
'Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
389389
path: [],
390390
value: { foo: 123, unknownField: 123 },
391391
},
@@ -403,7 +403,7 @@ describe('coerceInputValue', () => {
403403
},
404404
{
405405
error:
406-
'Exactly one key must be specified for OneOf type "TestInputObject".',
406+
'Within OneOf Input Object Type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
407407
path: [],
408408
value: { bart: 123 },
409409
},

src/utilities/coerceInputValue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function coerceInputValueImpl(
183183
pathToArray(path),
184184
inputValue,
185185
new GraphQLError(
186-
`Exactly one key must be specified for OneOf type "${type}".`,
186+
`Within OneOf Input Object Type "${type}", exactly one field must be specified, and the value for that field must be non-null.`,
187187
),
188188
);
189189
} else {
@@ -194,7 +194,7 @@ function coerceInputValueImpl(
194194
pathToArray(path).concat(key),
195195
value,
196196
new GraphQLError(
197-
`Field "${key}" of OneOf type "${type}" must be non-null.`,
197+
`Within OneOf Input Object Type "${type}", exactly one field must be specified, and the value for that field must be non-null.`,
198198
),
199199
);
200200
}

src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,8 @@ describe('Validate: Values of correct type', () => {
10881088
}
10891089
`).toDeepEqual([
10901090
{
1091-
message: 'Field "OneOfInput.stringField" must be non-null.',
1091+
message:
1092+
'Within OneOf Input Object Type "OneOfInput", exactly one field must be specified, and the value for that field must be non-null.',
10921093
locations: [{ line: 4, column: 37 }],
10931094
},
10941095
]);
@@ -1104,7 +1105,7 @@ describe('Validate: Values of correct type', () => {
11041105
`).toDeepEqual([
11051106
{
11061107
message:
1107-
'Variable "$string" must be non-nullable to be used for OneOf Input Object "OneOfInput".',
1108+
'Variable "$string" must be non-nullable to be used for Within OneOf Input Object Type "OneOfInput".',
11081109
locations: [{ line: 4, column: 37 }],
11091110
},
11101111
]);
@@ -1120,7 +1121,7 @@ describe('Validate: Values of correct type', () => {
11201121
`).toDeepEqual([
11211122
{
11221123
message:
1123-
'OneOf Input Object "OneOfInput" must specify exactly one key.',
1124+
'Within OneOf Input Object Type "OneOfInput", exactly one field must be specified, and the value for that field must be non-null.',
11241125
locations: [{ line: 4, column: 37 }],
11251126
},
11261127
]);

src/validation/rules/ValuesOfCorrectTypeRule.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function validateOneOfInputObject(
193193
if (isNotExactlyOneField) {
194194
context.reportError(
195195
new GraphQLError(
196-
`OneOf Input Object "${type}" must specify exactly one key.`,
196+
`Within OneOf Input Object Type "${type}", exactly one field must be specified, and the value for that field must be non-null.`,
197197
{ nodes: [node] },
198198
),
199199
);
@@ -206,9 +206,12 @@ function validateOneOfInputObject(
206206

207207
if (isNullLiteral) {
208208
context.reportError(
209-
new GraphQLError(`Field "${type}.${keys[0]}" must be non-null.`, {
210-
nodes: [node],
211-
}),
209+
new GraphQLError(
210+
`Within OneOf Input Object Type "${type}", exactly one field must be specified, and the value for that field must be non-null.`,
211+
{
212+
nodes: [node],
213+
},
214+
),
212215
);
213216
return;
214217
}
@@ -221,7 +224,7 @@ function validateOneOfInputObject(
221224
if (isNullableVariable) {
222225
context.reportError(
223226
new GraphQLError(
224-
`Variable "$${variableName}" must be non-nullable to be used for OneOf Input Object "${type}".`,
227+
`Variable "$${variableName}" must be non-nullable to be used for Within OneOf Input Object Type "${type}".`,
225228
{ nodes: [node] },
226229
),
227230
);

0 commit comments

Comments
 (0)