Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Jan 16, 2025
1 parent d56d8a0 commit 1358ce2
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions spec/datadog/tracing/contrib/graphql/test_schema_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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')
Expand All @@ -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'],
}
)
)
Expand Down

0 comments on commit 1358ce2

Please sign in to comment.