Skip to content
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
8 changes: 4 additions & 4 deletions src/execution/__tests__/oneof-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
{
locations: [{ column: 16, line: 2 }],
message:
'Variable "$input" has invalid default value: OneOf Input Object "TestInputObject" must specify exactly one key.',
'Variable "$input" has invalid default value: Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
},
],
});
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
errors: [
{
message:
'Variable "$input" has invalid value: Field "a" for OneOf type "TestInputObject" must be non-null.',
'Variable "$input" has invalid value at .a: Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
locations: [{ line: 2, column: 16 }],
},
],
Expand All @@ -173,7 +173,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
{
locations: [{ column: 16, line: 2 }],
message:
'Variable "$input" has invalid value: Exactly one key must be specified for OneOf type "TestInputObject".',
'Variable "$input" has invalid value: Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
},
],
});
Expand All @@ -197,7 +197,7 @@ describe('Execute: Handles OneOf Input Objects', () => {
{
locations: [{ column: 16, line: 2 }],
message:
'Variable "$input" has invalid value: Exactly one key must be specified for OneOf type "TestInputObject".',
'Variable "$input" has invalid value: Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
},
],
});
Expand Down
22 changes: 11 additions & 11 deletions src/utilities/__tests__/validateInputValue-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ describe('validateInputValue', () => {
test({ foo: 123, bar: null }, TestInputObject, [
{
error:
'Exactly one key must be specified for OneOf type "TestInputObject".',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: [],
},
]);
Expand All @@ -409,8 +409,8 @@ describe('validateInputValue', () => {
test({ bar: null }, TestInputObject, [
{
error:
'Field "bar" for OneOf type "TestInputObject" must be non-null.',
path: [],
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: ['bar'],
},
]);
});
Expand All @@ -436,7 +436,7 @@ describe('validateInputValue', () => {
},
{
error:
'Exactly one key must be specified for OneOf type "TestInputObject".',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: [],
},
]);
Expand All @@ -452,7 +452,7 @@ describe('validateInputValue', () => {
},
{
error:
'Exactly one key must be specified for OneOf type "TestInputObject".',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: [],
},
]);
Expand Down Expand Up @@ -980,7 +980,7 @@ describe('validateInputLiteral', () => {
test('{ foo: 123, bar: null }', TestInputObject, [
{
error:
'OneOf Input Object "TestInputObject" must specify exactly one key.',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: [],
},
]);
Expand All @@ -990,7 +990,7 @@ describe('validateInputLiteral', () => {
test('{ bar: null }', TestInputObject, [
{
error:
'Field "TestInputObject.bar" used for OneOf Input Object must be non-null.',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: ['bar'],
},
]);
Expand Down Expand Up @@ -1025,7 +1025,7 @@ describe('validateInputLiteral', () => {
},
{
error:
'OneOf Input Object "TestInputObject" must specify exactly one key.',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: [],
},
]);
Expand All @@ -1041,7 +1041,7 @@ describe('validateInputLiteral', () => {
},
{
error:
'OneOf Input Object "TestInputObject" must specify exactly one key.',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: [],
},
]);
Expand Down Expand Up @@ -1087,7 +1087,7 @@ describe('validateInputLiteral', () => {
},
{
error:
'OneOf Input Object "TestInputObject" must specify exactly one key.',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: [],
},
]);
Expand All @@ -1105,7 +1105,7 @@ describe('validateInputLiteral', () => {
},
{
error:
'OneOf Input Object "TestInputObject" must specify exactly one key.',
'Within OneOf Input Object type "TestInputObject", exactly one field must be specified, and the value for that field must be non-null.',
path: [],
},
],
Expand Down
14 changes: 9 additions & 5 deletions src/utilities/validateInputValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function validateInputValueImpl(
if (fields.length !== 1) {
reportInvalidValue(
onError,
`Exactly one key must be specified for OneOf type "${type}".`,
getOneOfInputObjectErrorMessage(type),
path,
);
}
Expand All @@ -179,8 +179,8 @@ function validateInputValueImpl(
if (value === null) {
reportInvalidValue(
onError,
`Field "${field}" for OneOf type "${type}" must be non-null.`,
path,
getOneOfInputObjectErrorMessage(type),
addPath(path, field, type.name),
);
}
}
Expand Down Expand Up @@ -437,7 +437,7 @@ function validateInputLiteralImpl(
if (isNotExactlyOneField) {
reportInvalidLiteral(
context.onError,
`OneOf Input Object "${type}" must specify exactly one key.`,
getOneOfInputObjectErrorMessage(type),
valueNode,
path,
);
Expand All @@ -449,7 +449,7 @@ function validateInputLiteralImpl(
const fieldName = fields[0].name.value;
reportInvalidLiteral(
context.onError,
`Field "${type}.${fieldName}" used for OneOf Input Object must be non-null.`,
getOneOfInputObjectErrorMessage(type),
valueNode,
addPath(path, fieldName, undefined),
);
Expand Down Expand Up @@ -532,3 +532,7 @@ function getCaughtErrorMessage(caughtError: unknown): string {

return String(caughtError);
}

function getOneOfInputObjectErrorMessage(type: GraphQLInputType): string {
return `Within OneOf Input Object type "${type}", exactly one field must be specified, and the value for that field must be non-null.`;
}
4 changes: 2 additions & 2 deletions src/validation/__tests__/ValuesOfCorrectTypeRule-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ describe('Validate: Values of correct type', () => {
`).toDeepEqual([
{
message:
'Field "OneOfInput.stringField" used for OneOf Input Object must be non-null.',
'Within OneOf Input Object type "OneOfInput", exactly one field must be specified, and the value for that field must be non-null.',
locations: [{ line: 4, column: 37 }],
},
]);
Expand All @@ -1163,7 +1163,7 @@ describe('Validate: Values of correct type', () => {
`).toDeepEqual([
{
message:
'OneOf Input Object "OneOfInput" must specify exactly one key.',
'Within OneOf Input Object type "OneOfInput", exactly one field must be specified, and the value for that field must be non-null.',
locations: [{ line: 4, column: 37 }],
},
]);
Expand Down
Loading