@@ -43,6 +43,7 @@ type context struct {
4343 overlapPairLimit int
4444 overlapPairsObserved int
4545 overlapLimitHit bool
46+ validateDeprecated bool
4647}
4748
4849func (c * context ) addErr (loc errors.Location , rule string , format string , a ... any ) {
@@ -62,21 +63,22 @@ type opContext struct {
6263 ops []* ast.OperationDefinition
6364}
6465
65- func newContext (s * ast.Schema , doc * ast.ExecutableDefinition , maxDepth int , overlapPairLimit int ) * context {
66+ func newContext (s * ast.Schema , doc * ast.ExecutableDefinition , maxDepth int , overlapPairLimit int , validateDeprecated bool ) * context {
6667 return & context {
67- schema : s ,
68- doc : doc ,
69- opErrs : make (map [* ast.OperationDefinition ][]* errors.QueryError ),
70- usedVars : make (map [* ast.OperationDefinition ]varSet ),
71- fieldMap : make (map [* ast.Field ]fieldInfo ),
72- overlapValidated : make (map [selectionPair ]bool ),
73- maxDepth : maxDepth ,
74- overlapPairLimit : overlapPairLimit ,
68+ schema : s ,
69+ doc : doc ,
70+ opErrs : make (map [* ast.OperationDefinition ][]* errors.QueryError ),
71+ usedVars : make (map [* ast.OperationDefinition ]varSet ),
72+ fieldMap : make (map [* ast.Field ]fieldInfo ),
73+ overlapValidated : make (map [selectionPair ]bool ),
74+ maxDepth : maxDepth ,
75+ overlapPairLimit : overlapPairLimit ,
76+ validateDeprecated : validateDeprecated ,
7577 }
7678}
7779
78- func Validate (s * ast.Schema , doc * ast.ExecutableDefinition , variables map [string ]any , maxDepth int , overlapPairLimit int ) []* errors.QueryError {
79- c := newContext (s , doc , maxDepth , overlapPairLimit )
80+ func Validate (s * ast.Schema , doc * ast.ExecutableDefinition , variables map [string ]any , maxDepth int , overlapPairLimit int , validateDeprecated bool ) []* errors.QueryError {
81+ c := newContext (s , doc , maxDepth , overlapPairLimit , validateDeprecated )
8082
8183 opNames := make (nameSet , len (doc .Operations ))
8284 fragUsedBy := make (map [* ast.FragmentDefinition ][]* ast.OperationDefinition )
@@ -628,8 +630,10 @@ func validateSelection(c *opContext, sel ast.Selection, t ast.NamedType) {
628630
629631 validateArgumentLiterals (c , sel .Arguments )
630632 if f != nil {
631- if reason , ok := deprecatedReason (f .Directives ); ok && t != nil {
632- c .addErr (sel .Name .Loc , "NoDeprecatedCustomRule" , "The field %s.%s is deprecated. %s" , t .TypeName (), fieldName , reason )
633+ if c .validateDeprecated {
634+ if reason , ok := deprecatedReason (f .Directives ); ok && t != nil {
635+ c .addErr (sel .Name .Loc , "NoDeprecatedCustomRule" , "The field %s.%s is deprecated. %s" , t .TypeName (), fieldName , reason )
636+ }
633637 }
634638
635639 validateArgumentTypes (c , sel .Arguments , f .Arguments , sel .Alias .Loc ,
@@ -643,8 +647,10 @@ func validateSelection(c *opContext, sel ast.Selection, t ast.NamedType) {
643647 if argDecl == nil {
644648 continue
645649 }
646- if reason , ok := deprecatedReason (argDecl .Directives ); ok {
647- c .addErr (selArg .Name .Loc , "NoDeprecatedCustomRule" , "Field %q argument %q is deprecated. %s" , t .TypeName ()+ "." + fieldName , selArg .Name .Name , reason )
650+ if c .validateDeprecated {
651+ if reason , ok := deprecatedReason (argDecl .Directives ); ok {
652+ c .addErr (selArg .Name .Loc , "NoDeprecatedCustomRule" , "Field %q argument %q is deprecated. %s" , t .TypeName ()+ "." + fieldName , selArg .Name .Name , reason )
653+ }
648654 }
649655 }
650656
@@ -658,8 +664,10 @@ func validateSelection(c *opContext, sel ast.Selection, t ast.NamedType) {
658664 if argDecl == nil {
659665 continue
660666 }
661- if reason , ok := deprecatedReason (argDecl .Directives ); ok {
662- c .addErr (selArg .Name .Loc , "NoDeprecatedCustomRule" , "Directive %q argument %q is deprecated. %s" , "@" + directive .Name .Name , selArg .Name .Name , reason )
667+ if c .validateDeprecated {
668+ if reason , ok := deprecatedReason (argDecl .Directives ); ok {
669+ c .addErr (selArg .Name .Loc , "NoDeprecatedCustomRule" , "Directive %q argument %q is deprecated. %s" , "@" + directive .Name .Name , selArg .Name .Name , reason )
670+ }
663671 }
664672 }
665673 }
@@ -1078,8 +1086,10 @@ func validateDirectives(c *opContext, loc string, directives ast.DirectiveList)
10781086 if argDecl == nil {
10791087 continue
10801088 }
1081- if reason , ok := deprecatedReason (argDecl .Directives ); ok {
1082- c .addErr (selArg .Name .Loc , "NoDeprecatedCustomRule" , "Directive %q argument %q is deprecated. %s" , "@" + dirName , selArg .Name .Name , reason )
1089+ if c .validateDeprecated {
1090+ if reason , ok := deprecatedReason (argDecl .Directives ); ok {
1091+ c .addErr (selArg .Name .Loc , "NoDeprecatedCustomRule" , "Directive %q argument %q is deprecated. %s" , "@" + dirName , selArg .Name .Name , reason )
1092+ }
10831093 }
10841094 }
10851095 }
@@ -1267,8 +1277,10 @@ func validateValueType(c *opContext, v ast.Value, t ast.Type) (bool, errors.Loca
12671277 if option .EnumValue != lit .Text {
12681278 continue
12691279 }
1270- if depReason , deprecated := deprecatedReason (option .Directives ); deprecated {
1271- c .addErr (lit .Location (), "NoDeprecatedCustomRule" , "The enum value %q is deprecated. %s" , enumType .Name + "." + option .EnumValue , depReason )
1280+ if c .validateDeprecated {
1281+ if depReason , deprecated := deprecatedReason (option .Directives ); deprecated {
1282+ c .addErr (lit .Location (), "NoDeprecatedCustomRule" , "The enum value %q is deprecated. %s" , enumType .Name + "." + option .EnumValue , depReason )
1283+ }
12721284 }
12731285 break
12741286 }
@@ -1302,7 +1314,7 @@ func validateValueType(c *opContext, v ast.Value, t ast.Type) (bool, errors.Loca
13021314 suggestion := makeSuggestion ("Did you mean" , t .Values .Names (), name )
13031315 return false , f .Name .Loc , fmt .Sprintf ("Field %q is not defined by type %q.%s" , name , t .Name , suggestion )
13041316 }
1305- if depReason , deprecated := deprecatedReason (iv .Directives ); deprecated {
1317+ if depReason , deprecated := deprecatedReason (iv .Directives ); deprecated && c . validateDeprecated {
13061318 c .addErr (f .Name .Loc , "NoDeprecatedCustomRule" , "The input field %s.%s is deprecated. %s" , t .Name , iv .Name .Name , depReason )
13071319 }
13081320 if ok , errLoc , reason := validateValueType (c , f .Value , iv .Type ); ! ok {
0 commit comments