3
3
4
4
5
5
class NoUnusedFragments (ValidationRule ):
6
- __slots__ = 'fragment_definitions' , 'spreads_within_operation ' , 'fragment_adjacencies' , 'spread_names'
6
+ __slots__ = 'fragment_definitions' , 'operation_definitions ' , 'fragment_adjacencies' , 'spread_names'
7
7
8
8
def __init__ (self , context ):
9
9
super (NoUnusedFragments , self ).__init__ (context )
10
- self .spreads_within_operation = []
10
+ self .operation_definitions = []
11
11
self .fragment_definitions = []
12
12
13
13
def enter_OperationDefinition (self , node , key , parent , path , ancestors ):
14
- self .spreads_within_operation .append (self . context . get_fragment_spreads ( node ) )
14
+ self .operation_definitions .append (node )
15
15
return False
16
16
17
17
def enter_FragmentDefinition (self , node , key , parent , path , ancestors ):
@@ -21,19 +21,10 @@ def enter_FragmentDefinition(self, node, key, parent, path, ancestors):
21
21
def leave_Document (self , node , key , parent , path , ancestors ):
22
22
fragment_names_used = set ()
23
23
24
- def reduce_spread_fragments (spreads ):
25
- for spread in spreads :
26
- frag_name = spread .name .value
27
- if frag_name in fragment_names_used :
28
- continue
29
-
30
- fragment_names_used .add (frag_name )
31
- fragment = self .context .get_fragment (frag_name )
32
- if fragment :
33
- reduce_spread_fragments (self .context .get_fragment_spreads (fragment ))
34
-
35
- for spreads in self .spreads_within_operation :
36
- reduce_spread_fragments (spreads )
24
+ for operation in self .operation_definitions :
25
+ fragments = self .context .get_recursively_referenced_fragments (operation )
26
+ for fragment in fragments :
27
+ fragment_names_used .add (fragment .name .value )
37
28
38
29
errors = [
39
30
GraphQLError (
0 commit comments