@@ -8,7 +8,7 @@ public AuthorizationVisitorBase(ValidationContext context)
8
8
{
9
9
if ( context == null )
10
10
throw new ArgumentNullException ( nameof ( context ) ) ;
11
- _fragmentDefinitionsToCheck = GetRecursivelyReferencedUsedFragments ( context ) ;
11
+ _fragmentDefinitionsToCheck = context . GetRecursivelyReferencedFragments ( context . Operation , true ) ;
12
12
}
13
13
14
14
private bool _checkTree ; // used to skip processing fragments or operations that do not apply
@@ -36,7 +36,7 @@ public virtual async ValueTask EnterAsync(ASTNode node, ValidationContext contex
36
36
else if ( _checkTree )
37
37
{
38
38
// if a directive indicates to skip this node, skip authorization checks until Leave() is called for this node
39
- if ( SkipNode ( node , context ) )
39
+ if ( ! context . ShouldIncludeNode ( node ) )
40
40
{
41
41
_checkTree = false ;
42
42
_checkUntil = node ;
@@ -175,72 +175,6 @@ async ValueTask PopAndProcessAsync()
175
175
}
176
176
}
177
177
178
- /// <summary>
179
- /// Indicates if the specified node should skip authentication processing.
180
- /// Default implementation looks at @skip and @include directives only.
181
- /// </summary>
182
- protected virtual bool SkipNode ( ASTNode node , ValidationContext context )
183
- {
184
- // according to GraphQL spec, directives with the same name may be defined so long as they cannot be
185
- // placed on the same node types as other directives with the same name; so here we verify that the
186
- // node is a field, fragment spread, or inline fragment, the only nodes allowed by the built-in @skip
187
- // and @include directives
188
- if ( node is not GraphQLField && node is not GraphQLFragmentSpread && node is not GraphQLInlineFragment )
189
- return false ;
190
-
191
- var directivesNode = ( IHasDirectivesNode ) node ;
192
-
193
- var skipDirective = directivesNode . Directives ? . FirstOrDefault ( x => x . Name == "skip" ) ;
194
- if ( skipDirective != null )
195
- {
196
- var value = GetDirectiveValue ( skipDirective , context , false ) ;
197
- if ( value )
198
- return true ;
199
- }
200
-
201
- var includeDirective = directivesNode . Directives ? . FirstOrDefault ( x => x . Name == "include" ) ;
202
- if ( includeDirective != null )
203
- {
204
- var value = GetDirectiveValue ( includeDirective , context , true ) ;
205
- if ( ! value )
206
- return true ;
207
- }
208
-
209
- return false ;
210
-
211
- static bool GetDirectiveValue ( GraphQLDirective directive , ValidationContext context , bool defaultValue )
212
- {
213
- var ifArg = directive . Arguments ? . FirstOrDefault ( x => x . Name == "if" ) ;
214
- if ( ifArg != null )
215
- {
216
- if ( ifArg . Value is GraphQLBooleanValue boolValue )
217
- {
218
- return boolValue . BoolValue ;
219
- }
220
- else if ( ifArg . Value is GraphQLVariable variable )
221
- {
222
- if ( context . Operation . Variables != null )
223
- {
224
- var varDef = context . Operation . Variables . FirstOrDefault ( x => x . Variable . Name == variable . Name ) ;
225
- if ( varDef != null && varDef . Type . Name ( ) == "Boolean" )
226
- {
227
- if ( context . Variables . TryGetValue ( variable . Name . StringValue , out var value ) )
228
- {
229
- if ( value is bool boolValue2 )
230
- return boolValue2 ;
231
- }
232
- if ( varDef . DefaultValue is GraphQLBooleanValue boolValue3 )
233
- {
234
- return boolValue3 . BoolValue ;
235
- }
236
- }
237
- }
238
- }
239
- }
240
- return defaultValue ;
241
- }
242
- }
243
-
244
178
/// <summary>
245
179
/// Runs when a fragment is added or updated; the fragment might not be waiting on any
246
180
/// other fragments, or it still might be.
0 commit comments