Skip to content
Merged
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
2 changes: 1 addition & 1 deletion ddtrace/contrib/graphql/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def _get_source_str(obj):
source_str = obj
elif isinstance(obj, Source):
source_str = obj.body
elif isinstance(obj, Document):
elif isinstance(obj, Document) and obj.loc is not None:
source_str = obj.loc.source.body
else:
source_str = ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
graphql: Resolves ``AttributeError`` raised while parsing graphql Documents where AST Location is None.
8 changes: 8 additions & 0 deletions tests/contrib/graphql/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ def test_graphql_v2_with_document(test_schema, test_source_str):
assert result.data == {"hello": "friend"}


@snapshot()
def test_graphql_with_document_with_no_location(test_schema, test_source_str):
source = graphql.language.source.Source(test_source_str, "GraphQL request")
document_ast = graphql.language.parser.parse(source, no_location=True)
result = graphql.execute(test_schema, document_ast)
assert result.data == {"hello": "friend"}


@snapshot(token_override="tests.contrib.graphql.test_graphql.test_graphql")
@pytest.mark.skipif(graphql_version < (3, 0), reason="graphql.graphql_sync is NOT suppoerted in v2.0")
def test_graphql_sync(test_schema, test_source_str):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[[
{
"name": "graphql.parse",
"service": "graphql",
"resource": "graphql.parse",
"trace_id": 0,
"span_id": 1,
"parent_id": 0,
"type": "graphql",
"meta": {
"_dd.base_service": "",
"_dd.p.dm": "-0",
"component": "graphql",
"graphql.source": "query HELLO { hello }",
"language": "python",
"runtime-id": "630b203d91914ec1bf98fe21da63344d"
},
"metrics": {
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"process_id": 29253
},
"duration": 284000,
"start": 1695228158961101000
}],
[
{
"name": "graphql.execute",
"service": "graphql",
"resource": "graphql.execute",
"trace_id": 1,
"span_id": 1,
"parent_id": 0,
"type": "graphql",
"meta": {
"_dd.base_service": "",
"_dd.p.dm": "-0",
"component": "graphql",
"graphql.operation.name": "HELLO",
"graphql.operation.type": "query",
"graphql.source": "",
"language": "python",
"runtime-id": "630b203d91914ec1bf98fe21da63344d"
},
"metrics": {
"_dd.measured": 1,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"process_id": 29253
},
"duration": 336000,
"start": 1695228158977945000
}]]