Files
genqlient/generate/testdata/queries/InterfaceNoFragments.graphql.go
T
2021-04-21 18:07:36 -07:00

127 lines
3.1 KiB
Go

package test
// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
import (
"encoding/json"
"github.com/Khan/genqlient/graphql"
"github.com/me/mypkg"
)
// InterfaceNoFragmentsQueryResponse is returned by InterfaceNoFragmentsQuery on success.
type InterfaceNoFragmentsQueryResponse struct {
Root InterfaceNoFragmentsQueryRootTopic `json:"root"`
}
type InterfaceNoFragmentsQueryRootTopic struct {
// ID is documented in the Content interface.
Id mypkg.ID `json:"id"`
Name string `json:"name"`
Children []InterfaceNoFragmentsQueryRootTopicChildrenContent `json:"-"`
}
func (v *InterfaceNoFragmentsQueryRootTopic) UnmarshalJSON(b []byte) error {
var firstPass struct {
*InterfaceNoFragmentsQueryRootTopic
Children json.RawMessage `json:"children"`
}
firstPass.InterfaceNoFragmentsQueryRootTopic = v
err := json.Unmarshal(b, &firstPass)
if err != nil {
return err
}
var tn struct {
TypeName string `json:"__typename"`
}
err = json.Unmarshal(firstPass.Children, &tn)
if err != nil {
return err
}
switch tn.TypeName {
case "Article":
v.Children = InterfaceNoFragmentsQueryRootTopicChildrenArticle{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Video":
v.Children = InterfaceNoFragmentsQueryRootTopicChildrenVideo{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Topic":
v.Children = InterfaceNoFragmentsQueryRootTopicChildrenTopic{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
}
if err != nil {
return err
}
return nil
}
type InterfaceNoFragmentsQueryRootTopicChildrenArticle struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
Name string `json:"name"`
}
func (v InterfaceNoFragmentsQueryRootTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent() {
}
// Content is implemented by various types like Article, Video, and Topic.
type InterfaceNoFragmentsQueryRootTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent()
}
type InterfaceNoFragmentsQueryRootTopicChildrenTopic struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
Name string `json:"name"`
}
func (v InterfaceNoFragmentsQueryRootTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent() {
}
type InterfaceNoFragmentsQueryRootTopicChildrenVideo struct {
// ID is the identifier of the content.
Id mypkg.ID `json:"id"`
Name string `json:"name"`
}
func (v InterfaceNoFragmentsQueryRootTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNoFragmentsQueryRootTopicChildrenContent() {
}
func InterfaceNoFragmentsQuery(
client graphql.Client,
) (*InterfaceNoFragmentsQueryResponse, error) {
var retval InterfaceNoFragmentsQueryResponse
err := client.MakeRequest(
nil,
"InterfaceNoFragmentsQuery",
`
query InterfaceNoFragmentsQuery {
root {
id
name
children {
id
name
}
}
}
`,
&retval,
nil,
)
return &retval, err
}