total rewrite to interface handling; not complete but it compiles

This commit is contained in:
Ben Kraft
2020-07-16 13:28:43 -07:00
parent af4a765a32
commit cf7136ca65
33 changed files with 712 additions and 173 deletions
+79
View File
@@ -0,0 +1,79 @@
package test
// Code generated by github.com/Khan/genql, DO NOT EDIT.
import (
"context"
"github.com/Khan/genql/graphql"
)
type Article struct {
Typename *string `json:"__typename"`
}
func (v Article) implementsGraphQLInterfaceLeafContent() {}
type LeafContent interface {
implementsGraphQLInterfaceLeafContent()
}
type UnionNoFragmentsQueryResponse struct {
RandomLeaf LeafContent `json:"-"`
}
func (v *UnionNoFragmentsQueryResponse) UnmarshalJSON(b []byte) error {
var firstPass struct {
*UnionNoFragmentsQueryResponse
RandomLeaf json.RawMessage `json:"randomLeaf"`
}
firstPass.UnionNoFragmentsQueryResponse = v
err := json.Unmarshal(b, &typenames)
if err != nil {
return err
}
var tn struct {
TypeName string `json:"__typename"`
}
err = json.Unmarshal(firstPass.RandomLeaf, &tn)
if err != nil {
return err
}
switch tn.TypeName {
case "Article":
v.RandomLeaf = Article{}
err = json.Unmarshal(
firstPass.RandomLeaf, &v.RandomLeaf)
case "Video":
v.RandomLeaf = Video{}
err = json.Unmarshal(
firstPass.RandomLeaf, &v.RandomLeaf)
}
if err != nil {
return err
}
}
type Video struct {
Typename *string `json:"__typename"`
}
func (v Video) implementsGraphQLInterfaceLeafContent() {}
func UnionNoFragmentsQuery(client *graphql.Client) (*UnionNoFragmentsQueryResponse, error) {
var retval UnionNoFragmentsQueryResponse
err := client.MakeRequest(context.Background(), `
query UnionNoFragmentsQuery {
randomLeaf {
__typename
}
}
`, &retval, nil)
return &retval, err
}