Skip to content

Commit 2d5dc93

Browse files
committed
Refactor Connection types with codegen
1 parent f3a901b commit 2d5dc93

47 files changed

Lines changed: 496 additions & 589 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

actions.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,11 @@ func (customActionsTriggerDefinition *CustomActionsTriggerDefinition) ExtendedTe
3838
}
3939
q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.Nodes = append(q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.Nodes, resp.Nodes...)
4040
q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.PageInfo = resp.PageInfo
41-
q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.TotalCount += resp.TotalCount
4241
}
42+
q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.TotalCount = len(q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.Nodes)
4343
return &q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess, nil
4444
}
4545

46-
type CustomActionsExternalActionsConnection struct {
47-
Nodes []CustomActionsExternalAction
48-
PageInfo PageInfo
49-
TotalCount int
50-
}
51-
52-
func (s *CustomActionsExternalActionsConnection) GetNodes() any {
53-
return s.Nodes
54-
}
55-
5646
type CustomActionsTriggerDefinitionsConnection struct {
5747
Nodes []CustomActionsTriggerDefinition
5848
PageInfo PageInfo
@@ -111,6 +101,7 @@ func (client *Client) ListCustomActions(variables *PayloadVariables) (*CustomAct
111101
q.Account.Actions.Nodes = append(q.Account.Actions.Nodes, resp.Nodes...)
112102
q.Account.Actions.PageInfo = resp.PageInfo
113103
}
104+
q.Account.Actions.TotalCount = len(q.Account.Actions.Nodes)
114105
return &q.Account.Actions, nil
115106
}
116107

actions_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ func TestCreateWebhookAction(t *testing.T) {
3939
func TestListCustomActions(t *testing.T) {
4040
// Arrange
4141
testRequestOne := autopilot.NewTestRequest(
42-
`query ExternalActionList($after:String!$first:Int!){account{customActionsExternalActions(after: $after, first: $first){nodes{{ template "custom_actions_request" }},{{ template "pagination_request" }},totalCount}}}`,
42+
`query ExternalActionList($after:String!$first:Int!){account{customActionsExternalActions(after: $after, first: $first){nodes{{ template "custom_actions_request" }},{{ template "pagination_request" }}}}}`,
4343
`{{ template "pagination_initial_query_variables" }}`,
44-
`{ "data": { "account": { "customActionsExternalActions": { "nodes": [ { {{ template "custom_action1_response" }} }, { {{ template "custom_action2_response" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}`,
44+
`{ "data": { "account": { "customActionsExternalActions": { "nodes": [ { {{ template "custom_action1_response" }} }, { {{ template "custom_action2_response" }} } ], {{ template "pagination_initial_pageInfo_response" }} }}}}`,
4545
)
4646
testRequestTwo := autopilot.NewTestRequest(
47-
`query ExternalActionList($after:String!$first:Int!){account{customActionsExternalActions(after: $after, first: $first){nodes{{ template "custom_actions_request" }},{{ template "pagination_request" }},totalCount}}}`,
47+
`query ExternalActionList($after:String!$first:Int!){account{customActionsExternalActions(after: $after, first: $first){nodes{{ template "custom_actions_request" }},{{ template "pagination_request" }}}}}`,
4848
`{{ template "pagination_second_query_variables" }}`,
49-
`{ "data": { "account": { "customActionsExternalActions": { "nodes": [ { {{ template "custom_action3_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
49+
`{ "data": { "account": { "customActionsExternalActions": { "nodes": [ { {{ template "custom_action3_response" }} } ], {{ template "pagination_second_pageInfo_response" }} }}}}`,
5050
)
5151
requests := []autopilot.TestRequest{testRequestOne, testRequestTwo}
5252

5353
client := BestTestClient(t, "custom_actions/list_actions", requests...)
5454
// Act
5555
response, err := client.ListCustomActions(nil)
56+
autopilot.Ok(t, err)
5657
result := response.Nodes
5758
// Assert
58-
autopilot.Ok(t, err)
5959
autopilot.Equals(t, 3, len(result))
6060
autopilot.Equals(t, "Deploy Freeze", result[1].Name)
6161
autopilot.Equals(t, "Page On-Call", result[2].Name)
@@ -352,12 +352,12 @@ func TestDeleteTriggerDefinition(t *testing.T) {
352352
func TestListExtendedTeamAccess(t *testing.T) {
353353
// Arrange
354354
testRequestOne := autopilot.NewTestRequest(
355-
`query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,type},htmlUrl,manager{id,email,htmlUrl,name,provisionedBy,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}`,
355+
`query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,type},htmlUrl,manager{id,email,htmlUrl,name,provisionedBy,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }}},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }}}},{{ template "pagination_request" }}}}}}`,
356356
`{{ template "extended_team_access_get_vars_1" }}`,
357357
`{{ template "extended_team_access_response_1" }}`,
358358
)
359359
testRequestTwo := autopilot.NewTestRequest(
360-
`query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,type},htmlUrl,manager{id,email,htmlUrl,name,provisionedBy,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}}`,
360+
`query ExtendedTeamAccessList($after:String!$first:Int!$input:IdentifierInput!){account{customActionsTriggerDefinition(input: $input){extendedTeamAccess(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,type},htmlUrl,manager{id,email,htmlUrl,name,provisionedBy,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }}},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }}}},{{ template "pagination_request" }}}}}}`,
361361
`{{ template "extended_team_access_get_vars_2" }}`,
362362
`{{ template "extended_team_access_response_2" }}`,
363363
)
@@ -372,10 +372,10 @@ func TestListExtendedTeamAccess(t *testing.T) {
372372
if resp == nil || resp.Nodes == nil || len(resp.Nodes) == 0 {
373373
t.Error("Expected team access response to not be nil")
374374
}
375+
autopilot.Ok(t, err)
375376
result := resp.Nodes
376377

377378
// Assert
378-
autopilot.Ok(t, err)
379379
autopilot.Equals(t, "example", result[0].Alias)
380380
autopilot.Equals(t, id1, result[0].Id)
381381
}

cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ func (cacher *Cacher) doCacheCategories(client *Client) {
189189
func (cacher *Cacher) doCacheLevels(client *Client) {
190190
log.Debug().Msg("Caching 'Level' lookup table from API ...")
191191

192-
data, dataErr := client.ListLevels()
192+
data, dataErr := client.ListLevels(nil)
193193
if dataErr != nil {
194194
log.Warn().Msgf("===> Failed to list all 'Level' from API - REASON: %s", dataErr.Error())
195195
}
196196

197-
for _, item := range data {
197+
for _, item := range data.Nodes {
198198
cacher.Levels[item.Alias] = item
199199
}
200200
}

cache_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ func TestCache(t *testing.T) {
2525
`{"data":{"account":{ "systems":{ "nodes":[{{ template "system1_response" }}] } }}}`,
2626
)
2727
testRequestFour := autopilot.NewTestRequest(
28-
`query TeamList($after:String!$first:Int!){account{teams(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,type},htmlUrl,manager{id,email,htmlUrl,name,provisionedBy,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }},totalCount},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount}},{{ template "pagination_request" }},totalCount}}}`,
28+
`query TeamList($after:String!$first:Int!){account{teams(after: $after, first: $first){nodes{alias,id,aliases,managedAliases,contacts{address,displayName,displayType,externalId,id,isDefault,type},htmlUrl,manager{id,email,htmlUrl,name,provisionedBy,role},memberships{nodes{role,team{alias,id},user{id,email}},{{ template "pagination_request" }}},name,parentTeam{alias,id},responsibilities,tags{nodes{id,key,value},{{ template "pagination_request" }}}},{{ template "pagination_request" }}}}}`,
2929
`{ "after": "", "first": 100 }`,
3030
`{"data":{"account":{ "teams":{ "nodes":[{{ template "team_1" }}] } }}}`,
3131
)
3232
testRequestFive := autopilot.NewTestRequest(
33-
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }},totalCount}}}}`,
33+
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }}}}}}`,
3434
`{ "after": "", "first": 100 }`,
3535
`{"data":{"account":{"rubric":{ "categories":{ "nodes":[{{ template "category_1" }}] } }}}}`,
3636
)
3737
testRequestSix := autopilot.NewTestRequest(
38-
`{account{rubric{levels{nodes{alias,description,id,index,name},{{ template "pagination_request" }},totalCount}}}}`,
39-
`{}`,
38+
`query LevelsList($after:String!$first:Int!){account{rubric{levels(after: $after, first: $first){nodes{alias,description,id,index,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor}}}}}`,
39+
`{ "after": "", "first": 100 }`,
4040
`{"data":{"account":{"rubric":{ "levels":{ "nodes":[{{ template "level_1" }}] } }}}}`,
4141
)
4242
testRequestSeven := autopilot.NewTestRequest(
43-
`query FilterList($after:String!$first:Int!){account{filters(after: $after, first: $first){nodes{id,name,connective,htmlUrl,predicates{caseSensitive,key,keyData,type,value}},{{ template "pagination_request" }},totalCount}}}`,
43+
`query FilterList($after:String!$first:Int!){account{filters(after: $after, first: $first){nodes{id,name,connective,htmlUrl,predicates{caseSensitive,key,keyData,type,value}},{{ template "pagination_request" }}}}}`,
4444
`{ "after": "", "first": 100 }`,
4545
`{"data":{"account":{ "filters":{ "nodes":[{{ template "filter_1" }}] } }}}`,
4646
)
4747
testRequestEight := autopilot.NewTestRequest(
48-
`query IntegrationList($after:String!$first:Int!){account{integrations(after: $after, first: $first){nodes{{ template "integration_request" }},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}`,
48+
`query IntegrationList($after:String!$first:Int!){account{integrations(after: $after, first: $first){nodes{{ template "integration_request" }},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor}}}}`,
4949
`{ "after": "", "first": 100 }`,
5050
`{"data":{"account":{ "integrations":{ "nodes":[{{ template "integration_1" }}] } }}}`,
5151
)
5252
testRequestNine := autopilot.NewTestRequest(
53-
`query RepositoryList($after:String!$first:Int!$visible:Boolean!){account{repositories(after: $after, first: $first, visible: $visible){hiddenCount,nodes{archivedAt,createdOn,defaultAlias,defaultBranch,description,forked,htmlUrl,id,languages{name,usage},lastOwnerChangedAt,locked,name,organization,owner{alias,id},private,repoKey,services{edges{atRoot,node{id,aliases},paths{href,path},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }},totalCount},tags{nodes{id,key,value},{{ template "pagination_request" }},totalCount},tier{alias,description,id,index,name},type,url,visible},organizationCount,ownedCount,{{ template "pagination_request" }},totalCount,visibleCount}}}`,
53+
`query RepositoryList($after:String!$first:Int!$visible:Boolean!){account{repositories(after: $after, first: $first, visible: $visible){hiddenCount,nodes{archivedAt,createdOn,defaultAlias,defaultBranch,description,forked,htmlUrl,id,languages{name,usage},lastOwnerChangedAt,locked,name,organization,owner{alias,id},private,repoKey,services{edges{atRoot,node{id,aliases},paths{href,path},serviceRepositories{baseDirectory,displayName,id,repository{id,defaultAlias},service{id,aliases}}},{{ template "pagination_request" }}},tags{nodes{id,key,value},{{ template "pagination_request" }}},tier{alias,description,id,index,name},type,url,visible},organizationCount,ownedCount,{{ template "pagination_request" }},visibleCount}}}`,
5454
`{ "after": "", "first": 100, "visible": true }`,
5555
`{"data":{"account":{ "repositories":{ "hiddenCount": 0, "nodes":[{{ template "repository_1" }}] } }}}`,
5656
)

category.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ import (
77
"github.com/hasura/go-graphql-client"
88
)
99

10-
type CategoryConnection struct {
11-
Nodes []Category
12-
PageInfo PageInfo
13-
TotalCount int
14-
}
15-
1610
func (category *Category) Alias() string {
1711
return slug.Make(category.Name)
1812
}
@@ -69,8 +63,8 @@ func (client *Client) ListCategories(variables *PayloadVariables) (*CategoryConn
6963
}
7064
q.Account.Rubric.Categories.Nodes = append(q.Account.Rubric.Categories.Nodes, resp.Nodes...)
7165
q.Account.Rubric.Categories.PageInfo = resp.PageInfo
72-
q.Account.Rubric.Categories.TotalCount += resp.TotalCount
7366
}
67+
q.Account.Rubric.Categories.TotalCount = len(q.Account.Rubric.Categories.Nodes)
7468
return &q.Account.Rubric.Categories, nil
7569
}
7670

category_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ func TestGetMissingRubricCategory(t *testing.T) {
5757
func TestListRubricCategories(t *testing.T) {
5858
// Arrange
5959
testRequestOne := autopilot.NewTestRequest(
60-
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }},totalCount}}}}`,
60+
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }}}}}}`,
6161
`{{ template "pagination_initial_query_variables" }}`,
62-
`{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response1" }} }, { {{ template "rubric_categories_response2" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
62+
`{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response1" }} }, { {{ template "rubric_categories_response2" }} } ], {{ template "pagination_initial_pageInfo_response" }} }}}}}`,
6363
)
6464
testRequestTwo := autopilot.NewTestRequest(
65-
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }},totalCount}}}}`,
65+
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }}}}}}`,
6666
`{{ template "pagination_second_query_variables" }}`,
67-
`{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response3" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
67+
`{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response3" }} } ], {{ template "pagination_second_pageInfo_response" }} }}}}}`,
6868
)
6969
requests := []autopilot.TestRequest{testRequestOne, testRequestTwo}
7070

check.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ func UnmarshalCheckUpdateInput(checkType CheckType, data []byte) (any, error) {
7474
return output, nil
7575
}
7676

77-
type CheckConnection struct {
78-
Nodes []Check
79-
PageInfo PageInfo
80-
TotalCount int
81-
}
82-
8377
type CheckCreateInputProvider interface {
8478
GetCheckCreateInput() *CheckCreateInput
8579
}
@@ -210,8 +204,8 @@ func (client *Client) ListChecks(variables *PayloadVariables) (*CheckConnection,
210204
}
211205
q.Account.Rubric.Checks.Nodes = append(q.Account.Rubric.Checks.Nodes, resp.Nodes...)
212206
q.Account.Rubric.Checks.PageInfo = resp.PageInfo
213-
q.Account.Rubric.Checks.TotalCount += resp.TotalCount
214207
}
208+
q.Account.Rubric.Checks.TotalCount = len(q.Account.Rubric.Checks.Nodes)
215209
return &q.Account.Rubric.Checks, nil
216210
}
217211

0 commit comments

Comments
 (0)