Skip to content

Commit 861f91c

Browse files
authored
Merge branch 'main' into fix-verison-check
2 parents b584946 + 541d126 commit 861f91c

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

newrelic/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,6 +2886,12 @@ def _process_module_builtin_defaults():
28862886
"instrument_graphql_validate",
28872887
)
28882888

2889+
_process_module_definition(
2890+
"graphql.type.schema",
2891+
"newrelic.hooks.framework_graphql",
2892+
"instrument_graphql_schema_get_field",
2893+
)
2894+
28892895
_process_module_definition(
28902896
"google.cloud.firestore_v1.base_client",
28912897
"newrelic.hooks.datastore_firestore",

newrelic/hooks/framework_graphql.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
9692
def 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

272269
def 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

360359
def 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+
473476
def instrument_graphql_execute(module):
474477
if hasattr(module, "get_field_def"):
475478
wrap_function_wrapper(module, "get_field_def", wrap_get_field_def)

tests/framework_graphql/test_application.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
from newrelic.common.object_names import callable_name
3737
from newrelic.common.package_version_utils import get_package_version
3838

39-
4039
graphql_version = get_package_version("graphql-core")
4140

41+
4242
def conditional_decorator(decorator, condition):
4343
def _conditional_decorator(func):
4444
if not condition:
@@ -150,7 +150,6 @@ def test_query_and_mutation(target_application):
150150
("GraphQL/resolve/%s/storage" % framework, 1),
151151
("GraphQL/operation/%s/query/<anonymous>/storage" % framework, 1),
152152
]
153-
154153
_expected_mutation_operation_attributes = {
155154
"graphql.operation.type": "mutation",
156155
"graphql.operation.name": "<anonymous>",

tox.ini

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ envlist =
132132
python-framework_flask-{py38,py39,py310,py311,py312,pypy310}-flask{020205,latest,master},
133133
python-framework_graphene-{py37,py38,py39,py310,py311,py312}-graphenelatest,
134134
python-framework_graphql-{py37,py38,py39,py310,py311,py312,pypy310}-graphql03,
135-
; temporarily disabling graphqlmaster tests
136-
python-framework_graphql-{py37,py38,py39,py310,py311,py312,pypy310}-graphqllatest,
137-
python-framework_graphql-py37-graphql{0300,0301,0302},
135+
python-framework_graphql-{py37,py38,py39,py310,py311,py312,pypy310}-graphql{latest,master},
136+
python-framework_graphql-py37-graphql{0301,0302},
138137
python-framework_pyramid-{py37,py38,py39,py310,py311,py312,pypy310}-Pyramidlatest,
139138
python-framework_pyramid-{py37,py38,py39,py310,py311,py312,pypy310}-Pyramid0110-cornice,
140139
python-framework_sanic-{py37,py38,py39,py310,py311,py312,pypy310}-saniclatest,
@@ -323,7 +322,6 @@ deps =
323322
framework_graphene-graphenelatest: graphene
324323
framework_graphql-graphqllatest: graphql-core
325324
framework_graphql-graphql03: graphql-core<4
326-
framework_graphql-graphql0300: graphql-core<3.1
327325
framework_graphql-graphql0301: graphql-core<3.2
328326
framework_graphql-graphql0302: graphql-core<3.3
329327
framework_graphql-graphqlmaster: https://github.com/graphql-python/graphql-core/archive/main.zip

0 commit comments

Comments
 (0)