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:
+14
-14
@@ -220,8 +220,8 @@ func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle
|
||||
//
|
||||
// StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent is implemented by the following types:
|
||||
// StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle
|
||||
// StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo
|
||||
// StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic
|
||||
// StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo
|
||||
// The GraphQL type's documentation follows.
|
||||
//
|
||||
// Content is implemented by various types like Article, Video, and Topic.
|
||||
@@ -238,10 +238,10 @@ type StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent int
|
||||
|
||||
func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() {
|
||||
}
|
||||
func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() {
|
||||
}
|
||||
func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() {
|
||||
}
|
||||
func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() {
|
||||
}
|
||||
|
||||
func __unmarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent(b []byte, v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent) error {
|
||||
if string(b) == "null" {
|
||||
@@ -260,12 +260,12 @@ func __unmarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildren
|
||||
case "Article":
|
||||
*v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "Video":
|
||||
*v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "Topic":
|
||||
*v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "Video":
|
||||
*v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "":
|
||||
return fmt.Errorf(
|
||||
"response was missing Content.__typename")
|
||||
@@ -287,6 +287,14 @@ func __marshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenCo
|
||||
*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle
|
||||
}{typename, v}
|
||||
return json.Marshal(result)
|
||||
case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic:
|
||||
typename = "Topic"
|
||||
|
||||
result := struct {
|
||||
TypeName string `json:"__typename"`
|
||||
*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic
|
||||
}{typename, v}
|
||||
return json.Marshal(result)
|
||||
case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo:
|
||||
typename = "Video"
|
||||
|
||||
@@ -299,14 +307,6 @@ func __marshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenCo
|
||||
*__premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo
|
||||
}{typename, premarshaled}
|
||||
return json.Marshal(result)
|
||||
case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic:
|
||||
typename = "Topic"
|
||||
|
||||
result := struct {
|
||||
TypeName string `json:"__typename"`
|
||||
*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic
|
||||
}{typename, v}
|
||||
return json.Marshal(result)
|
||||
case nil:
|
||||
return []byte("null"), nil
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user