Make output deterministic for graphql interfaces (#209)

We noticed that the output from genqlient can be non-deterministic
when a graphql query queries a field that's an interface. This PR
fixes that by sorting the types as soon as we extract them from
the schema.
This commit is contained in:
Viktor Stanchev
2022-07-28 16:19:53 -07:00
committed by GitHub
parent 03b6b6b5d1
commit 2ae8ea42e5
14 changed files with 529 additions and 524 deletions
@@ -145,8 +145,8 @@ func (v *InterfaceListFieldRootTopicChildrenArticle) GetName() string { return v
//
// InterfaceListFieldRootTopicChildrenContent is implemented by the following types:
// InterfaceListFieldRootTopicChildrenArticle
// InterfaceListFieldRootTopicChildrenVideo
// InterfaceListFieldRootTopicChildrenTopic
// InterfaceListFieldRootTopicChildrenVideo
// The GraphQL type's documentation follows.
//
// Content is implemented by various types like Article, Video, and Topic.
@@ -165,10 +165,10 @@ type InterfaceListFieldRootTopicChildrenContent interface {
func (v *InterfaceListFieldRootTopicChildrenArticle) implementsGraphQLInterfaceInterfaceListFieldRootTopicChildrenContent() {
}
func (v *InterfaceListFieldRootTopicChildrenVideo) implementsGraphQLInterfaceInterfaceListFieldRootTopicChildrenContent() {
}
func (v *InterfaceListFieldRootTopicChildrenTopic) implementsGraphQLInterfaceInterfaceListFieldRootTopicChildrenContent() {
}
func (v *InterfaceListFieldRootTopicChildrenVideo) implementsGraphQLInterfaceInterfaceListFieldRootTopicChildrenContent() {
}
func __unmarshalInterfaceListFieldRootTopicChildrenContent(b []byte, v *InterfaceListFieldRootTopicChildrenContent) error {
if string(b) == "null" {
@@ -187,12 +187,12 @@ func __unmarshalInterfaceListFieldRootTopicChildrenContent(b []byte, v *Interfac
case "Article":
*v = new(InterfaceListFieldRootTopicChildrenArticle)
return json.Unmarshal(b, *v)
case "Video":
*v = new(InterfaceListFieldRootTopicChildrenVideo)
return json.Unmarshal(b, *v)
case "Topic":
*v = new(InterfaceListFieldRootTopicChildrenTopic)
return json.Unmarshal(b, *v)
case "Video":
*v = new(InterfaceListFieldRootTopicChildrenVideo)
return json.Unmarshal(b, *v)
case "":
return fmt.Errorf(
"response was missing Content.__typename")
@@ -214,14 +214,6 @@ func __marshalInterfaceListFieldRootTopicChildrenContent(v *InterfaceListFieldRo
*InterfaceListFieldRootTopicChildrenArticle
}{typename, v}
return json.Marshal(result)
case *InterfaceListFieldRootTopicChildrenVideo:
typename = "Video"
result := struct {
TypeName string `json:"__typename"`
*InterfaceListFieldRootTopicChildrenVideo
}{typename, v}
return json.Marshal(result)
case *InterfaceListFieldRootTopicChildrenTopic:
typename = "Topic"
@@ -230,6 +222,14 @@ func __marshalInterfaceListFieldRootTopicChildrenContent(v *InterfaceListFieldRo
*InterfaceListFieldRootTopicChildrenTopic
}{typename, v}
return json.Marshal(result)
case *InterfaceListFieldRootTopicChildrenVideo:
typename = "Video"
result := struct {
TypeName string `json:"__typename"`
*InterfaceListFieldRootTopicChildrenVideo
}{typename, v}
return json.Marshal(result)
case nil:
return []byte("null"), nil
default:
@@ -393,8 +393,8 @@ func (v *InterfaceListFieldWithPointerTopicChildrenArticle) GetName() string { r
//
// InterfaceListFieldWithPointerTopicChildrenContent is implemented by the following types:
// InterfaceListFieldWithPointerTopicChildrenArticle
// InterfaceListFieldWithPointerTopicChildrenVideo
// InterfaceListFieldWithPointerTopicChildrenTopic
// InterfaceListFieldWithPointerTopicChildrenVideo
// The GraphQL type's documentation follows.
//
// Content is implemented by various types like Article, Video, and Topic.
@@ -413,10 +413,10 @@ type InterfaceListFieldWithPointerTopicChildrenContent interface {
func (v *InterfaceListFieldWithPointerTopicChildrenArticle) implementsGraphQLInterfaceInterfaceListFieldWithPointerTopicChildrenContent() {
}
func (v *InterfaceListFieldWithPointerTopicChildrenVideo) implementsGraphQLInterfaceInterfaceListFieldWithPointerTopicChildrenContent() {
}
func (v *InterfaceListFieldWithPointerTopicChildrenTopic) implementsGraphQLInterfaceInterfaceListFieldWithPointerTopicChildrenContent() {
}
func (v *InterfaceListFieldWithPointerTopicChildrenVideo) implementsGraphQLInterfaceInterfaceListFieldWithPointerTopicChildrenContent() {
}
func __unmarshalInterfaceListFieldWithPointerTopicChildrenContent(b []byte, v *InterfaceListFieldWithPointerTopicChildrenContent) error {
if string(b) == "null" {
@@ -435,12 +435,12 @@ func __unmarshalInterfaceListFieldWithPointerTopicChildrenContent(b []byte, v *I
case "Article":
*v = new(InterfaceListFieldWithPointerTopicChildrenArticle)
return json.Unmarshal(b, *v)
case "Video":
*v = new(InterfaceListFieldWithPointerTopicChildrenVideo)
return json.Unmarshal(b, *v)
case "Topic":
*v = new(InterfaceListFieldWithPointerTopicChildrenTopic)
return json.Unmarshal(b, *v)
case "Video":
*v = new(InterfaceListFieldWithPointerTopicChildrenVideo)
return json.Unmarshal(b, *v)
case "":
return fmt.Errorf(
"response was missing Content.__typename")
@@ -462,14 +462,6 @@ func __marshalInterfaceListFieldWithPointerTopicChildrenContent(v *InterfaceList
*InterfaceListFieldWithPointerTopicChildrenArticle
}{typename, v}
return json.Marshal(result)
case *InterfaceListFieldWithPointerTopicChildrenVideo:
typename = "Video"
result := struct {
TypeName string `json:"__typename"`
*InterfaceListFieldWithPointerTopicChildrenVideo
}{typename, v}
return json.Marshal(result)
case *InterfaceListFieldWithPointerTopicChildrenTopic:
typename = "Topic"
@@ -478,6 +470,14 @@ func __marshalInterfaceListFieldWithPointerTopicChildrenContent(v *InterfaceList
*InterfaceListFieldWithPointerTopicChildrenTopic
}{typename, v}
return json.Marshal(result)
case *InterfaceListFieldWithPointerTopicChildrenVideo:
typename = "Video"
result := struct {
TypeName string `json:"__typename"`
*InterfaceListFieldWithPointerTopicChildrenVideo
}{typename, v}
return json.Marshal(result)
case nil:
return []byte("null"), nil
default: