Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defensively check GQL path parts in framework_graphql #829

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions newrelic/hooks/framework_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,16 @@ def wrap_execute_operation(wrapped, instance, args, kwargs):
trace.operation_type = get_node_value(operation, "operation", "name").lower() or "<unknown>"

if operation.selection_set is not None:
fields = operation.selection_set.selections
fields = [f for f in operation.selection_set.selections if f]
# Ignore transactions for 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()

fragments = execution_context.fragments
trace.deepest_path = ".".join(traverse_deepest_unique_path(fields, fragments)) or ""
path_parts = [p for p in traverse_deepest_unique_path(fields, fragments) if p]
trace.deepest_path = ".".join(path_parts) if path_parts else ""

transaction.set_transaction_name(callable_name(wrapped), "GraphQL", priority=11)
result = wrapped(*args, **kwargs)
Expand Down Expand Up @@ -417,7 +418,7 @@ def bind_execute_graphql_query(
operation_name=None,
middleware=None,
backend=None,
**execute_options
**execute_options,
):
return schema, request_string

Expand Down
5 changes: 5 additions & 0 deletions tests/framework_graphql/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,11 @@ def _test():
"{ library(index: 0) { book { ...MyFragment } magazine { ...MagFragment } } } fragment MyFragment on Book { author { first_name } } fragment MagFragment on Magazine { name }",
"/library",
),
# fragement on type union
(
'{ search(contains: "A") { ...MyFragment } fragment MyFragment on Item { __typename ... on Book { name } } }',
"/search<Book>.name",
),
]


Expand Down