From e3c0f8b2199b784ee8e9cde191177299eaaea248 Mon Sep 17 00:00:00 2001 From: Sam Davies Date: Mon, 16 Dec 2024 09:37:15 -0500 Subject: [PATCH] wip --- core/web/resolver/spec.go | 13 +++-- core/web/resolver/spec_test.go | 85 +++++++++++++++++++++++++++++++ core/web/schema/type/spec.graphql | 2 +- 3 files changed, 94 insertions(+), 6 deletions(-) diff --git a/core/web/resolver/spec.go b/core/web/resolver/spec.go index ce23df49264..f91421b5133 100644 --- a/core/web/resolver/spec.go +++ b/core/web/resolver/spec.go @@ -1,8 +1,6 @@ package resolver import ( - "fmt" - "github.com/graph-gophers/graphql-go" "github.com/smartcontractkit/chainlink/v2/core/services/job" @@ -139,8 +137,13 @@ func (r *SpecResolver) ToStreamSpec() (*StreamSpecResolver, bool) { if r.j.Type != job.Stream { return nil, false } + res := &StreamSpecResolver{} + if r.j.StreamID != nil { + sid := int64(*r.j.StreamID) + res.streamID = &sid + } - return &StreamSpecResolver{streamID: fmt.Sprintf("%d", r.j.StreamID)}, true + return res, true } type CronSpecResolver struct { @@ -1057,9 +1060,9 @@ func (r *StandardCapabilitiesSpecResolver) Config() *string { } type StreamSpecResolver struct { - streamID string + streamID *int64 } -func (r *StreamSpecResolver) StreamID() string { +func (r *StreamSpecResolver) StreamID() *int64 { return r.streamID } diff --git a/core/web/resolver/spec_test.go b/core/web/resolver/spec_test.go index 69d6a56509c..f0d3a2752ee 100644 --- a/core/web/resolver/spec_test.go +++ b/core/web/resolver/spec_test.go @@ -1166,3 +1166,88 @@ func TestResolver_StandardCapabilitiesSpec(t *testing.T) { RunGQLTests(t, testCases) } + +func TestResolver_StreamSpec(t *testing.T) { + const ( + id = int32(1) + streamID = uint32(2) + ) + + 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, id).Return(job.Job{ + Type: job.Stream, + StreamID: &streamID, + }, nil) + }, + query: ` + query GetJob { + job(id: "1") { + ... on Job { + spec { + __typename + ... on StreamSpec { + streamID + createdAt + } + } + } + } + } + `, + result: ` + { + "job": { + "spec": { + "__typename": "CronSpec", + "streamID": "2", + "createdAt": "2021-01-01T00:00:00Z" + } + } + } + `, + }, + { + 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, id).Return(job.Job{ + Type: job.Stream, + }, nil) + }, + query: ` + query GetJob { + job(id: "1") { + ... on Job { + spec { + __typename + ... on StreamSpec { + streamID + createdAt + } + } + } + } + } + `, + result: ` + { + "job": { + "spec": { + "__typename": "CronSpec", + "streamID": null, + "createdAt": "2021-01-01T00:00:00Z" + } + } + } + `, + }, + } + + RunGQLTests(t, testCases) +} diff --git a/core/web/schema/type/spec.graphql b/core/web/schema/type/spec.graphql index db81001543c..85c8e0cbcf1 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: Int }