1313# limitations under the License.
1414
1515import pytest
16+ import sys
1617from testing_support .fixtures import validate_transaction_metrics , validate_transaction_errors , dt_enabled
1718from testing_support .validators .validate_span_events import validate_span_events
1819
@@ -49,11 +50,6 @@ def error_middleware(next, root, info, **args):
4950
5051_runtime_error_name = callable_name (RuntimeError )
5152_test_runtime_error = [(_runtime_error_name , "Runtime Error!" )]
52- _expected_attributes = {
53- "graphql.operation.name" : "MyQuery" ,
54- "graphql.operation.type" : "query" ,
55- "graphql.operation.deepestPath" : "hello"
56- }
5753_graphql_base_rollup_metrics = [
5854 ("OtherTransaction/all" , 1 ),
5955 ("GraphQL/all" , 1 ),
@@ -64,25 +60,61 @@ def error_middleware(next, root, info, **args):
6460
6561
6662@dt_enabled
67- def test_basic (app , graphql_run , is_graphql_2 ):
68- _test_basic_metrics = [
69- ("OtherTransaction/Function/_target_application:resolve_hello" , 1 ),
70- ("GraphQL/operation/GraphQL/query/MyQuery/hello" , 1 ),
71- #("Function/_target_application:resolve_hello", 1),
63+ def test_basic (app , graphql_run ):
64+ _test_mutation_scoped_metrics = [
65+ ("GraphQL/resolve/GraphQL/storage" , 1 ),
66+ ("GraphQL/resolve/GraphQL/storage_add" , 1 ),
67+ ("GraphQL/operation/GraphQL/query/<anonymous>/storage" , 1 ),
68+ ("GraphQL/operation/GraphQL/mutation/<anonymous>/storage_add" , 1 ),
7269 ]
73-
70+ _test_mutation_unscoped_metrics = [
71+ ("OtherTransaction/all" , 1 ),
72+ ("GraphQL/all" , 2 ),
73+ ("GraphQL/GraphQL/all" , 2 ),
74+ ("GraphQL/allOther" , 2 ),
75+ ("GraphQL/GraphQL/allOther" , 2 ),
76+ ] + _test_mutation_scoped_metrics
77+
78+ _expected_mutation_operation_attributes = {
79+ "graphql.operation.type" : "mutation" ,
80+ "graphql.operation.name" : "<anonymous>" ,
81+ "graphql.operation.deepestPath" : "storage_add" ,
82+ }
83+ _expected_mutation_resolver_attributes = {
84+ "graphql.field.name" : "storage_add" ,
85+ "graphql.field.parentType" : "Mutation" ,
86+ "graphql.field.path" : "storage_add" ,
87+ }
88+ _expected_query_operation_attributes = {
89+ "graphql.operation.type" : "query" ,
90+ "graphql.operation.name" : "<anonymous>" ,
91+ "graphql.operation.deepestPath" : "storage" ,
92+ }
93+ _expected_query_resolver_attributes = {
94+ "graphql.field.name" : "storage" ,
95+ "graphql.field.parentType" : "Query" ,
96+ "graphql.field.path" : "storage" ,
97+ }
7498 @validate_transaction_metrics (
75- "_target_application:resolve_hello" ,
76- rollup_metrics = _test_basic_metrics + _graphql_base_rollup_metrics ,
99+ "_target_application:resolve_storage" ,
100+ scoped_metrics = _test_mutation_scoped_metrics ,
101+ rollup_metrics = _test_mutation_unscoped_metrics ,
77102 background_task = True ,
78103 )
79- @validate_span_events (exact_agents = _expected_attributes )
104+ @validate_span_events (exact_agents = _expected_mutation_operation_attributes )
105+ @validate_span_events (exact_agents = _expected_mutation_resolver_attributes )
106+ @validate_span_events (exact_agents = _expected_query_operation_attributes )
107+ @validate_span_events (exact_agents = _expected_query_resolver_attributes )
80108 @background_task ()
81109 def _test ():
82- response = graphql_run (app , "query MyQuery{ hello }" )
110+ response = graphql_run (app , 'mutation { storage_add(string: "abc") }' )
111+ assert not response .errors
112+ response = graphql_run (app , "query { storage }" )
83113 assert not response .errors
84- assert "Hello!" in str (response .data )
85114
115+ # These are separate assertions because pypy stores 'abc' as a unicode string while other Python versions do not
116+ assert "storage" in str (response .data )
117+ assert "abc" in str (response .data )
86118 _test ()
87119
88120
@@ -193,3 +225,4 @@ def _test():
193225 assert "Hello!" in str (response .data )
194226
195227 _test ()
228+
0 commit comments