Skip to content

Commit e5ba99f

Browse files
committed
get_field_def: accept FieldNode instead of field name
Replicates graphql/graphql-js@6fd5607
1 parent a145cf6 commit e5ba99f

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/graphql/execution/execute.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,7 @@ def resolve_field(
590590
resolve function, then calls complete_value to await coroutine objects,
591591
serialize scalars, or execute the sub-selection-set for objects.
592592
"""
593-
field_node = field_nodes[0]
594-
field_name = field_node.name.value
595-
596-
field_def = get_field_def(self.schema, parent_type, field_name)
593+
field_def = get_field_def(self.schema, parent_type, field_nodes[0])
597594
if not field_def:
598595
return Undefined
599596

@@ -1191,7 +1188,7 @@ def assert_valid_execution_arguments(
11911188

11921189

11931190
def get_field_def(
1194-
schema: GraphQLSchema, parent_type: GraphQLObjectType, field_name: str
1191+
schema: GraphQLSchema, parent_type: GraphQLObjectType, field_node: FieldNode
11951192
) -> GraphQLField:
11961193
"""Get field definition.
11971194
@@ -1204,6 +1201,8 @@ def get_field_def(
12041201
12051202
For internal use only.
12061203
"""
1204+
field_name = field_node.name.value
1205+
12071206
if field_name == "__schema" and schema.query_type == parent_type:
12081207
return SchemaMetaFieldDef
12091208
elif field_name == "__type" and schema.query_type == parent_type:

src/graphql/subscription/subscribe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ async def execute_subscription(context: ExecutionContext) -> AsyncIterable[Any]:
165165
type_ = get_operation_root_type(schema, context.operation)
166166
fields = context.collect_fields(type_, context.operation.selection_set, {}, set())
167167
response_name, field_nodes = next(iter(fields.items()))
168-
field_name = field_nodes[0].name.value
169-
field_def = get_field_def(schema, type_, field_name)
168+
field_def = get_field_def(schema, type_, field_nodes[0])
170169

171170
if not field_def:
171+
field_name = field_nodes[0].name.value
172172
raise GraphQLError(
173173
f"The subscription field '{field_name}' is not defined.", field_nodes
174174
)

0 commit comments

Comments
 (0)