@@ -62,37 +62,39 @@ public Task<INodeVisitor> ValidateAsync(ValidationContext context)
62
62
} ) ) ;
63
63
}
64
64
65
- private bool SkipAuthCheck ( Field fieldAst , ValidationContext context )
65
+ private bool SkipAuthCheck ( Field field , ValidationContext context )
66
66
{
67
- if ( fieldAst . Directives == null || ! fieldAst . Directives . Any ( ) ) return false ;
67
+ if ( field . Directives == null || ! field . Directives . Any ( ) ) return false ;
68
68
69
- var includeField = GetDirectiveValue ( context , fieldAst . Directives , DirectiveGraphType . Include ) ;
69
+ var operationName = context . OperationName ;
70
+ var documentOperations = context . Document . Operations ;
71
+ var operation = ! string . IsNullOrWhiteSpace ( operationName )
72
+ ? documentOperations . WithName ( operationName )
73
+ : documentOperations . FirstOrDefault ( ) ;
74
+ var variables = ExecutionHelper . GetVariableValues ( context . Document , context . Schema ,
75
+ operation ? . Variables , context . Inputs ) ;
76
+
77
+ var includeField = GetDirectiveValue ( context , field . Directives , DirectiveGraphType . Include , variables ) ;
70
78
if ( includeField . HasValue ) return ! includeField . Value ;
71
79
72
- var skipField = GetDirectiveValue ( context , fieldAst . Directives , DirectiveGraphType . Skip ) ;
80
+ var skipField = GetDirectiveValue ( context , field . Directives , DirectiveGraphType . Skip , variables ) ;
73
81
if ( skipField . HasValue ) return skipField . Value ;
74
82
75
83
return false ;
76
84
}
77
85
78
- private static bool ? GetDirectiveValue ( ValidationContext context , Directives directives , DirectiveGraphType directiveType )
86
+ private static bool ? GetDirectiveValue ( ValidationContext context , Directives directives , DirectiveGraphType directiveType , Variables variables )
79
87
{
80
88
var directive = directives . Find ( directiveType . Name ) ;
81
89
if ( directive == null ) return null ;
82
90
83
- var operationName = context . OperationName ;
84
- var documentOperations = context . Document . Operations ;
85
- var operation = ! string . IsNullOrWhiteSpace ( operationName )
86
- ? documentOperations . WithName ( operationName )
87
- : documentOperations . FirstOrDefault ( ) ;
88
-
89
- var values = ExecutionHelper . GetArgumentValues (
91
+ var argumentValues = ExecutionHelper . GetArgumentValues (
90
92
context . Schema ,
91
93
directiveType . Arguments ,
92
94
directive . Arguments ,
93
- ExecutionHelper . GetVariableValues ( context . Document , context . Schema , operation ? . Variables , context . Inputs ) ) ;
95
+ variables ) ;
94
96
95
- values . TryGetValue ( "if" , out object ifObj ) ;
97
+ argumentValues . TryGetValue ( "if" , out object ifObj ) ;
96
98
return bool . TryParse ( ifObj ? . ToString ( ) ?? string . Empty , out bool ifVal ) && ifVal ;
97
99
}
98
100
0 commit comments