@@ -89,10 +89,6 @@ def wrap_executor_context_init(wrapped, instance, args, kwargs):
8989 return result
9090
9191
92- def bind_operation_v3 (operation , root_value ):
93- return operation
94-
95-
9692def wrap_execute_operation (wrapped , instance , args , kwargs ):
9793 transaction = current_transaction ()
9894 trace = current_trace ()
@@ -106,13 +102,14 @@ def wrap_execute_operation(wrapped, instance, args, kwargs):
106102 )
107103 return wrapped (* args , ** kwargs )
108104
105+ execution_context = instance
106+
109107 try :
110- operation = bind_operation_v3 (* args , ** kwargs )
111- except TypeError :
108+ # Works for both v3.2 and v3.3+
109+ operation = execution_context .operation
110+ except (TypeError , AttributeError ):
112111 return wrapped (* args , ** kwargs )
113112
114- execution_context = instance
115-
116113 trace .operation_name = get_node_value (operation , "name" ) or "<anonymous>"
117114
118115 trace .operation_type = get_node_value (operation , "operation" , "name" ).lower () or "<unknown>"
@@ -270,6 +267,7 @@ def wrap_get_field_resolver(wrapped, instance, args, kwargs):
270267
271268
272269def wrap_get_field_def (wrapped , instance , args , kwargs ):
270+ """In v3.3+ this is called `get_field` and it is called from schema itself"""
273271 result = wrapped (* args , ** kwargs )
274272
275273 if hasattr (result , "resolve" ):
@@ -353,24 +351,24 @@ def wrap_parse(wrapped, instance, args, kwargs):
353351 return wrapped (* args , ** kwargs )
354352
355353
356- def bind_resolve_field_v3 (parent_type , source , field_nodes , path ):
354+ def bind_resolve_field (parent_type , source , field_nodes , path , * args , ** kwargs ):
355+ """This is called execute_field in GraphQL-core v3.3+"""
357356 return parent_type , field_nodes , path
358357
359358
360359def wrap_resolve_field (wrapped , instance , args , kwargs ):
360+ """This is called execute_field in GraphQL-core v3.3+"""
361361 transaction = current_transaction ()
362362 if transaction is None :
363363 return wrapped (* args , ** kwargs )
364364
365- bind_resolve_field = bind_resolve_field_v3
366-
367365 try :
368366 parent_type , field_asts , field_path = bind_resolve_field (* args , ** kwargs )
369367 except TypeError :
370368 return wrapped (* args , ** kwargs )
371369
372370 field_name = field_asts [0 ].name .value
373- field_def = parent_type .fields .get (field_name )
371+ field_def = parent_type .fields .get (field_name , None )
374372 field_return_type = str (field_def .type ) if field_def else "<unknown>"
375373 if isinstance (field_path , list ):
376374 field_path = field_path [0 ]
@@ -470,6 +468,11 @@ def wrap_graphql_impl(wrapped, instance, args, kwargs):
470468 return result
471469
472470
471+ def instrument_graphql_schema_get_field (module ):
472+ if hasattr (module , "GraphQLSchema" ) and hasattr (module .GraphQLSchema , "get_field" ):
473+ wrap_function_wrapper (module , "GraphQLSchema.get_field" , wrap_get_field_def )
474+
475+
473476def instrument_graphql_execute (module ):
474477 if hasattr (module , "get_field_def" ):
475478 wrap_function_wrapper (module , "get_field_def" , wrap_get_field_def )
0 commit comments