add a test with a pile of nested interfaces

This commit is contained in:
Ben Kraft
2021-04-15 18:46:24 -07:00
parent 89fe78e11a
commit 234c683e21
3 changed files with 377 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
query InterfaceNesting {
root {
id
children {
id
parent {
id
children {
id
}
}
}
}
}
+354
View File
@@ -0,0 +1,354 @@
package test
// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
import (
"encoding/json"
"github.com/Khan/genqlient/graphql"
"github.com/me/mypkg"
)
type InterfaceNestingResponse struct {
Root InterfaceNestingRootTopic `json:"root"`
}
type InterfaceNestingRootTopic struct {
Id mypkg.ID `json:"id"`
Children []InterfaceNestingRootTopicChildrenContent `json:"-"`
}
func (v *InterfaceNestingRootTopic) UnmarshalJSON(b []byte) error {
var firstPass struct {
*InterfaceNestingRootTopic
Children json.RawMessage `json:"children"`
}
firstPass.InterfaceNestingRootTopic = 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 = InterfaceNestingRootTopicChildrenArticle{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Video":
v.Children = InterfaceNestingRootTopicChildrenVideo{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Topic":
v.Children = InterfaceNestingRootTopicChildrenTopic{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
}
if err != nil {
return err
}
return nil
}
type InterfaceNestingRootTopicChildrenArticle struct {
Id mypkg.ID `json:"id"`
Parent InterfaceNestingRootTopicChildrenArticleParentTopic `json:"parent"`
}
func (v InterfaceNestingRootTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenArticleParentTopic struct {
Id mypkg.ID `json:"id"`
Children []InterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent `json:"-"`
}
func (v *InterfaceNestingRootTopicChildrenArticleParentTopic) UnmarshalJSON(b []byte) error {
var firstPass struct {
*InterfaceNestingRootTopicChildrenArticleParentTopic
Children json.RawMessage `json:"children"`
}
firstPass.InterfaceNestingRootTopicChildrenArticleParentTopic = 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 = InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Video":
v.Children = InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Topic":
v.Children = InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
}
if err != nil {
return err
}
return nil
}
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent()
}
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenArticleParentTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenArticleParentTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent()
}
type InterfaceNestingRootTopicChildrenTopic struct {
Id mypkg.ID `json:"id"`
Parent InterfaceNestingRootTopicChildrenTopicParentTopic `json:"parent"`
}
func (v InterfaceNestingRootTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenTopicParentTopic struct {
Id mypkg.ID `json:"id"`
Children []InterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent `json:"-"`
}
func (v *InterfaceNestingRootTopicChildrenTopicParentTopic) UnmarshalJSON(b []byte) error {
var firstPass struct {
*InterfaceNestingRootTopicChildrenTopicParentTopic
Children json.RawMessage `json:"children"`
}
firstPass.InterfaceNestingRootTopicChildrenTopicParentTopic = 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 = InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Video":
v.Children = InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Topic":
v.Children = InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
}
if err != nil {
return err
}
return nil
}
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent()
}
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenTopicParentTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenTopicParentTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenVideo struct {
Id mypkg.ID `json:"id"`
Parent InterfaceNestingRootTopicChildrenVideoParentTopic `json:"parent"`
}
func (v InterfaceNestingRootTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenVideoParentTopic struct {
Id mypkg.ID `json:"id"`
Children []InterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent `json:"-"`
}
func (v *InterfaceNestingRootTopicChildrenVideoParentTopic) UnmarshalJSON(b []byte) error {
var firstPass struct {
*InterfaceNestingRootTopicChildrenVideoParentTopic
Children json.RawMessage `json:"children"`
}
firstPass.InterfaceNestingRootTopicChildrenVideoParentTopic = 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 = InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Video":
v.Children = InterfaceNestingRootTopicChildrenVideoParentTopicChildrenVideo{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
case "Topic":
v.Children = InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic{}
err = json.Unmarshal(
firstPass.Children, &v.Children)
}
if err != nil {
return err
}
return nil
}
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenVideoParentTopicChildrenArticle) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent interface {
implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent()
}
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenVideoParentTopicChildrenTopic) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent() {
}
type InterfaceNestingRootTopicChildrenVideoParentTopicChildrenVideo struct {
Id mypkg.ID `json:"id"`
}
func (v InterfaceNestingRootTopicChildrenVideoParentTopicChildrenVideo) implementsGraphQLInterfaceInterfaceNestingRootTopicChildrenVideoParentTopicChildrenContent() {
}
func InterfaceNesting(
client graphql.Client,
) (*InterfaceNestingResponse, error) {
var retval InterfaceNestingResponse
err := client.MakeRequest(
nil,
"InterfaceNesting",
`
query InterfaceNesting {
root {
id
children {
id
parent {
id
children {
id
}
}
}
}
}
`,
&retval,
nil,
)
return &retval, err
}
@@ -0,0 +1,9 @@
{
"operations": [
{
"operationName": "InterfaceNesting",
"query": "\nquery InterfaceNesting {\n\troot {\n\t\tid\n\t\tchildren {\n\t\t\tid\n\t\t\tparent {\n\t\t\t\tid\n\t\t\t\tchildren {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n",
"sourceLocation": "testdata/queries/InterfaceNesting.graphql"
}
]
}