@@ -82,24 +82,31 @@ def __init__(self, data=None, errors=None, invalid=False):
82
82
error .value if isinstance (error , DeferredException ) else error
83
83
for error in errors
84
84
]
85
+
85
86
self .errors = errors
87
+
86
88
if invalid :
87
89
assert data is None
90
+
88
91
self .invalid = invalid
89
92
90
93
91
94
def get_operation_root_type (schema , operation ):
92
95
op = operation .operation
93
96
if op == 'query' :
94
97
return schema .get_query_type ()
98
+
95
99
elif op == 'mutation' :
96
100
mutation_type = schema .get_mutation_type ()
101
+
97
102
if not mutation_type :
98
103
raise GraphQLError (
99
104
'Schema is not configured for mutations' ,
100
105
[operation ]
101
106
)
107
+
102
108
return mutation_type
109
+
103
110
raise GraphQLError (
104
111
'Can only execute queries and mutations' ,
105
112
[operation ]
@@ -109,35 +116,36 @@ def get_operation_root_type(schema, operation):
109
116
def collect_fields (ctx , type , selection_set , fields , prev_fragment_names ):
110
117
for selection in selection_set .selections :
111
118
directives = selection .directives
119
+
112
120
if isinstance (selection , ast .Field ):
113
121
if not should_include_node (ctx , directives ):
114
122
continue
123
+
115
124
name = get_field_entry_key (selection )
116
- if name not in fields :
117
- fields [name ] = []
118
125
fields [name ].append (selection )
126
+
119
127
elif isinstance (selection , ast .InlineFragment ):
120
- if not should_include_node (ctx , directives ) or \
121
- not does_fragment_condition_match (ctx , selection , type ):
128
+ if not should_include_node (ctx , directives ) or not does_fragment_condition_match (ctx , selection , type ):
122
129
continue
123
- collect_fields (
124
- ctx , type , selection .selection_set ,
125
- fields , prev_fragment_names )
130
+
131
+ collect_fields ( ctx , type , selection .selection_set , fields , prev_fragment_names )
132
+
126
133
elif isinstance (selection , ast .FragmentSpread ):
127
134
frag_name = selection .name .value
128
- if frag_name in prev_fragment_names or \
129
- not should_include_node (ctx , directives ):
135
+
136
+ if frag_name in prev_fragment_names or not should_include_node (ctx , directives ):
130
137
continue
138
+
131
139
prev_fragment_names .add (frag_name )
132
140
fragment = ctx .fragments .get (frag_name )
133
141
frag_directives = fragment .directives
134
- if not fragment or \
135
- not should_include_node (ctx , frag_directives ) or \
136
- not does_fragment_condition_match (ctx , fragment , type ):
142
+ if not fragment or not \
143
+ should_include_node (ctx , frag_directives ) or not \
144
+ does_fragment_condition_match (ctx , fragment , type ):
137
145
continue
138
- collect_fields (
139
- ctx , type , fragment .selection_set ,
140
- fields , prev_fragment_names )
146
+
147
+ collect_fields ( ctx , type , fragment .selection_set , fields , prev_fragment_names )
148
+
141
149
return fields
142
150
143
151
@@ -146,10 +154,12 @@ def should_include_node(ctx, directives):
146
154
@skip directives, where @skip has higher precidence than @include."""
147
155
if directives :
148
156
skip_ast = None
157
+
149
158
for directive in directives :
150
159
if directive .name .value == GraphQLSkipDirective .name :
151
160
skip_ast = directive
152
161
break
162
+
153
163
if skip_ast :
154
164
args = get_argument_values (
155
165
GraphQLSkipDirective .args ,
@@ -159,16 +169,19 @@ def should_include_node(ctx, directives):
159
169
return not args .get ('if' )
160
170
161
171
include_ast = None
172
+
162
173
for directive in directives :
163
174
if directive .name .value == GraphQLIncludeDirective .name :
164
175
include_ast = directive
165
176
break
177
+
166
178
if include_ast :
167
179
args = get_argument_values (
168
180
GraphQLIncludeDirective .args ,
169
181
include_ast .arguments ,
170
182
ctx .variables ,
171
183
)
184
+
172
185
return bool (args .get ('if' ))
173
186
174
187
return True
0 commit comments