Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Gen v2 #509

Merged
merged 10 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
generate Go structs of graphql API objects (#499)
* generate Go structs of graphql API objects

* temp limit objects generated, add mapping for field types

* generate first objects, update tests

* generate most objects starting with A-C, update tests
davidbloss authored and rocktavious committed Jan 28, 2025
commit 1fe42e77b085e0373669dbc95c3e5f22d278789a
16 changes: 0 additions & 16 deletions actions.go
Original file line number Diff line number Diff line change
@@ -15,22 +15,6 @@ type CustomActionsWebhookAction struct {
WebhookURL string `graphql:"webhookUrl"`
}

type CustomActionsTriggerDefinition struct {
Action CustomActionsId `graphql:"action"`
Aliases []string `graphql:"aliases"`
Description string `graphql:"description"`
Filter FilterId `graphql:"filter"`
Id ID `graphql:"id"`
ManualInputsDefinition string `graphql:"manualInputsDefinition"`
Name string `graphql:"name"`
Owner TeamId `graphql:"owner"`
Published bool `graphql:"published"`
Timestamps Timestamps `graphql:"timestamps"`
AccessControl CustomActionsTriggerDefinitionAccessControlEnum `graphql:"accessControl"`
ResponseTemplate string `graphql:"responseTemplate"`
EntityType CustomActionsEntityTypeEnum `graphql:"entityType"`
}

func (customActionsTriggerDefinition *CustomActionsTriggerDefinition) ExtendedTeamAccess(client *Client, variables *PayloadVariables) (*TeamConnection, error) {
var q struct {
Account struct {
4 changes: 2 additions & 2 deletions actions_test.go
Original file line number Diff line number Diff line change
@@ -224,12 +224,12 @@ func TestGetTriggerDefinition(t *testing.T) {
func TestListTriggerDefinitions(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query TriggerDefinitionList($after:String!$first:Int!){account{customActionsTriggerDefinitions(after: $after, first: $first){nodes{action{aliases,id},aliases,description,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,timestamps{createdAt,updatedAt},accessControl,responseTemplate,entityType},{{ template "pagination_request" }},totalCount}}}`,
`query TriggerDefinitionList($after:String!$first:Int!){account{customActionsTriggerDefinitions(after: $after, first: $first){nodes{accessControl,action{aliases,id},aliases,description,entityType,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,responseTemplate,timestamps{createdAt,updatedAt}},{{ template "pagination_request" }},totalCount}}}`,
`{{ template "pagination_initial_query_variables" }}`,
`{ "data": { "account": { "customActionsTriggerDefinitions": { "nodes": [ { {{ template "custom_action_trigger1_response" }} }, { {{ template "custom_action_trigger2_response" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query TriggerDefinitionList($after:String!$first:Int!){account{customActionsTriggerDefinitions(after: $after, first: $first){nodes{action{aliases,id},aliases,description,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,timestamps{createdAt,updatedAt},accessControl,responseTemplate,entityType},{{ template "pagination_request" }},totalCount}}}`,
`query TriggerDefinitionList($after:String!$first:Int!){account{customActionsTriggerDefinitions(after: $after, first: $first){nodes{accessControl,action{aliases,id},aliases,description,entityType,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,responseTemplate,timestamps{createdAt,updatedAt}},{{ template "pagination_request" }},totalCount}}}`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "customActionsTriggerDefinitions": { "nodes": [ { {{ template "custom_action_trigger3_response" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}`,
)
17 changes: 0 additions & 17 deletions alert_source.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
package opslevel

type AlertSource struct {
Description string `graphql:"description"`
ExternalId string `graphql:"externalId"`
Id ID `graphql:"id"`
Integration IntegrationId `graphql:"integration"`
Name string `graphql:"name"`
Type AlertSourceTypeEnum `graphql:"type"`
Url string `graphql:"url"`
}

type AlertSourceService struct {
AlertSource AlertSource `graphql:"alertSource"`
Id ID `graphql:"id"`
Service ServiceId `graphql:"service"`
Status AlertSourceStatusTypeEnum `graphql:"status"`
}

type AlertSourceDeleteInput struct {
Id ID `json:"id"`
}
6 changes: 3 additions & 3 deletions alert_source_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
func TestCreateAlertSourceService(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation AlertSourceServiceCreate($input:AlertSourceServiceCreateInput!){alertSourceServiceCreate(input: $input){alertSourceService{alertSource{description,externalId,id,integration{id,name,type},name,type,url},id,service{id,aliases},status},errors{message,path}}}`,
`mutation AlertSourceServiceCreate($input:AlertSourceServiceCreateInput!){alertSourceServiceCreate(input: $input){alertSourceService{alertSource{description,externalId,id,integration{id,name,type},metadata,name,type,url},id,service{id,aliases},status},errors{message,path}}}`,
`{"input": { "alertSourceExternalIdentifier": { "externalId": "QWERTY", "type": "datadog" }, "service": { "alias": "example" }}}`,
`{"data": { "alertSourceServiceCreate": { "alertSourceService": { "service": { "aliases": ["example"] }}}}}`,
)
@@ -28,7 +28,7 @@ func TestCreateAlertSourceService(t *testing.T) {
func TestGetAlertSourceWithExternalIdentifier(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query AlertSourceGet($externalIdentifier:AlertSourceExternalIdentifier!){account{alertSource(externalIdentifier: $externalIdentifier){description,externalId,id,integration{id,name,type},name,type,url}}}`,
`query AlertSourceGet($externalIdentifier:AlertSourceExternalIdentifier!){account{alertSource(externalIdentifier: $externalIdentifier){description,externalId,id,integration{id,name,type},metadata,name,type,url}}}`,
`{"externalIdentifier": { "type": "datadog", "externalId": "12345678" }}`,
`{"data": {
"account": {
@@ -64,7 +64,7 @@ func TestGetAlertSourceWithExternalIdentifier(t *testing.T) {
func TestGetAlertSource(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query AlertSourceGet($id:ID!){account{alertSource(id: $id){description,externalId,id,integration{id,name,type},name,type,url}}}`,
`query AlertSourceGet($id:ID!){account{alertSource(id: $id){description,externalId,id,integration{id,name,type},metadata,name,type,url}}}`,
`{"id": "Z2lkOi8vb3BzbGV2ZWwvQWxlcnRTb3VyY2VzOjpQYWdlcmR1dHkvNjE" }`,
`{"data": {
"account": {
2 changes: 1 addition & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ func TestCache(t *testing.T) {
`{"data":{"account":{ "teams":{ "nodes":[{{ template "team_1" }}] } }}}`,
)
testRequestFive := autopilot.NewTestRequest(
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},{{ template "pagination_request" }},totalCount}}}}`,
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }},totalCount}}}}`,
`{ "after": "", "first": 100 }`,
`{"data":{"account":{"rubric":{ "categories":{ "nodes":[{{ template "category_1" }}] } }}}}`,
)
5 changes: 0 additions & 5 deletions category.go
Original file line number Diff line number Diff line change
@@ -7,11 +7,6 @@ import (
"github.com/hasura/go-graphql-client"
)

type Category struct {
Id ID `json:"id"`
Name string
}

type CategoryConnection struct {
Nodes []Category
PageInfo PageInfo
12 changes: 6 additions & 6 deletions category_test.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
func TestCreateRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation CategoryCreate($input:CategoryCreateInput!){categoryCreate(input: $input){category{id,name},errors{message,path}}}`,
`mutation CategoryCreate($input:CategoryCreateInput!){categoryCreate(input: $input){category{description,id,name},errors{message,path}}}`,
`{ "input": { "name": "Kyle" }}`,
`{"data": { "categoryCreate": { "category": { {{ template "id1" }}, "name": "Kyle" }, "errors": [] } }}`,
)
@@ -27,7 +27,7 @@ func TestCreateRubricCategory(t *testing.T) {
func TestGetRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query CategoryGet($id:ID!){account{category(id: $id){id,name}}}`,
`query CategoryGet($id:ID!){account{category(id: $id){description,id,name}}}`,
`{ {{ template "id2" }} }`,
`{"data": { "account": { "category": { {{ template "id3" }}, "name": "Reliability" } }}}`,
)
@@ -43,7 +43,7 @@ func TestGetRubricCategory(t *testing.T) {
func TestGetMissingRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query CategoryGet($id:ID!){account{category(id: $id){id,name}}}`,
`query CategoryGet($id:ID!){account{category(id: $id){description,id,name}}}`,
`{ {{ template "id1" }} }`,
`{"data": { "account": { "category": null }}}`,
)
@@ -57,12 +57,12 @@ func TestGetMissingRubricCategory(t *testing.T) {
func TestListRubricCategories(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},{{ template "pagination_request" }},totalCount}}}}`,
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }},totalCount}}}}`,
`{{ template "pagination_initial_query_variables" }}`,
`{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response1" }} }, { {{ template "rubric_categories_response2" }} } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 2 }}}}}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{id,name},{{ template "pagination_request" }},totalCount}}}}`,
`query CategoryList($after:String!$first:Int!){account{rubric{categories(after: $after, first: $first){nodes{description,id,name},{{ template "pagination_request" }},totalCount}}}}`,
`{{ template "pagination_second_query_variables" }}`,
`{ "data": { "account": { "rubric": { "categories": { "nodes": [ { {{ template "rubric_categories_response3" }} } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
@@ -85,7 +85,7 @@ func TestListRubricCategories(t *testing.T) {
func TestUpdateRubricCategory(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`mutation CategoryUpdate($input:CategoryUpdateInput!){categoryUpdate(input: $input){category{id,name},errors{message,path}}}`,
`mutation CategoryUpdate($input:CategoryUpdateInput!){categoryUpdate(input: $input){category{description,id,name},errors{message,path}}}`,
`{ "input": { {{ template "id4" }}, "name": "Emily" }}`,
`{"data": { "categoryUpdate": { "category": { {{ template "id4" }}, "name": "Emily" }, "errors": [] }}}`,
)
10 changes: 5 additions & 5 deletions check_test.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions maturity_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
func TestGetServiceMaturityWithAlias(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query ($service:String!){account{service(alias:$service){name,maturityReport{categoryBreakdown{category{id,name},level{alias,description,id,index,name}},overallLevel{alias,description,id,index,name}}}}}`,
`query ($service:String!){account{service(alias:$service){name,maturityReport{categoryBreakdown{category{description,id,name},level{alias,description,id,index,name}},overallLevel{alias,description,id,index,name}}}}}`,
`{"service": "cert-manager"}`,
`{
"data": {
@@ -133,7 +133,7 @@ func TestGetServiceMaturityWithAlias(t *testing.T) {
func TestListServicesMaturity(t *testing.T) {
// Arrange
testRequest := autopilot.NewTestRequest(
`query ServiceMaturityList($after:String!$first:Int!){account{services(after: $after, first: $first){nodes{name,maturityReport{categoryBreakdown{category{id,name},level{alias,description,id,index,name}},overallLevel{alias,description,id,index,name}}},{{ template "pagination_request" }}}}}`,
`query ServiceMaturityList($after:String!$first:Int!){account{services(after: $after, first: $first){nodes{name,maturityReport{categoryBreakdown{category{description,id,name},level{alias,description,id,index,name}},overallLevel{alias,description,id,index,name}}},{{ template "pagination_request" }}}}}`,
`{"after":"", "first":100}`,
`{
"data": {
338 changes: 338 additions & 0 deletions object.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions scorecards_test.go
Original file line number Diff line number Diff line change
@@ -168,12 +168,12 @@ func TestListScorecards(t *testing.T) {
func TestListScorecardCategories(t *testing.T) {
// Arrange
testRequestOne := autopilot.NewTestRequest(
`query ScorecardCategoryList($after:String!$first:Int!$scorecard:IdentifierInput!){account{scorecard(input: $scorecard){categories(after: $after, first: $first){nodes{id,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}`,
`query ScorecardCategoryList($after:String!$first:Int!$scorecard:IdentifierInput!){account{scorecard(input: $scorecard){categories(after: $after, first: $first){nodes{description,id,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}`,
`{ {{ template "first_page_variables" }}, "scorecard": { {{ template "id1" }} } }`,
`{ "data": { "account": { "scorecard": { "categories": { "nodes": [ { {{ template "id2" }}, "name": "quality" } ], {{ template "pagination_initial_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
testRequestTwo := autopilot.NewTestRequest(
`query ScorecardCategoryList($after:String!$first:Int!$scorecard:IdentifierInput!){account{scorecard(input: $scorecard){categories(after: $after, first: $first){nodes{id,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}`,
`query ScorecardCategoryList($after:String!$first:Int!$scorecard:IdentifierInput!){account{scorecard(input: $scorecard){categories(after: $after, first: $first){nodes{description,id,name},pageInfo{hasNextPage,hasPreviousPage,startCursor,endCursor},totalCount}}}}`,
`{ {{ template "second_page_variables" }}, "scorecard": { {{ template "id1" }} } }`,
`{ "data": { "account": { "scorecard": { "categories": { "nodes": [ { {{ template "id3" }}, "name": "ownership" } ], {{ template "pagination_second_pageInfo_response" }}, "totalCount": 1 }}}}}`,
)
9 changes: 9 additions & 0 deletions templates/objects.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- define "objects" }}
// {{.Name | title}} {{.Desc | clean | endSentence}}
type {{.Name}} struct { {{ range .Fields }}
{{- if eq (len .Arguments) 0 }}
{{ title .Name | getFieldNameForObject }} {{ getFieldTypeForObject . | trimPrefix "*" }} `graphql:"{{ .Name }}" json:"{{ .Name }}"
{{- if hasPrefix "JSON" .Type.String }} scalar:"true"{{ end }}` // {{ .Desc | replace "\n" " " }}
{{- end -}}{{- end }}
}
{{- end -}}
2 changes: 1 addition & 1 deletion testdata/templates/custom_actions.tpl
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@
}
{{ end }}
{{- define "custom_actions_request" }}{aliases,id,description,liquidTemplate,name,... on CustomActionsWebhookAction{headers,httpMethod,webhookUrl}}{{ end }}
{{- define "custom_actions_trigger_request" }}{action{aliases,id},aliases,description,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,timestamps{createdAt,updatedAt},accessControl,responseTemplate,entityType}{{ end }}
{{- define "custom_actions_trigger_request" }}{accessControl,action{aliases,id},aliases,description,entityType,filter{id,name},id,manualInputsDefinition,name,owner{alias,id},published,responseTemplate,timestamps{createdAt,updatedAt}}{{ end }}
{{- define "custom_action1" }}{
"aliases": [],
"description": null,