Skip to content

Commit 604bd20

Browse files
committed
add type name to ProvidedRequiredArguments rule errors
1 parent e184259 commit 604bd20

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/type/__tests__/introspection-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ describe('Introspection', () => {
16441644
errors: [
16451645
{
16461646
message:
1647-
'Argument "__type(name:)" of type "String!" is required, but it was not provided.',
1647+
'Argument "<meta>.__type(name:)" of type "String!" is required, but it was not provided.',
16481648
locations: [{ line: 3, column: 9 }],
16491649
},
16501650
],

src/validation/__tests__/ProvidedRequiredArgumentsRule-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ describe('Validate: Provided required arguments', () => {
168168
`).toDeepEqual([
169169
{
170170
message:
171-
'Argument "multipleReqs(req1:)" of type "Int!" is required, but it was not provided.',
171+
'Argument "ComplicatedArgs.multipleReqs(req1:)" of type "Int!" is required, but it was not provided.',
172172
locations: [{ line: 4, column: 13 }],
173173
},
174174
]);
@@ -184,12 +184,12 @@ describe('Validate: Provided required arguments', () => {
184184
`).toDeepEqual([
185185
{
186186
message:
187-
'Argument "multipleReqs(req1:)" of type "Int!" is required, but it was not provided.',
187+
'Argument "ComplicatedArgs.multipleReqs(req1:)" of type "Int!" is required, but it was not provided.',
188188
locations: [{ line: 4, column: 13 }],
189189
},
190190
{
191191
message:
192-
'Argument "multipleReqs(req2:)" of type "Int!" is required, but it was not provided.',
192+
'Argument "ComplicatedArgs.multipleReqs(req2:)" of type "Int!" is required, but it was not provided.',
193193
locations: [{ line: 4, column: 13 }],
194194
},
195195
]);
@@ -205,7 +205,7 @@ describe('Validate: Provided required arguments', () => {
205205
`).toDeepEqual([
206206
{
207207
message:
208-
'Argument "multipleReqs(req2:)" of type "Int!" is required, but it was not provided.',
208+
'Argument "ComplicatedArgs.multipleReqs(req2:)" of type "Int!" is required, but it was not provided.',
209209
locations: [{ line: 4, column: 13 }],
210210
},
211211
]);

src/validation/rules/ProvidedRequiredArgumentsRule.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ import { Kind } from '../../language/kinds.js';
77
import { print } from '../../language/printer.js';
88
import type { ASTVisitor } from '../../language/visitor.js';
99

10-
import type { GraphQLArgument } from '../../type/definition.js';
10+
import {
11+
isCompositeType,
12+
type GraphQLArgument,
13+
isOutputType,
14+
getNamedType,
15+
} from '../../type/definition.js';
1116
import { isRequiredArgument, isType } from '../../type/definition.js';
1217
import { specifiedDirectives } from '../../type/directives.js';
1318

1419
import type {
1520
SDLValidationContext,
1621
ValidationContext,
1722
} from '../ValidationContext.js';
23+
import { isIntrospectionType } from '../../type/introspection.js';
1824

1925
/**
2026
* Provided required arguments
@@ -43,10 +49,18 @@ export function ProvidedRequiredArgumentsRule(
4349
);
4450
for (const argDef of fieldDef.args) {
4551
if (!providedArgs.has(argDef.name) && isRequiredArgument(argDef)) {
52+
const fieldType = getNamedType(context.getType());
53+
const parentType = context.getParentType();
54+
const parentTypeStr =
55+
fieldType && isIntrospectionType(fieldType)
56+
? '<meta>.'
57+
: parentType && isCompositeType(parentType)
58+
? `${parentType.name}.`
59+
: '';
4660
const argTypeStr = inspect(argDef.type);
4761
context.reportError(
4862
new GraphQLError(
49-
`Argument "${fieldDef.name}(${argDef.name}:)" of type "${argTypeStr}" is required, but it was not provided.`,
63+
`Argument "${parentTypeStr}${fieldDef.name}(${argDef.name}:)" of type "${argTypeStr}" is required, but it was not provided.`,
5064
{ nodes: fieldNode },
5165
),
5266
);

0 commit comments

Comments
 (0)