From 1358ce22dce96ab34b0622ad991e669f0a968a88 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Thu, 16 Jan 2025 15:14:36 -0800 Subject: [PATCH] wip --- .../contrib/graphql/test_schema_examples.rb | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/spec/datadog/tracing/contrib/graphql/test_schema_examples.rb b/spec/datadog/tracing/contrib/graphql/test_schema_examples.rb index 96926b6449b..8bb99e877ad 100644 --- a/spec/datadog/tracing/contrib/graphql/test_schema_examples.rb +++ b/spec/datadog/tracing/contrib/graphql/test_schema_examples.rb @@ -26,12 +26,22 @@ def user(id:) field :graphql_error, ::GraphQL::Types::Int, description: 'Raises error' def graphql_error - raise ::GraphQL::ExecutionError, 'GraphQL error' + raise 'GraphQL error' end end class #{prefix}TestGraphQLSchema < ::GraphQL::Schema query(#{prefix}TestGraphQLQuery) + + rescue_from(RuntimeError) do |err, obj, args, ctx, field| + raise GraphQL::ExecutionError.new(err.message, extensions: { + 'int-1': 1, + 'str-1': '1', + 'array-1-2': [1,'2'], + '': 'empty string', + ',': 'comma', + }) + end end RUBY # rubocop:enable Style/DocumentDynamicEvalDefinition @@ -85,7 +95,7 @@ def unload_test_schema(prefix: '') let(:schema) { Object.const_get("#{prefix}TestGraphQLSchema") } let(:service) { defined?(super) ? super() : tracer.default_service } - describe 'query trace' do + xdescribe 'query trace' do subject(:result) { schema.execute(query: 'query Users($var: ID!){ user(id: $var) { name } }', variables: { var: 1 }) } matrix = [ @@ -148,11 +158,7 @@ def unload_test_schema(prefix: '') let(:graphql_execute) { spans.find { |s| s.name == 'graphql.execute' } } it 'creates query span for error' do - expect(result.to_h['errors']).to contain_exactly( - 'message' => 'GraphQL error', - 'locations' => [{ 'line' => 1, 'column' => 14 }], - 'path' => ['graphqlError'] - ) + expect(result.to_h['errors'][0]['message']).to eq('GraphQL error') expect(result.to_h['data']).to eq('graphqlError' => nil) expect(graphql_execute.resource).to eq('Error') @@ -168,11 +174,11 @@ def unload_test_schema(prefix: '') a_span_event_with( name: 'dd.graphql.query.error', attributes: { - message: 'GraphQL error', - type: 'GraphQL::ExecutionError', - stacktrace: include(__FILE__), - locations: ['1:14'], - path: ['graphqlError'], + 'message' => 'GraphQL error', + 'type' => 'GraphQL::ExecutionError', + 'stacktrace' => include(__FILE__), + 'locations' => ['1:14'], + 'path' => ['graphqlError'], } ) )