chore: handle push of unchanged schema
This commit is contained in:
+10
-6
@@ -1,9 +1,13 @@
|
||||
query SubGraphs($ref: String!) {
|
||||
subGraphs(ref: $ref) {
|
||||
service
|
||||
url
|
||||
wsUrl
|
||||
changedBy
|
||||
changedAt
|
||||
supergraph(ref: $ref) {
|
||||
... on SubGraphs {
|
||||
subGraphs {
|
||||
service
|
||||
url
|
||||
wsUrl
|
||||
changedBy
|
||||
changedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-9
@@ -2,6 +2,7 @@ package ctl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
@@ -47,15 +48,19 @@ func List(apiKey, schemaRef, service string, schemasUrl url.URL) ([]*SubGraph, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subGraphs := make([]*SubGraph, len(response.SubGraphs))
|
||||
for i, subGraph := range response.SubGraphs {
|
||||
subGraphs[i] = &SubGraph{
|
||||
Service: subGraph.Service,
|
||||
URL: subGraph.Url,
|
||||
WSUrl: subGraph.WsUrl,
|
||||
ChangedBy: subGraph.ChangedBy,
|
||||
ChangedAt: subGraph.ChangedAt,
|
||||
var subGraphs []*SubGraph
|
||||
if s, ok := response.Supergraph.(*SubGraphsSupergraphSubGraphs); ok {
|
||||
subGraphs = make([]*SubGraph, len(s.SubGraphs))
|
||||
for i, subGraph := range s.SubGraphs {
|
||||
subGraphs[i] = &SubGraph{
|
||||
Service: subGraph.Service,
|
||||
URL: subGraph.Url,
|
||||
WSUrl: subGraph.WsUrl,
|
||||
ChangedBy: subGraph.ChangedBy,
|
||||
ChangedAt: subGraph.ChangedAt,
|
||||
}
|
||||
}
|
||||
return subGraphs, nil
|
||||
}
|
||||
return subGraphs, nil
|
||||
return nil, fmt.Errorf("unexpected response type")
|
||||
}
|
||||
|
||||
+182
-21
@@ -4,6 +4,8 @@ package ctl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
@@ -34,14 +36,160 @@ func (v *InputSubGraph) GetSdl() string { return v.Sdl }
|
||||
|
||||
// SubGraphsResponse is returned by SubGraphs on success.
|
||||
type SubGraphsResponse struct {
|
||||
SubGraphs []*SubGraphsSubGraphsSubGraph `json:"subGraphs"`
|
||||
Supergraph SubGraphsSupergraph `json:"-"`
|
||||
}
|
||||
|
||||
// GetSubGraphs returns SubGraphsResponse.SubGraphs, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsResponse) GetSubGraphs() []*SubGraphsSubGraphsSubGraph { return v.SubGraphs }
|
||||
// GetSupergraph returns SubGraphsResponse.Supergraph, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsResponse) GetSupergraph() SubGraphsSupergraph { return v.Supergraph }
|
||||
|
||||
// SubGraphsSubGraphsSubGraph includes the requested fields of the GraphQL type SubGraph.
|
||||
type SubGraphsSubGraphsSubGraph struct {
|
||||
func (v *SubGraphsResponse) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var firstPass struct {
|
||||
*SubGraphsResponse
|
||||
Supergraph json.RawMessage `json:"supergraph"`
|
||||
graphql.NoUnmarshalJSON
|
||||
}
|
||||
firstPass.SubGraphsResponse = v
|
||||
|
||||
err := json.Unmarshal(b, &firstPass)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
{
|
||||
dst := &v.Supergraph
|
||||
src := firstPass.Supergraph
|
||||
if len(src) != 0 && string(src) != "null" {
|
||||
err = __unmarshalSubGraphsSupergraph(
|
||||
src, dst)
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"unable to unmarshal SubGraphsResponse.Supergraph: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type __premarshalSubGraphsResponse struct {
|
||||
Supergraph json.RawMessage `json:"supergraph"`
|
||||
}
|
||||
|
||||
func (v *SubGraphsResponse) MarshalJSON() ([]byte, error) {
|
||||
premarshaled, err := v.__premarshalJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return json.Marshal(premarshaled)
|
||||
}
|
||||
|
||||
func (v *SubGraphsResponse) __premarshalJSON() (*__premarshalSubGraphsResponse, error) {
|
||||
var retval __premarshalSubGraphsResponse
|
||||
|
||||
{
|
||||
|
||||
dst := &retval.Supergraph
|
||||
src := v.Supergraph
|
||||
var err error
|
||||
*dst, err = __marshalSubGraphsSupergraph(
|
||||
&src)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"unable to marshal SubGraphsResponse.Supergraph: %w", err)
|
||||
}
|
||||
}
|
||||
return &retval, nil
|
||||
}
|
||||
|
||||
// SubGraphsSupergraph includes the requested fields of the GraphQL interface Supergraph.
|
||||
//
|
||||
// SubGraphsSupergraph is implemented by the following types:
|
||||
// SubGraphsSupergraphSubGraphs
|
||||
// SubGraphsSupergraphUnchanged
|
||||
type SubGraphsSupergraph interface {
|
||||
implementsGraphQLInterfaceSubGraphsSupergraph()
|
||||
// GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values).
|
||||
GetTypename() *string
|
||||
}
|
||||
|
||||
func (v *SubGraphsSupergraphSubGraphs) implementsGraphQLInterfaceSubGraphsSupergraph() {}
|
||||
func (v *SubGraphsSupergraphUnchanged) implementsGraphQLInterfaceSubGraphsSupergraph() {}
|
||||
|
||||
func __unmarshalSubGraphsSupergraph(b []byte, v *SubGraphsSupergraph) error {
|
||||
if string(b) == "null" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var tn struct {
|
||||
TypeName string `json:"__typename"`
|
||||
}
|
||||
err := json.Unmarshal(b, &tn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch tn.TypeName {
|
||||
case "SubGraphs":
|
||||
*v = new(SubGraphsSupergraphSubGraphs)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "Unchanged":
|
||||
*v = new(SubGraphsSupergraphUnchanged)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "":
|
||||
return fmt.Errorf(
|
||||
"response was missing Supergraph.__typename")
|
||||
default:
|
||||
return fmt.Errorf(
|
||||
`unexpected concrete type for SubGraphsSupergraph: "%v"`, tn.TypeName)
|
||||
}
|
||||
}
|
||||
|
||||
func __marshalSubGraphsSupergraph(v *SubGraphsSupergraph) ([]byte, error) {
|
||||
var typename string
|
||||
switch v := (*v).(type) {
|
||||
case *SubGraphsSupergraphSubGraphs:
|
||||
typename = "SubGraphs"
|
||||
|
||||
result := struct {
|
||||
TypeName string `json:"__typename"`
|
||||
*SubGraphsSupergraphSubGraphs
|
||||
}{typename, v}
|
||||
return json.Marshal(result)
|
||||
case *SubGraphsSupergraphUnchanged:
|
||||
typename = "Unchanged"
|
||||
|
||||
result := struct {
|
||||
TypeName string `json:"__typename"`
|
||||
*SubGraphsSupergraphUnchanged
|
||||
}{typename, v}
|
||||
return json.Marshal(result)
|
||||
case nil:
|
||||
return []byte("null"), nil
|
||||
default:
|
||||
return nil, fmt.Errorf(
|
||||
`unexpected concrete type for SubGraphsSupergraph: "%T"`, v)
|
||||
}
|
||||
}
|
||||
|
||||
// SubGraphsSupergraphSubGraphs includes the requested fields of the GraphQL type SubGraphs.
|
||||
type SubGraphsSupergraphSubGraphs struct {
|
||||
Typename *string `json:"__typename"`
|
||||
SubGraphs []*SubGraphsSupergraphSubGraphsSubGraphsSubGraph `json:"subGraphs"`
|
||||
}
|
||||
|
||||
// GetTypename returns SubGraphsSupergraphSubGraphs.Typename, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSupergraphSubGraphs) GetTypename() *string { return v.Typename }
|
||||
|
||||
// GetSubGraphs returns SubGraphsSupergraphSubGraphs.SubGraphs, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSupergraphSubGraphs) GetSubGraphs() []*SubGraphsSupergraphSubGraphsSubGraphsSubGraph {
|
||||
return v.SubGraphs
|
||||
}
|
||||
|
||||
// SubGraphsSupergraphSubGraphsSubGraphsSubGraph includes the requested fields of the GraphQL type SubGraph.
|
||||
type SubGraphsSupergraphSubGraphsSubGraphsSubGraph struct {
|
||||
Service string `json:"service"`
|
||||
Url *string `json:"url"`
|
||||
WsUrl *string `json:"wsUrl"`
|
||||
@@ -49,20 +197,28 @@ type SubGraphsSubGraphsSubGraph struct {
|
||||
ChangedAt time.Time `json:"changedAt"`
|
||||
}
|
||||
|
||||
// GetService returns SubGraphsSubGraphsSubGraph.Service, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSubGraphsSubGraph) GetService() string { return v.Service }
|
||||
// GetService returns SubGraphsSupergraphSubGraphsSubGraphsSubGraph.Service, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSupergraphSubGraphsSubGraphsSubGraph) GetService() string { return v.Service }
|
||||
|
||||
// GetUrl returns SubGraphsSubGraphsSubGraph.Url, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSubGraphsSubGraph) GetUrl() *string { return v.Url }
|
||||
// GetUrl returns SubGraphsSupergraphSubGraphsSubGraphsSubGraph.Url, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSupergraphSubGraphsSubGraphsSubGraph) GetUrl() *string { return v.Url }
|
||||
|
||||
// GetWsUrl returns SubGraphsSubGraphsSubGraph.WsUrl, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSubGraphsSubGraph) GetWsUrl() *string { return v.WsUrl }
|
||||
// GetWsUrl returns SubGraphsSupergraphSubGraphsSubGraphsSubGraph.WsUrl, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSupergraphSubGraphsSubGraphsSubGraph) GetWsUrl() *string { return v.WsUrl }
|
||||
|
||||
// GetChangedBy returns SubGraphsSubGraphsSubGraph.ChangedBy, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSubGraphsSubGraph) GetChangedBy() string { return v.ChangedBy }
|
||||
// GetChangedBy returns SubGraphsSupergraphSubGraphsSubGraphsSubGraph.ChangedBy, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSupergraphSubGraphsSubGraphsSubGraph) GetChangedBy() string { return v.ChangedBy }
|
||||
|
||||
// GetChangedAt returns SubGraphsSubGraphsSubGraph.ChangedAt, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSubGraphsSubGraph) GetChangedAt() time.Time { return v.ChangedAt }
|
||||
// GetChangedAt returns SubGraphsSupergraphSubGraphsSubGraphsSubGraph.ChangedAt, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSupergraphSubGraphsSubGraphsSubGraph) GetChangedAt() time.Time { return v.ChangedAt }
|
||||
|
||||
// SubGraphsSupergraphUnchanged includes the requested fields of the GraphQL type Unchanged.
|
||||
type SubGraphsSupergraphUnchanged struct {
|
||||
Typename *string `json:"__typename"`
|
||||
}
|
||||
|
||||
// GetTypename returns SubGraphsSupergraphUnchanged.Typename, and is useful for accessing the field via an interface.
|
||||
func (v *SubGraphsSupergraphUnchanged) GetTypename() *string { return v.Typename }
|
||||
|
||||
// UpdateSubGraphResponse is returned by UpdateSubGraph on success.
|
||||
type UpdateSubGraphResponse struct {
|
||||
@@ -123,12 +279,17 @@ func SubGraphs(
|
||||
OpName: "SubGraphs",
|
||||
Query: `
|
||||
query SubGraphs ($ref: String!) {
|
||||
subGraphs(ref: $ref) {
|
||||
service
|
||||
url
|
||||
wsUrl
|
||||
changedBy
|
||||
changedAt
|
||||
supergraph(ref: $ref) {
|
||||
__typename
|
||||
... on SubGraphs {
|
||||
subGraphs {
|
||||
service
|
||||
url
|
||||
wsUrl
|
||||
changedBy
|
||||
changedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
|
||||
Reference in New Issue
Block a user