diff --git a/core/web/resolver/spec.go b/core/web/resolver/spec.go index ce23df49264..ca88f75a519 100644 --- a/core/web/resolver/spec.go +++ b/core/web/resolver/spec.go @@ -1,7 +1,7 @@ package resolver import ( - "fmt" + "strconv" "github.com/graph-gophers/graphql-go" @@ -139,8 +139,13 @@ func (r *SpecResolver) ToStreamSpec() (*StreamSpecResolver, bool) { if r.j.Type != job.Stream { return nil, false } + res := &StreamSpecResolver{} + if r.j.StreamID != nil { + sid := strconv.FormatUint(uint64(*r.j.StreamID), 10) + res.streamID = &sid + } - return &StreamSpecResolver{streamID: fmt.Sprintf("%d", r.j.StreamID)}, true + return res, true } type CronSpecResolver struct { @@ -1057,9 +1062,9 @@ func (r *StandardCapabilitiesSpecResolver) Config() *string { } type StreamSpecResolver struct { - streamID string + streamID *string } -func (r *StreamSpecResolver) StreamID() string { +func (r *StreamSpecResolver) StreamID() *string { return r.streamID } diff --git a/core/web/resolver/spec_test.go b/core/web/resolver/spec_test.go index 69d6a56509c..ed6cbb459b6 100644 --- a/core/web/resolver/spec_test.go +++ b/core/web/resolver/spec_test.go @@ -2,6 +2,7 @@ package resolver import ( "context" + "fmt" "testing" "time" @@ -1166,3 +1167,85 @@ func TestResolver_StandardCapabilitiesSpec(t *testing.T) { RunGQLTests(t, testCases) } + +func TestResolver_StreamSpec(t *testing.T) { + var ( + id1 = int32(1) + id2 = int32(2) + streamID = uint32(3) + ) + + testCases := []GQLTestCase{ + { + name: "stream spec with stream ID", + authenticated: true, + before: func(ctx context.Context, f *gqlTestFramework) { + f.App.On("JobORM").Return(f.Mocks.jobORM) + f.Mocks.jobORM.On("FindJobWithoutSpecErrors", mock.Anything, id1).Return(job.Job{ + Type: job.Stream, + StreamID: &streamID, + }, nil) + }, + query: fmt.Sprintf(` + query GetJob { + job(id: "%d") { + ... on Job { + spec { + __typename + ... on StreamSpec { + streamID + } + } + } + } + } + `, id1), + result: fmt.Sprintf(` + { + "job": { + "spec": { + "__typename": "StreamSpec", + "streamID": "%d" + } + } + } + `, streamID), + }, + { + name: "stream spec without stream ID", + authenticated: true, + before: func(ctx context.Context, f *gqlTestFramework) { + f.App.On("JobORM").Return(f.Mocks.jobORM) + f.Mocks.jobORM.On("FindJobWithoutSpecErrors", mock.Anything, id2).Return(job.Job{ + Type: job.Stream, + }, nil) + }, + query: fmt.Sprintf(` + query GetJob { + job(id: "%d") { + ... on Job { + spec { + __typename + ... on StreamSpec { + streamID + } + } + } + } + } + `, id2), + result: ` + { + "job": { + "spec": { + "__typename": "StreamSpec", + "streamID": null + } + } + } + `, + }, + } + + RunGQLTests(t, testCases) +} diff --git a/core/web/schema/type/spec.graphql b/core/web/schema/type/spec.graphql index db81001543c..1efeb2c77ba 100644 --- a/core/web/schema/type/spec.graphql +++ b/core/web/schema/type/spec.graphql @@ -182,5 +182,5 @@ type StandardCapabilitiesSpec { } type StreamSpec { - streamID: String! + streamID: String }