9
9
10
10
import type { ValidationContext } from '../index' ;
11
11
import { GraphQLError } from '../../error' ;
12
- import find from '../../jsutils/find' ;
13
- import invariant from '../../jsutils/invariant' ;
14
12
import suggestionList from '../../jsutils/suggestionList' ;
15
13
import quotedOrList from '../../jsutils/quotedOrList' ;
16
- import * as Kind from '../../language/kinds' ;
14
+ import { FIELD , DIRECTIVE } from '../../language/kinds' ;
17
15
18
16
export function unknownArgMessage (
19
17
argName : string ,
@@ -53,17 +51,13 @@ export function unknownDirectiveArgMessage(
53
51
export function KnownArgumentNames ( context : ValidationContext ) : any {
54
52
return {
55
53
Argument ( node , key , parent , path , ancestors ) {
56
- const argumentOf = ancestors [ ancestors . length - 1 ] ;
57
- if ( argumentOf . kind === Kind . FIELD ) {
58
- const fieldDef = context . getFieldDef ( ) ;
59
- if ( fieldDef ) {
60
- const fieldArgDef = find (
61
- fieldDef . args ,
62
- arg => arg . name === node . name . value ,
63
- ) ;
64
- if ( ! fieldArgDef ) {
65
- const parentType = context . getParentType ( ) ;
66
- invariant ( parentType ) ;
54
+ const argDef = context . getArgument ( ) ;
55
+ if ( ! argDef ) {
56
+ const argumentOf = ancestors [ ancestors . length - 1 ] ;
57
+ if ( argumentOf . kind === FIELD ) {
58
+ const fieldDef = context . getFieldDef ( ) ;
59
+ const parentType = context . getParentType ( ) ;
60
+ if ( fieldDef && parentType ) {
67
61
context . reportError (
68
62
new GraphQLError (
69
63
unknownArgMessage (
@@ -79,15 +73,9 @@ export function KnownArgumentNames(context: ValidationContext): any {
79
73
) ,
80
74
) ;
81
75
}
82
- }
83
- } else if ( argumentOf . kind === Kind . DIRECTIVE ) {
84
- const directive = context . getDirective ( ) ;
85
- if ( directive ) {
86
- const directiveArgDef = find (
87
- directive . args ,
88
- arg => arg . name === node . name . value ,
89
- ) ;
90
- if ( ! directiveArgDef ) {
76
+ } else if ( argumentOf . kind === DIRECTIVE ) {
77
+ const directive = context . getDirective ( ) ;
78
+ if ( directive ) {
91
79
context . reportError (
92
80
new GraphQLError (
93
81
unknownDirectiveArgMessage (
0 commit comments