Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goodspark committed Oct 8, 2024
1 parent 2ca06ad commit 19ebc9d
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/contrib/graphql/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def enable_graphql_resolvers():
yield


@pytest.fixture
def enable_simplify_resource_names():
with override_config("graphql", dict(simplify_resource_name=True)):
yield


@pytest.fixture
def test_schema():
return graphql.GraphQLSchema(
Expand Down Expand Up @@ -187,3 +193,20 @@ def test(test_schema, test_source_str):
out, err, status, _ = ddtrace_run_python_code_in_subprocess(code, env=env)
assert status == 0, out.decode()
assert err == b"", err.decode()


@pytest.mark.snapshot
@pytest.mark.usefixtures("enable_simplify_resource_names")
@pytest.mark.parametrize(
"source_str",
[
pytest.param("query { hello }", id="no-name"),
pytest.param("query Name { hello }", id="query-name"),
pytest.param("query Name($arg: String) { hello }", id="query-name-with-arg"),
],
)
def test_simple_resource_names(source_str, test_schema):
source = graphql.language.source.Source(source_str, "GraphQL request")
document_ast = graphql.language.parser.parse(source)
result = graphql.execute(test_schema, document_ast)
assert result.data == {"hello": "friend"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[[
{
"name": "graphql.parse",
"service": "graphql",
"resource": "graphql.parse",
"trace_id": 0,
"span_id": 1,
"parent_id": 0,
"type": "graphql",
"error": 0,
"meta": {
"_dd.base_service": "",
"_dd.p.dm": "-0",
"_dd.p.tid": "6704d09800000000",
"component": "graphql",
"graphql.source": "query { hello }",
"language": "python",
"runtime-id": "1827a5391f4e49098f51092c2bff10f2"
},
"metrics": {
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"process_id": 39155
},
"duration": 208383,
"start": 1728368792959860894
}],
[
{
"name": "graphql.execute",
"service": "graphql",
"resource": "query { hello }",
"trace_id": 1,
"span_id": 1,
"parent_id": 0,
"type": "graphql",
"error": 0,
"meta": {
"_dd.base_service": "",
"_dd.p.dm": "-0",
"_dd.p.tid": "6704d09800000000",
"component": "graphql",
"graphql.operation.type": "query",
"graphql.source": "query { hello }",
"language": "python",
"runtime-id": "1827a5391f4e49098f51092c2bff10f2"
},
"metrics": {
"_dd.measured": 1,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"process_id": 39155
},
"duration": 170810,
"start": 1728368792960462650
}]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[[
{
"name": "graphql.parse",
"service": "graphql",
"resource": "graphql.parse",
"trace_id": 0,
"span_id": 1,
"parent_id": 0,
"type": "graphql",
"error": 0,
"meta": {
"_dd.base_service": "",
"_dd.p.dm": "-0",
"_dd.p.tid": "6704d09800000000",
"component": "graphql",
"graphql.source": "query Name($arg: String) { hello }",
"language": "python",
"runtime-id": "1827a5391f4e49098f51092c2bff10f2"
},
"metrics": {
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"process_id": 39155
},
"duration": 161928,
"start": 1728368792981910765
}],
[
{
"name": "graphql.execute",
"service": "graphql",
"resource": "query Name",
"trace_id": 1,
"span_id": 1,
"parent_id": 0,
"type": "graphql",
"error": 0,
"meta": {
"_dd.base_service": "",
"_dd.p.dm": "-0",
"_dd.p.tid": "6704d09800000000",
"component": "graphql",
"graphql.operation.name": "Name",
"graphql.operation.type": "query",
"graphql.source": "query Name($arg: String) { hello }",
"language": "python",
"runtime-id": "1827a5391f4e49098f51092c2bff10f2"
},
"metrics": {
"_dd.measured": 1,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"process_id": 39155
},
"duration": 148166,
"start": 1728368792982168023
}]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[[
{
"name": "graphql.parse",
"service": "graphql",
"resource": "graphql.parse",
"trace_id": 0,
"span_id": 1,
"parent_id": 0,
"type": "graphql",
"error": 0,
"meta": {
"_dd.base_service": "",
"_dd.p.dm": "-0",
"_dd.p.tid": "6704d09800000000",
"component": "graphql",
"graphql.source": "query Name { hello }",
"language": "python",
"runtime-id": "1827a5391f4e49098f51092c2bff10f2"
},
"metrics": {
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"process_id": 39155
},
"duration": 110426,
"start": 1728368792975497665
}],
[
{
"name": "graphql.execute",
"service": "graphql",
"resource": "query Name",
"trace_id": 1,
"span_id": 1,
"parent_id": 0,
"type": "graphql",
"error": 0,
"meta": {
"_dd.base_service": "",
"_dd.p.dm": "-0",
"_dd.p.tid": "6704d09800000000",
"component": "graphql",
"graphql.operation.name": "Name",
"graphql.operation.type": "query",
"graphql.source": "query Name { hello }",
"language": "python",
"runtime-id": "1827a5391f4e49098f51092c2bff10f2"
},
"metrics": {
"_dd.measured": 1,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"process_id": 39155
},
"duration": 142495,
"start": 1728368792975699668
}]]

0 comments on commit 19ebc9d

Please sign in to comment.