Skip to content

Commit

Permalink
Guard GraphQL Settings Lookup (#787)
Browse files Browse the repository at this point in the history
* Guard graphql settings lookup

* [Mega-Linter] Apply linters fixes

* Bump tests

* Update graphql settings test

---------

Co-authored-by: TimPansino <TimPansino@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 30, 2023
1 parent 912d088 commit 637879a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions newrelic/hooks/framework_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def bind_operation_v2(exe_context, operation, root_value):
def wrap_execute_operation(wrapped, instance, args, kwargs):
transaction = current_transaction()
trace = current_trace()
settings = transaction.settings

if not transaction:
return wrapped(*args, **kwargs)
Expand Down Expand Up @@ -136,7 +135,7 @@ def wrap_execute_operation(wrapped, instance, args, kwargs):
if operation.selection_set is not None:
fields = operation.selection_set.selections
# Ignore transactions for introspection queries
if not settings.instrumentation.graphql.capture_introspection_queries:
if not (transaction.settings and transaction.settings.instrumentation.graphql.capture_introspection_queries):
# If all selected fields are introspection fields
if all(get_node_value(field, "name") in GRAPHQL_INTROSPECTION_FIELDS for field in fields):
ignore_transaction()
Expand Down
8 changes: 8 additions & 0 deletions tests/framework_graphql/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def error_middleware(next, root, info, **args):
raise RuntimeError("Runtime Error!")


def test_no_harm_no_transaction(app, graphql_run):
def _test():
response = graphql_run(app, "{ __schema { types { name } } }")
assert not response.errors

_test()


_runtime_error_name = callable_name(RuntimeError)
_test_runtime_error = [(_runtime_error_name, "Runtime Error!")]
_graphql_base_rollup_metrics = [
Expand Down

0 comments on commit 637879a

Please sign in to comment.