Commit 7211e6ab authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Markus Koller

Use GlobalID in error tracking

This changes the type of id from ID to the more meaningful
GlobalIDType[Gitlab::ErrorTracking::DetailedError]

This is a bit of an interim fix, since these IDs (being sentry IDs
really) don't make much sense as global IDs, which are meant to
represent application resources.
parent e2f4a758
......@@ -5,19 +5,20 @@ module Resolvers
class SentryDetailedErrorResolver < BaseResolver
type Types::ErrorTracking::SentryDetailedErrorType, null: true
argument :id, GraphQL::ID_TYPE,
argument :id, ::Types::GlobalIDType[::Gitlab::ErrorTracking::DetailedError],
required: true,
description: 'ID of the Sentry issue'
def resolve(**args)
current_user = context[:current_user]
issue_id = GlobalID.parse(args[:id])&.model_id
def resolve(id:)
# TODO: remove this line when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
id = ::Types::GlobalIDType[::Gitlab::ErrorTracking::DetailedError].coerce_isolated_input(id)
# Get data from Sentry
response = ::ErrorTracking::IssueDetailsService.new(
project,
current_user,
{ issue_id: issue_id }
{ issue_id: id.model_id }
).execute
issue = response[:issue]
issue.gitlab_project = project if issue
......
......@@ -3,18 +3,20 @@
module Resolvers
module ErrorTracking
class SentryErrorStackTraceResolver < BaseResolver
argument :id, GraphQL::ID_TYPE,
argument :id, ::Types::GlobalIDType[::Gitlab::ErrorTracking::DetailedError],
required: true,
description: 'ID of the Sentry issue'
def resolve(**args)
issue_id = GlobalID.parse(args[:id])&.model_id
def resolve(id:)
# TODO: remove this line when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
id = ::Types::GlobalIDType[::Gitlab::ErrorTracking::DetailedError].coerce_isolated_input(id)
# Get data from Sentry
response = ::ErrorTracking::IssueLatestEventService.new(
project,
current_user,
{ issue_id: issue_id }
{ issue_id: id.model_id }
).execute
event = response[:latest_event]
......
---
title: Use global IDs for GraphQL arguments accepting sentry IDs
merge_request: 36098
author:
type: changed
......@@ -8097,6 +8097,11 @@ type GeoNode {
verificationMaxCapacity: Int
}
"""
Identifier of Gitlab::ErrorTracking::DetailedError
"""
scalar GitlabErrorTrackingDetailedErrorID
type GrafanaIntegration {
"""
Timestamp of the issue's creation
......@@ -15910,7 +15915,7 @@ type Project {
"""
ID of the Sentry issue
"""
id: ID!
id: GitlabErrorTrackingDetailedErrorID!
): SentryDetailedError
"""
......@@ -19249,7 +19254,7 @@ type SentryErrorCollection {
"""
ID of the Sentry issue
"""
id: ID!
id: GitlabErrorTrackingDetailedErrorID!
): SentryDetailedError
"""
......@@ -19259,7 +19264,7 @@ type SentryErrorCollection {
"""
ID of the Sentry issue
"""
id: ID!
id: GitlabErrorTrackingDetailedErrorID!
): SentryErrorStackTrace
"""
......
......@@ -22356,6 +22356,16 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "SCALAR",
"name": "GitlabErrorTrackingDetailedErrorID",
"description": "Identifier of Gitlab::ErrorTracking::DetailedError",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "GrafanaIntegration",
......@@ -46148,7 +46158,7 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"name": "GitlabErrorTrackingDetailedErrorID",
"ofType": null
}
},
......@@ -55651,7 +55661,7 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"name": "GitlabErrorTrackingDetailedErrorID",
"ofType": null
}
},
......@@ -55678,7 +55688,7 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"name": "GitlabErrorTrackingDetailedErrorID",
"ofType": null
}
},
......@@ -65,7 +65,9 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
context 'blank id' do
let(:args) { { id: '' } }
it_behaves_like 'it resolves to nil'
it 'responds with an error' do
expect { resolve_error(args) }.to raise_error(::GraphQL::CoercionError)
end
end
end
......
......@@ -191,7 +191,7 @@ RSpec.describe 'sentry errors requests' do
describe 'getting a stack trace' do
let_it_be(:sentry_stack_trace) { build(:error_tracking_error_event) }
let(:sentry_gid) { Gitlab::ErrorTracking::DetailedError.new(id: 1).to_global_id.to_s }
let(:sentry_gid) { global_id_of(Gitlab::ErrorTracking::DetailedError.new(id: 1)) }
let(:stack_trace_fields) do
all_graphql_fields_for('SentryErrorStackTrace'.classify)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment