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:
Vendored
+14
-14
@@ -31,8 +31,8 @@ func (v *SimpleNamedFragmentRandomItemArticle) GetName() string { return v.Name
|
||||
//
|
||||
// SimpleNamedFragmentRandomItemContent is implemented by the following types:
|
||||
// SimpleNamedFragmentRandomItemArticle
|
||||
// SimpleNamedFragmentRandomItemVideo
|
||||
// SimpleNamedFragmentRandomItemTopic
|
||||
// SimpleNamedFragmentRandomItemVideo
|
||||
// The GraphQL type's documentation follows.
|
||||
//
|
||||
// Content is implemented by various types like Article, Video, and Topic.
|
||||
@@ -51,10 +51,10 @@ type SimpleNamedFragmentRandomItemContent interface {
|
||||
|
||||
func (v *SimpleNamedFragmentRandomItemArticle) implementsGraphQLInterfaceSimpleNamedFragmentRandomItemContent() {
|
||||
}
|
||||
func (v *SimpleNamedFragmentRandomItemVideo) implementsGraphQLInterfaceSimpleNamedFragmentRandomItemContent() {
|
||||
}
|
||||
func (v *SimpleNamedFragmentRandomItemTopic) implementsGraphQLInterfaceSimpleNamedFragmentRandomItemContent() {
|
||||
}
|
||||
func (v *SimpleNamedFragmentRandomItemVideo) implementsGraphQLInterfaceSimpleNamedFragmentRandomItemContent() {
|
||||
}
|
||||
|
||||
func __unmarshalSimpleNamedFragmentRandomItemContent(b []byte, v *SimpleNamedFragmentRandomItemContent) error {
|
||||
if string(b) == "null" {
|
||||
@@ -73,12 +73,12 @@ func __unmarshalSimpleNamedFragmentRandomItemContent(b []byte, v *SimpleNamedFra
|
||||
case "Article":
|
||||
*v = new(SimpleNamedFragmentRandomItemArticle)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "Video":
|
||||
*v = new(SimpleNamedFragmentRandomItemVideo)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "Topic":
|
||||
*v = new(SimpleNamedFragmentRandomItemTopic)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "Video":
|
||||
*v = new(SimpleNamedFragmentRandomItemVideo)
|
||||
return json.Unmarshal(b, *v)
|
||||
case "":
|
||||
return fmt.Errorf(
|
||||
"response was missing Content.__typename")
|
||||
@@ -100,6 +100,14 @@ func __marshalSimpleNamedFragmentRandomItemContent(v *SimpleNamedFragmentRandomI
|
||||
*SimpleNamedFragmentRandomItemArticle
|
||||
}{typename, v}
|
||||
return json.Marshal(result)
|
||||
case *SimpleNamedFragmentRandomItemTopic:
|
||||
typename = "Topic"
|
||||
|
||||
result := struct {
|
||||
TypeName string `json:"__typename"`
|
||||
*SimpleNamedFragmentRandomItemTopic
|
||||
}{typename, v}
|
||||
return json.Marshal(result)
|
||||
case *SimpleNamedFragmentRandomItemVideo:
|
||||
typename = "Video"
|
||||
|
||||
@@ -112,14 +120,6 @@ func __marshalSimpleNamedFragmentRandomItemContent(v *SimpleNamedFragmentRandomI
|
||||
*__premarshalSimpleNamedFragmentRandomItemVideo
|
||||
}{typename, premarshaled}
|
||||
return json.Marshal(result)
|
||||
case *SimpleNamedFragmentRandomItemTopic:
|
||||
typename = "Topic"
|
||||
|
||||
result := struct {
|
||||
TypeName string `json:"__typename"`
|
||||
*SimpleNamedFragmentRandomItemTopic
|
||||
}{typename, v}
|
||||
return json.Marshal(result)
|
||||
case nil:
|
||||
return []byte("null"), nil
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user