## Summary: When genqlient generates output types, it generates whatever code is necessary to unmarshal them. Conversely, when it generates input types, it generates whatever code is necessary to marshal. This is all that's needed for genqlient itself: it never needs to marshal output types or unmarshal input types. But maybe you do! (For example, to put the responses in a cache, which is the use case that @csilvers hit at Khan, although there are others one can imagine.) While we can't support every serialization format you might want (at least not without adding plugins or some such), it's not unreasonable to expect that since genqlient can read JSON, it can write it too. Sadly, in the past this was not true for types requiring custom unmarshaling logic, for several reasons. In this commit I implement logic to always write both marshalers and unmarshalers whenever they're needed to be able to correctly round-trip the types, even though genqlient doesn't do so. I wasn't starting from scratch, since of course we already write both marshalers and unmarshalers in some cases. But this ended up requiring surprisingly large changes on the marshaling side, mostly to correctly support embedding (which we use for named fragments). Specifically, as the comments in `types.go` discuss, the most difficult issue is spreads with duplicate fields, which translate to Go embedded fields which end up hidden from the json-marshaler. Ultimately, I had to do things quite differently from unmarshaling, and essentially flatten the type when we write marshaler. But in the end it's not so ugly -- indeed arguably it's cleaner! Mainly it's just different. One thing to note is that we do marshal `__typename` based on what we know about the types; users need not fill it in (and if they do we'll ignore it). This seemed to me to be a better UX, and didn't add much complexity. In general, I begin to wonder whether using `encoding/json` at all is really right for genqlient: we're doing a lot of work to appease it, despite knowing what our types look like. I think it would still be a significant increase in lines of code to roll our own, but that code would perhaps be simpler, and would surely be faster (although if we just want the speed gains we could use another JSON-generator library, see also #47). Anyway, something to think about in the future. ## Test plan: make tesc Author: benjaminjkraft Reviewers: csilvers, StevenACoffman, benjaminjkraft, dnerdy, aberkan, jvoll, mahtabsabet, MiguelCastillo Required Reviewers: Approved By: StevenACoffman, dnerdy Checks: ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Lint, ✅ Test (1.17), ✅ Test (1.16), ✅ Test (1.15), ✅ Test (1.14), ✅ Lint Pull Request URL: https://github.com/Khan/genqlient/pull/120
1664 lines
43 KiB
Go
1664 lines
43 KiB
Go
package test
|
|
|
|
// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/Khan/genqlient/graphql"
|
|
"github.com/Khan/genqlient/internal/testutil"
|
|
)
|
|
|
|
// ComplexNamedFragmentsResponse is returned by ComplexNamedFragments on success.
|
|
type ComplexNamedFragmentsResponse struct {
|
|
QueryFragment `json:"-"`
|
|
}
|
|
|
|
func (v *ComplexNamedFragmentsResponse) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*ComplexNamedFragmentsResponse
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.ComplexNamedFragmentsResponse = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.QueryFragment)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalComplexNamedFragmentsResponse struct {
|
|
RandomItem json.RawMessage `json:"randomItem"`
|
|
|
|
RandomLeaf json.RawMessage `json:"randomLeaf"`
|
|
|
|
OtherLeaf json.RawMessage `json:"otherLeaf"`
|
|
}
|
|
|
|
func (v *ComplexNamedFragmentsResponse) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *ComplexNamedFragmentsResponse) __premarshalJSON() (*__premarshalComplexNamedFragmentsResponse, error) {
|
|
var retval __premarshalComplexNamedFragmentsResponse
|
|
|
|
{
|
|
|
|
dst := &retval.RandomItem
|
|
src := v.QueryFragment.InnerQueryFragment.RandomItem
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentRandomItemContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal ComplexNamedFragmentsResponse.QueryFragment.InnerQueryFragment.RandomItem: %w", err)
|
|
}
|
|
}
|
|
{
|
|
|
|
dst := &retval.RandomLeaf
|
|
src := v.QueryFragment.InnerQueryFragment.RandomLeaf
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentRandomLeafLeafContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal ComplexNamedFragmentsResponse.QueryFragment.InnerQueryFragment.RandomLeaf: %w", err)
|
|
}
|
|
}
|
|
{
|
|
|
|
dst := &retval.OtherLeaf
|
|
src := v.QueryFragment.InnerQueryFragment.OtherLeaf
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentOtherLeafLeafContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal ComplexNamedFragmentsResponse.QueryFragment.InnerQueryFragment.OtherLeaf: %w", err)
|
|
}
|
|
}
|
|
return &retval, nil
|
|
}
|
|
|
|
// ContentFields includes the GraphQL fields of Content requested by the fragment ContentFields.
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// Content is implemented by various types like Article, Video, and Topic.
|
|
//
|
|
// ContentFields is implemented by the following types:
|
|
// ContentFieldsArticle
|
|
// ContentFieldsVideo
|
|
// ContentFieldsTopic
|
|
type ContentFields interface {
|
|
implementsGraphQLInterfaceContentFields()
|
|
// GetName returns the interface-field "name" from its implementation.
|
|
GetName() string
|
|
// GetUrl returns the interface-field "url" from its implementation.
|
|
GetUrl() string
|
|
}
|
|
|
|
func (v *ContentFieldsArticle) implementsGraphQLInterfaceContentFields() {}
|
|
|
|
// GetName is a part of, and documented with, the interface ContentFields.
|
|
func (v *ContentFieldsArticle) GetName() string { return v.Name }
|
|
|
|
// GetUrl is a part of, and documented with, the interface ContentFields.
|
|
func (v *ContentFieldsArticle) GetUrl() string { return v.Url }
|
|
|
|
func (v *ContentFieldsVideo) implementsGraphQLInterfaceContentFields() {}
|
|
|
|
// GetName is a part of, and documented with, the interface ContentFields.
|
|
func (v *ContentFieldsVideo) GetName() string { return v.Name }
|
|
|
|
// GetUrl is a part of, and documented with, the interface ContentFields.
|
|
func (v *ContentFieldsVideo) GetUrl() string { return v.Url }
|
|
|
|
func (v *ContentFieldsTopic) implementsGraphQLInterfaceContentFields() {}
|
|
|
|
// GetName is a part of, and documented with, the interface ContentFields.
|
|
func (v *ContentFieldsTopic) GetName() string { return v.Name }
|
|
|
|
// GetUrl is a part of, and documented with, the interface ContentFields.
|
|
func (v *ContentFieldsTopic) GetUrl() string { return v.Url }
|
|
|
|
func __unmarshalContentFields(b []byte, v *ContentFields) error {
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var tn struct {
|
|
TypeName string `json:"__typename"`
|
|
}
|
|
err := json.Unmarshal(b, &tn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch tn.TypeName {
|
|
case "Article":
|
|
*v = new(ContentFieldsArticle)
|
|
return json.Unmarshal(b, *v)
|
|
case "Video":
|
|
*v = new(ContentFieldsVideo)
|
|
return json.Unmarshal(b, *v)
|
|
case "Topic":
|
|
*v = new(ContentFieldsTopic)
|
|
return json.Unmarshal(b, *v)
|
|
case "":
|
|
return fmt.Errorf(
|
|
"Response was missing Content.__typename")
|
|
default:
|
|
return fmt.Errorf(
|
|
`Unexpected concrete type for ContentFields: "%v"`, tn.TypeName)
|
|
}
|
|
}
|
|
|
|
func __marshalContentFields(v *ContentFields) ([]byte, error) {
|
|
|
|
var typename string
|
|
switch v := (*v).(type) {
|
|
case *ContentFieldsArticle:
|
|
typename = "Article"
|
|
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*ContentFieldsArticle
|
|
}{typename, v}
|
|
return json.Marshal(result)
|
|
case *ContentFieldsVideo:
|
|
typename = "Video"
|
|
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*ContentFieldsVideo
|
|
}{typename, v}
|
|
return json.Marshal(result)
|
|
case *ContentFieldsTopic:
|
|
typename = "Topic"
|
|
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*ContentFieldsTopic
|
|
}{typename, v}
|
|
return json.Marshal(result)
|
|
case nil:
|
|
return []byte("null"), nil
|
|
default:
|
|
return nil, fmt.Errorf(
|
|
`Unexpected concrete type for ContentFields: "%T"`, v)
|
|
}
|
|
}
|
|
|
|
// ContentFields includes the GraphQL fields of Article requested by the fragment ContentFields.
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// Content is implemented by various types like Article, Video, and Topic.
|
|
type ContentFieldsArticle struct {
|
|
Name string `json:"name"`
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
// ContentFields includes the GraphQL fields of Topic requested by the fragment ContentFields.
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// Content is implemented by various types like Article, Video, and Topic.
|
|
type ContentFieldsTopic struct {
|
|
Name string `json:"name"`
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
// ContentFields includes the GraphQL fields of Video requested by the fragment ContentFields.
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// Content is implemented by various types like Article, Video, and Topic.
|
|
type ContentFieldsVideo struct {
|
|
Name string `json:"name"`
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
// InnerQueryFragment includes the GraphQL fields of Query requested by the fragment InnerQueryFragment.
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// Query's description is probably ignored by almost all callers.
|
|
type InnerQueryFragment struct {
|
|
RandomItem InnerQueryFragmentRandomItemContent `json:"-"`
|
|
RandomLeaf InnerQueryFragmentRandomLeafLeafContent `json:"-"`
|
|
OtherLeaf InnerQueryFragmentOtherLeafLeafContent `json:"-"`
|
|
}
|
|
|
|
func (v *InnerQueryFragment) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*InnerQueryFragment
|
|
RandomItem json.RawMessage `json:"randomItem"`
|
|
RandomLeaf json.RawMessage `json:"randomLeaf"`
|
|
OtherLeaf json.RawMessage `json:"otherLeaf"`
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.InnerQueryFragment = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
{
|
|
dst := &v.RandomItem
|
|
src := firstPass.RandomItem
|
|
if len(src) != 0 && string(src) != "null" {
|
|
err = __unmarshalInnerQueryFragmentRandomItemContent(
|
|
src, dst)
|
|
if err != nil {
|
|
return fmt.Errorf(
|
|
"Unable to unmarshal InnerQueryFragment.RandomItem: %w", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
dst := &v.RandomLeaf
|
|
src := firstPass.RandomLeaf
|
|
if len(src) != 0 && string(src) != "null" {
|
|
err = __unmarshalInnerQueryFragmentRandomLeafLeafContent(
|
|
src, dst)
|
|
if err != nil {
|
|
return fmt.Errorf(
|
|
"Unable to unmarshal InnerQueryFragment.RandomLeaf: %w", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
dst := &v.OtherLeaf
|
|
src := firstPass.OtherLeaf
|
|
if len(src) != 0 && string(src) != "null" {
|
|
err = __unmarshalInnerQueryFragmentOtherLeafLeafContent(
|
|
src, dst)
|
|
if err != nil {
|
|
return fmt.Errorf(
|
|
"Unable to unmarshal InnerQueryFragment.OtherLeaf: %w", err)
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalInnerQueryFragment struct {
|
|
RandomItem json.RawMessage `json:"randomItem"`
|
|
|
|
RandomLeaf json.RawMessage `json:"randomLeaf"`
|
|
|
|
OtherLeaf json.RawMessage `json:"otherLeaf"`
|
|
}
|
|
|
|
func (v *InnerQueryFragment) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *InnerQueryFragment) __premarshalJSON() (*__premarshalInnerQueryFragment, error) {
|
|
var retval __premarshalInnerQueryFragment
|
|
|
|
{
|
|
|
|
dst := &retval.RandomItem
|
|
src := v.RandomItem
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentRandomItemContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal InnerQueryFragment.RandomItem: %w", err)
|
|
}
|
|
}
|
|
{
|
|
|
|
dst := &retval.RandomLeaf
|
|
src := v.RandomLeaf
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentRandomLeafLeafContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal InnerQueryFragment.RandomLeaf: %w", err)
|
|
}
|
|
}
|
|
{
|
|
|
|
dst := &retval.OtherLeaf
|
|
src := v.OtherLeaf
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentOtherLeafLeafContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal InnerQueryFragment.OtherLeaf: %w", err)
|
|
}
|
|
}
|
|
return &retval, nil
|
|
}
|
|
|
|
// InnerQueryFragmentOtherLeafArticle includes the requested fields of the GraphQL type Article.
|
|
type InnerQueryFragmentOtherLeafArticle struct {
|
|
Typename string `json:"__typename"`
|
|
ContentFieldsArticle `json:"-"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentOtherLeafArticle) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*InnerQueryFragmentOtherLeafArticle
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.InnerQueryFragmentOtherLeafArticle = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsArticle)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalInnerQueryFragmentOtherLeafArticle struct {
|
|
Typename string `json:"__typename"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentOtherLeafArticle) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *InnerQueryFragmentOtherLeafArticle) __premarshalJSON() (*__premarshalInnerQueryFragmentOtherLeafArticle, error) {
|
|
var retval __premarshalInnerQueryFragmentOtherLeafArticle
|
|
|
|
retval.Typename = v.Typename
|
|
retval.Name = v.ContentFieldsArticle.Name
|
|
retval.Url = v.ContentFieldsArticle.Url
|
|
return &retval, nil
|
|
}
|
|
|
|
// InnerQueryFragmentOtherLeafLeafContent includes the requested fields of the GraphQL interface LeafContent.
|
|
//
|
|
// InnerQueryFragmentOtherLeafLeafContent is implemented by the following types:
|
|
// InnerQueryFragmentOtherLeafArticle
|
|
// InnerQueryFragmentOtherLeafVideo
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// LeafContent represents content items that can't have child-nodes.
|
|
type InnerQueryFragmentOtherLeafLeafContent interface {
|
|
implementsGraphQLInterfaceInnerQueryFragmentOtherLeafLeafContent()
|
|
// GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values).
|
|
GetTypename() string
|
|
}
|
|
|
|
func (v *InnerQueryFragmentOtherLeafArticle) implementsGraphQLInterfaceInnerQueryFragmentOtherLeafLeafContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface InnerQueryFragmentOtherLeafLeafContent.
|
|
func (v *InnerQueryFragmentOtherLeafArticle) GetTypename() string { return v.Typename }
|
|
|
|
func (v *InnerQueryFragmentOtherLeafVideo) implementsGraphQLInterfaceInnerQueryFragmentOtherLeafLeafContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface InnerQueryFragmentOtherLeafLeafContent.
|
|
func (v *InnerQueryFragmentOtherLeafVideo) GetTypename() string { return v.Typename }
|
|
|
|
func __unmarshalInnerQueryFragmentOtherLeafLeafContent(b []byte, v *InnerQueryFragmentOtherLeafLeafContent) error {
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var tn struct {
|
|
TypeName string `json:"__typename"`
|
|
}
|
|
err := json.Unmarshal(b, &tn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch tn.TypeName {
|
|
case "Article":
|
|
*v = new(InnerQueryFragmentOtherLeafArticle)
|
|
return json.Unmarshal(b, *v)
|
|
case "Video":
|
|
*v = new(InnerQueryFragmentOtherLeafVideo)
|
|
return json.Unmarshal(b, *v)
|
|
case "":
|
|
return fmt.Errorf(
|
|
"Response was missing LeafContent.__typename")
|
|
default:
|
|
return fmt.Errorf(
|
|
`Unexpected concrete type for InnerQueryFragmentOtherLeafLeafContent: "%v"`, tn.TypeName)
|
|
}
|
|
}
|
|
|
|
func __marshalInnerQueryFragmentOtherLeafLeafContent(v *InnerQueryFragmentOtherLeafLeafContent) ([]byte, error) {
|
|
|
|
var typename string
|
|
switch v := (*v).(type) {
|
|
case *InnerQueryFragmentOtherLeafArticle:
|
|
typename = "Article"
|
|
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*__premarshalInnerQueryFragmentOtherLeafArticle
|
|
}{typename, premarshaled}
|
|
return json.Marshal(result)
|
|
case *InnerQueryFragmentOtherLeafVideo:
|
|
typename = "Video"
|
|
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*__premarshalInnerQueryFragmentOtherLeafVideo
|
|
}{typename, premarshaled}
|
|
return json.Marshal(result)
|
|
case nil:
|
|
return []byte("null"), nil
|
|
default:
|
|
return nil, fmt.Errorf(
|
|
`Unexpected concrete type for InnerQueryFragmentOtherLeafLeafContent: "%T"`, v)
|
|
}
|
|
}
|
|
|
|
// InnerQueryFragmentOtherLeafVideo includes the requested fields of the GraphQL type Video.
|
|
type InnerQueryFragmentOtherLeafVideo struct {
|
|
Typename string `json:"__typename"`
|
|
MoreVideoFields `json:"-"`
|
|
ContentFieldsVideo `json:"-"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentOtherLeafVideo) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*InnerQueryFragmentOtherLeafVideo
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.InnerQueryFragmentOtherLeafVideo = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.MoreVideoFields)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsVideo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalInnerQueryFragmentOtherLeafVideo struct {
|
|
Typename string `json:"__typename"`
|
|
|
|
Id *testutil.ID `json:"id"`
|
|
|
|
Parent *MoreVideoFieldsParentTopic `json:"parent"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentOtherLeafVideo) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *InnerQueryFragmentOtherLeafVideo) __premarshalJSON() (*__premarshalInnerQueryFragmentOtherLeafVideo, error) {
|
|
var retval __premarshalInnerQueryFragmentOtherLeafVideo
|
|
|
|
retval.Typename = v.Typename
|
|
retval.Id = v.MoreVideoFields.Id
|
|
retval.Parent = v.MoreVideoFields.Parent
|
|
retval.Name = v.ContentFieldsVideo.Name
|
|
retval.Url = v.ContentFieldsVideo.Url
|
|
return &retval, nil
|
|
}
|
|
|
|
// InnerQueryFragmentRandomItemArticle includes the requested fields of the GraphQL type Article.
|
|
type InnerQueryFragmentRandomItemArticle struct {
|
|
Typename string `json:"__typename"`
|
|
// ID is the identifier of the content.
|
|
Id testutil.ID `json:"id"`
|
|
Name string `json:"name"`
|
|
ContentFieldsArticle `json:"-"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemArticle) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*InnerQueryFragmentRandomItemArticle
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.InnerQueryFragmentRandomItemArticle = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsArticle)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalInnerQueryFragmentRandomItemArticle struct {
|
|
Typename string `json:"__typename"`
|
|
|
|
Id testutil.ID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemArticle) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemArticle) __premarshalJSON() (*__premarshalInnerQueryFragmentRandomItemArticle, error) {
|
|
var retval __premarshalInnerQueryFragmentRandomItemArticle
|
|
|
|
retval.Typename = v.Typename
|
|
retval.Id = v.Id
|
|
retval.Name = v.Name
|
|
retval.Url = v.ContentFieldsArticle.Url
|
|
return &retval, nil
|
|
}
|
|
|
|
// InnerQueryFragmentRandomItemContent includes the requested fields of the GraphQL interface Content.
|
|
//
|
|
// InnerQueryFragmentRandomItemContent is implemented by the following types:
|
|
// InnerQueryFragmentRandomItemArticle
|
|
// InnerQueryFragmentRandomItemVideo
|
|
// InnerQueryFragmentRandomItemTopic
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// Content is implemented by various types like Article, Video, and Topic.
|
|
type InnerQueryFragmentRandomItemContent interface {
|
|
implementsGraphQLInterfaceInnerQueryFragmentRandomItemContent()
|
|
// GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values).
|
|
GetTypename() string
|
|
// GetId returns the interface-field "id" from its implementation.
|
|
// The GraphQL interface field's documentation follows.
|
|
//
|
|
// ID is the identifier of the content.
|
|
GetId() testutil.ID
|
|
// GetName returns the interface-field "name" from its implementation.
|
|
GetName() string
|
|
ContentFields
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemArticle) implementsGraphQLInterfaceInnerQueryFragmentRandomItemContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemArticle) GetTypename() string { return v.Typename }
|
|
|
|
// GetId is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemArticle) GetId() testutil.ID { return v.Id }
|
|
|
|
// GetName is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemArticle) GetName() string { return v.Name }
|
|
|
|
func (v *InnerQueryFragmentRandomItemVideo) implementsGraphQLInterfaceInnerQueryFragmentRandomItemContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemVideo) GetTypename() string { return v.Typename }
|
|
|
|
// GetId is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemVideo) GetId() testutil.ID { return v.Id }
|
|
|
|
// GetName is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemVideo) GetName() string { return v.Name }
|
|
|
|
func (v *InnerQueryFragmentRandomItemTopic) implementsGraphQLInterfaceInnerQueryFragmentRandomItemContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemTopic) GetTypename() string { return v.Typename }
|
|
|
|
// GetId is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemTopic) GetId() testutil.ID { return v.Id }
|
|
|
|
// GetName is a part of, and documented with, the interface InnerQueryFragmentRandomItemContent.
|
|
func (v *InnerQueryFragmentRandomItemTopic) GetName() string { return v.Name }
|
|
|
|
func __unmarshalInnerQueryFragmentRandomItemContent(b []byte, v *InnerQueryFragmentRandomItemContent) error {
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var tn struct {
|
|
TypeName string `json:"__typename"`
|
|
}
|
|
err := json.Unmarshal(b, &tn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch tn.TypeName {
|
|
case "Article":
|
|
*v = new(InnerQueryFragmentRandomItemArticle)
|
|
return json.Unmarshal(b, *v)
|
|
case "Video":
|
|
*v = new(InnerQueryFragmentRandomItemVideo)
|
|
return json.Unmarshal(b, *v)
|
|
case "Topic":
|
|
*v = new(InnerQueryFragmentRandomItemTopic)
|
|
return json.Unmarshal(b, *v)
|
|
case "":
|
|
return fmt.Errorf(
|
|
"Response was missing Content.__typename")
|
|
default:
|
|
return fmt.Errorf(
|
|
`Unexpected concrete type for InnerQueryFragmentRandomItemContent: "%v"`, tn.TypeName)
|
|
}
|
|
}
|
|
|
|
func __marshalInnerQueryFragmentRandomItemContent(v *InnerQueryFragmentRandomItemContent) ([]byte, error) {
|
|
|
|
var typename string
|
|
switch v := (*v).(type) {
|
|
case *InnerQueryFragmentRandomItemArticle:
|
|
typename = "Article"
|
|
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*__premarshalInnerQueryFragmentRandomItemArticle
|
|
}{typename, premarshaled}
|
|
return json.Marshal(result)
|
|
case *InnerQueryFragmentRandomItemVideo:
|
|
typename = "Video"
|
|
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*__premarshalInnerQueryFragmentRandomItemVideo
|
|
}{typename, premarshaled}
|
|
return json.Marshal(result)
|
|
case *InnerQueryFragmentRandomItemTopic:
|
|
typename = "Topic"
|
|
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*__premarshalInnerQueryFragmentRandomItemTopic
|
|
}{typename, premarshaled}
|
|
return json.Marshal(result)
|
|
case nil:
|
|
return []byte("null"), nil
|
|
default:
|
|
return nil, fmt.Errorf(
|
|
`Unexpected concrete type for InnerQueryFragmentRandomItemContent: "%T"`, v)
|
|
}
|
|
}
|
|
|
|
// InnerQueryFragmentRandomItemTopic includes the requested fields of the GraphQL type Topic.
|
|
type InnerQueryFragmentRandomItemTopic struct {
|
|
Typename string `json:"__typename"`
|
|
// ID is the identifier of the content.
|
|
Id testutil.ID `json:"id"`
|
|
Name string `json:"name"`
|
|
ContentFieldsTopic `json:"-"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemTopic) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*InnerQueryFragmentRandomItemTopic
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.InnerQueryFragmentRandomItemTopic = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsTopic)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalInnerQueryFragmentRandomItemTopic struct {
|
|
Typename string `json:"__typename"`
|
|
|
|
Id testutil.ID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemTopic) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemTopic) __premarshalJSON() (*__premarshalInnerQueryFragmentRandomItemTopic, error) {
|
|
var retval __premarshalInnerQueryFragmentRandomItemTopic
|
|
|
|
retval.Typename = v.Typename
|
|
retval.Id = v.Id
|
|
retval.Name = v.Name
|
|
retval.Url = v.ContentFieldsTopic.Url
|
|
return &retval, nil
|
|
}
|
|
|
|
// InnerQueryFragmentRandomItemVideo includes the requested fields of the GraphQL type Video.
|
|
type InnerQueryFragmentRandomItemVideo struct {
|
|
Typename string `json:"__typename"`
|
|
// ID is the identifier of the content.
|
|
Id testutil.ID `json:"id"`
|
|
Name string `json:"name"`
|
|
VideoFields `json:"-"`
|
|
ContentFieldsVideo `json:"-"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemVideo) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*InnerQueryFragmentRandomItemVideo
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.InnerQueryFragmentRandomItemVideo = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.VideoFields)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsVideo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalInnerQueryFragmentRandomItemVideo struct {
|
|
Typename string `json:"__typename"`
|
|
|
|
Id testutil.ID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Duration int `json:"duration"`
|
|
|
|
Thumbnail VideoFieldsThumbnail `json:"thumbnail"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemVideo) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomItemVideo) __premarshalJSON() (*__premarshalInnerQueryFragmentRandomItemVideo, error) {
|
|
var retval __premarshalInnerQueryFragmentRandomItemVideo
|
|
|
|
retval.Typename = v.Typename
|
|
retval.Id = v.Id
|
|
retval.Name = v.Name
|
|
retval.Url = v.VideoFields.Url
|
|
retval.Duration = v.VideoFields.Duration
|
|
retval.Thumbnail = v.VideoFields.Thumbnail
|
|
return &retval, nil
|
|
}
|
|
|
|
// InnerQueryFragmentRandomLeafArticle includes the requested fields of the GraphQL type Article.
|
|
type InnerQueryFragmentRandomLeafArticle struct {
|
|
Typename string `json:"__typename"`
|
|
ContentFieldsArticle `json:"-"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomLeafArticle) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*InnerQueryFragmentRandomLeafArticle
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.InnerQueryFragmentRandomLeafArticle = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsArticle)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalInnerQueryFragmentRandomLeafArticle struct {
|
|
Typename string `json:"__typename"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomLeafArticle) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomLeafArticle) __premarshalJSON() (*__premarshalInnerQueryFragmentRandomLeafArticle, error) {
|
|
var retval __premarshalInnerQueryFragmentRandomLeafArticle
|
|
|
|
retval.Typename = v.Typename
|
|
retval.Name = v.ContentFieldsArticle.Name
|
|
retval.Url = v.ContentFieldsArticle.Url
|
|
return &retval, nil
|
|
}
|
|
|
|
// InnerQueryFragmentRandomLeafLeafContent includes the requested fields of the GraphQL interface LeafContent.
|
|
//
|
|
// InnerQueryFragmentRandomLeafLeafContent is implemented by the following types:
|
|
// InnerQueryFragmentRandomLeafArticle
|
|
// InnerQueryFragmentRandomLeafVideo
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// LeafContent represents content items that can't have child-nodes.
|
|
type InnerQueryFragmentRandomLeafLeafContent interface {
|
|
implementsGraphQLInterfaceInnerQueryFragmentRandomLeafLeafContent()
|
|
// GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values).
|
|
GetTypename() string
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomLeafArticle) implementsGraphQLInterfaceInnerQueryFragmentRandomLeafLeafContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface InnerQueryFragmentRandomLeafLeafContent.
|
|
func (v *InnerQueryFragmentRandomLeafArticle) GetTypename() string { return v.Typename }
|
|
|
|
func (v *InnerQueryFragmentRandomLeafVideo) implementsGraphQLInterfaceInnerQueryFragmentRandomLeafLeafContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface InnerQueryFragmentRandomLeafLeafContent.
|
|
func (v *InnerQueryFragmentRandomLeafVideo) GetTypename() string { return v.Typename }
|
|
|
|
func __unmarshalInnerQueryFragmentRandomLeafLeafContent(b []byte, v *InnerQueryFragmentRandomLeafLeafContent) error {
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var tn struct {
|
|
TypeName string `json:"__typename"`
|
|
}
|
|
err := json.Unmarshal(b, &tn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch tn.TypeName {
|
|
case "Article":
|
|
*v = new(InnerQueryFragmentRandomLeafArticle)
|
|
return json.Unmarshal(b, *v)
|
|
case "Video":
|
|
*v = new(InnerQueryFragmentRandomLeafVideo)
|
|
return json.Unmarshal(b, *v)
|
|
case "":
|
|
return fmt.Errorf(
|
|
"Response was missing LeafContent.__typename")
|
|
default:
|
|
return fmt.Errorf(
|
|
`Unexpected concrete type for InnerQueryFragmentRandomLeafLeafContent: "%v"`, tn.TypeName)
|
|
}
|
|
}
|
|
|
|
func __marshalInnerQueryFragmentRandomLeafLeafContent(v *InnerQueryFragmentRandomLeafLeafContent) ([]byte, error) {
|
|
|
|
var typename string
|
|
switch v := (*v).(type) {
|
|
case *InnerQueryFragmentRandomLeafArticle:
|
|
typename = "Article"
|
|
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*__premarshalInnerQueryFragmentRandomLeafArticle
|
|
}{typename, premarshaled}
|
|
return json.Marshal(result)
|
|
case *InnerQueryFragmentRandomLeafVideo:
|
|
typename = "Video"
|
|
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*__premarshalInnerQueryFragmentRandomLeafVideo
|
|
}{typename, premarshaled}
|
|
return json.Marshal(result)
|
|
case nil:
|
|
return []byte("null"), nil
|
|
default:
|
|
return nil, fmt.Errorf(
|
|
`Unexpected concrete type for InnerQueryFragmentRandomLeafLeafContent: "%T"`, v)
|
|
}
|
|
}
|
|
|
|
// InnerQueryFragmentRandomLeafVideo includes the requested fields of the GraphQL type Video.
|
|
type InnerQueryFragmentRandomLeafVideo struct {
|
|
Typename string `json:"__typename"`
|
|
VideoFields `json:"-"`
|
|
MoreVideoFields `json:"-"`
|
|
ContentFieldsVideo `json:"-"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomLeafVideo) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*InnerQueryFragmentRandomLeafVideo
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.InnerQueryFragmentRandomLeafVideo = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.VideoFields)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = json.Unmarshal(
|
|
b, &v.MoreVideoFields)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsVideo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalInnerQueryFragmentRandomLeafVideo struct {
|
|
Typename string `json:"__typename"`
|
|
|
|
Id testutil.ID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Duration int `json:"duration"`
|
|
|
|
Thumbnail VideoFieldsThumbnail `json:"thumbnail"`
|
|
|
|
Parent *MoreVideoFieldsParentTopic `json:"parent"`
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomLeafVideo) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *InnerQueryFragmentRandomLeafVideo) __premarshalJSON() (*__premarshalInnerQueryFragmentRandomLeafVideo, error) {
|
|
var retval __premarshalInnerQueryFragmentRandomLeafVideo
|
|
|
|
retval.Typename = v.Typename
|
|
retval.Id = v.VideoFields.Id
|
|
retval.Name = v.VideoFields.Name
|
|
retval.Url = v.VideoFields.Url
|
|
retval.Duration = v.VideoFields.Duration
|
|
retval.Thumbnail = v.VideoFields.Thumbnail
|
|
retval.Parent = v.MoreVideoFields.Parent
|
|
return &retval, nil
|
|
}
|
|
|
|
// MoreVideoFields includes the GraphQL fields of Video requested by the fragment MoreVideoFields.
|
|
type MoreVideoFields struct {
|
|
// ID is documented in the Content interface.
|
|
Id *testutil.ID `json:"id"`
|
|
Parent *MoreVideoFieldsParentTopic `json:"parent"`
|
|
}
|
|
|
|
// MoreVideoFieldsParentTopic includes the requested fields of the GraphQL type Topic.
|
|
type MoreVideoFieldsParentTopic struct {
|
|
Name *string `json:"name"`
|
|
Url *string `json:"url"`
|
|
ContentFieldsTopic `json:"-"`
|
|
Children []MoreVideoFieldsParentTopicChildrenContent `json:"-"`
|
|
}
|
|
|
|
func (v *MoreVideoFieldsParentTopic) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*MoreVideoFieldsParentTopic
|
|
Children []json.RawMessage `json:"children"`
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.MoreVideoFieldsParentTopic = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsTopic)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
{
|
|
dst := &v.Children
|
|
src := firstPass.Children
|
|
*dst = make(
|
|
[]MoreVideoFieldsParentTopicChildrenContent,
|
|
len(src))
|
|
for i, src := range src {
|
|
dst := &(*dst)[i]
|
|
if len(src) != 0 && string(src) != "null" {
|
|
err = __unmarshalMoreVideoFieldsParentTopicChildrenContent(
|
|
src, dst)
|
|
if err != nil {
|
|
return fmt.Errorf(
|
|
"Unable to unmarshal MoreVideoFieldsParentTopic.Children: %w", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalMoreVideoFieldsParentTopic struct {
|
|
Name *string `json:"name"`
|
|
|
|
Url *string `json:"url"`
|
|
|
|
Children []json.RawMessage `json:"children"`
|
|
}
|
|
|
|
func (v *MoreVideoFieldsParentTopic) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *MoreVideoFieldsParentTopic) __premarshalJSON() (*__premarshalMoreVideoFieldsParentTopic, error) {
|
|
var retval __premarshalMoreVideoFieldsParentTopic
|
|
|
|
retval.Name = v.Name
|
|
retval.Url = v.Url
|
|
{
|
|
|
|
dst := &retval.Children
|
|
src := v.Children
|
|
*dst = make(
|
|
[]json.RawMessage,
|
|
len(src))
|
|
for i, src := range src {
|
|
dst := &(*dst)[i]
|
|
var err error
|
|
*dst, err = __marshalMoreVideoFieldsParentTopicChildrenContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal MoreVideoFieldsParentTopic.Children: %w", err)
|
|
}
|
|
}
|
|
}
|
|
return &retval, nil
|
|
}
|
|
|
|
// MoreVideoFieldsParentTopicChildrenArticle includes the requested fields of the GraphQL type Article.
|
|
type MoreVideoFieldsParentTopicChildrenArticle struct {
|
|
Typename *string `json:"__typename"`
|
|
}
|
|
|
|
// MoreVideoFieldsParentTopicChildrenContent includes the requested fields of the GraphQL interface Content.
|
|
//
|
|
// MoreVideoFieldsParentTopicChildrenContent is implemented by the following types:
|
|
// MoreVideoFieldsParentTopicChildrenArticle
|
|
// MoreVideoFieldsParentTopicChildrenVideo
|
|
// MoreVideoFieldsParentTopicChildrenTopic
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// Content is implemented by various types like Article, Video, and Topic.
|
|
type MoreVideoFieldsParentTopicChildrenContent interface {
|
|
implementsGraphQLInterfaceMoreVideoFieldsParentTopicChildrenContent()
|
|
// GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values).
|
|
GetTypename() *string
|
|
}
|
|
|
|
func (v *MoreVideoFieldsParentTopicChildrenArticle) implementsGraphQLInterfaceMoreVideoFieldsParentTopicChildrenContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface MoreVideoFieldsParentTopicChildrenContent.
|
|
func (v *MoreVideoFieldsParentTopicChildrenArticle) GetTypename() *string { return v.Typename }
|
|
|
|
func (v *MoreVideoFieldsParentTopicChildrenVideo) implementsGraphQLInterfaceMoreVideoFieldsParentTopicChildrenContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface MoreVideoFieldsParentTopicChildrenContent.
|
|
func (v *MoreVideoFieldsParentTopicChildrenVideo) GetTypename() *string { return v.Typename }
|
|
|
|
func (v *MoreVideoFieldsParentTopicChildrenTopic) implementsGraphQLInterfaceMoreVideoFieldsParentTopicChildrenContent() {
|
|
}
|
|
|
|
// GetTypename is a part of, and documented with, the interface MoreVideoFieldsParentTopicChildrenContent.
|
|
func (v *MoreVideoFieldsParentTopicChildrenTopic) GetTypename() *string { return v.Typename }
|
|
|
|
func __unmarshalMoreVideoFieldsParentTopicChildrenContent(b []byte, v *MoreVideoFieldsParentTopicChildrenContent) error {
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var tn struct {
|
|
TypeName string `json:"__typename"`
|
|
}
|
|
err := json.Unmarshal(b, &tn)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
switch tn.TypeName {
|
|
case "Article":
|
|
*v = new(MoreVideoFieldsParentTopicChildrenArticle)
|
|
return json.Unmarshal(b, *v)
|
|
case "Video":
|
|
*v = new(MoreVideoFieldsParentTopicChildrenVideo)
|
|
return json.Unmarshal(b, *v)
|
|
case "Topic":
|
|
*v = new(MoreVideoFieldsParentTopicChildrenTopic)
|
|
return json.Unmarshal(b, *v)
|
|
case "":
|
|
return fmt.Errorf(
|
|
"Response was missing Content.__typename")
|
|
default:
|
|
return fmt.Errorf(
|
|
`Unexpected concrete type for MoreVideoFieldsParentTopicChildrenContent: "%v"`, tn.TypeName)
|
|
}
|
|
}
|
|
|
|
func __marshalMoreVideoFieldsParentTopicChildrenContent(v *MoreVideoFieldsParentTopicChildrenContent) ([]byte, error) {
|
|
|
|
var typename string
|
|
switch v := (*v).(type) {
|
|
case *MoreVideoFieldsParentTopicChildrenArticle:
|
|
typename = "Article"
|
|
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*MoreVideoFieldsParentTopicChildrenArticle
|
|
}{typename, v}
|
|
return json.Marshal(result)
|
|
case *MoreVideoFieldsParentTopicChildrenVideo:
|
|
typename = "Video"
|
|
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*__premarshalMoreVideoFieldsParentTopicChildrenVideo
|
|
}{typename, premarshaled}
|
|
return json.Marshal(result)
|
|
case *MoreVideoFieldsParentTopicChildrenTopic:
|
|
typename = "Topic"
|
|
|
|
result := struct {
|
|
TypeName string `json:"__typename"`
|
|
*MoreVideoFieldsParentTopicChildrenTopic
|
|
}{typename, v}
|
|
return json.Marshal(result)
|
|
case nil:
|
|
return []byte("null"), nil
|
|
default:
|
|
return nil, fmt.Errorf(
|
|
`Unexpected concrete type for MoreVideoFieldsParentTopicChildrenContent: "%T"`, v)
|
|
}
|
|
}
|
|
|
|
// MoreVideoFieldsParentTopicChildrenTopic includes the requested fields of the GraphQL type Topic.
|
|
type MoreVideoFieldsParentTopicChildrenTopic struct {
|
|
Typename *string `json:"__typename"`
|
|
}
|
|
|
|
// MoreVideoFieldsParentTopicChildrenVideo includes the requested fields of the GraphQL type Video.
|
|
type MoreVideoFieldsParentTopicChildrenVideo struct {
|
|
Typename *string `json:"__typename"`
|
|
VideoFields `json:"-"`
|
|
}
|
|
|
|
func (v *MoreVideoFieldsParentTopicChildrenVideo) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*MoreVideoFieldsParentTopicChildrenVideo
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.MoreVideoFieldsParentTopicChildrenVideo = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.VideoFields)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalMoreVideoFieldsParentTopicChildrenVideo struct {
|
|
Typename *string `json:"__typename"`
|
|
|
|
Id testutil.ID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Duration int `json:"duration"`
|
|
|
|
Thumbnail VideoFieldsThumbnail `json:"thumbnail"`
|
|
}
|
|
|
|
func (v *MoreVideoFieldsParentTopicChildrenVideo) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *MoreVideoFieldsParentTopicChildrenVideo) __premarshalJSON() (*__premarshalMoreVideoFieldsParentTopicChildrenVideo, error) {
|
|
var retval __premarshalMoreVideoFieldsParentTopicChildrenVideo
|
|
|
|
retval.Typename = v.Typename
|
|
retval.Id = v.VideoFields.Id
|
|
retval.Name = v.VideoFields.Name
|
|
retval.Url = v.VideoFields.Url
|
|
retval.Duration = v.VideoFields.Duration
|
|
retval.Thumbnail = v.VideoFields.Thumbnail
|
|
return &retval, nil
|
|
}
|
|
|
|
// QueryFragment includes the GraphQL fields of Query requested by the fragment QueryFragment.
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// Query's description is probably ignored by almost all callers.
|
|
type QueryFragment struct {
|
|
InnerQueryFragment `json:"-"`
|
|
}
|
|
|
|
func (v *QueryFragment) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*QueryFragment
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.QueryFragment = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.InnerQueryFragment)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalQueryFragment struct {
|
|
RandomItem json.RawMessage `json:"randomItem"`
|
|
|
|
RandomLeaf json.RawMessage `json:"randomLeaf"`
|
|
|
|
OtherLeaf json.RawMessage `json:"otherLeaf"`
|
|
}
|
|
|
|
func (v *QueryFragment) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *QueryFragment) __premarshalJSON() (*__premarshalQueryFragment, error) {
|
|
var retval __premarshalQueryFragment
|
|
|
|
{
|
|
|
|
dst := &retval.RandomItem
|
|
src := v.InnerQueryFragment.RandomItem
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentRandomItemContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal QueryFragment.InnerQueryFragment.RandomItem: %w", err)
|
|
}
|
|
}
|
|
{
|
|
|
|
dst := &retval.RandomLeaf
|
|
src := v.InnerQueryFragment.RandomLeaf
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentRandomLeafLeafContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal QueryFragment.InnerQueryFragment.RandomLeaf: %w", err)
|
|
}
|
|
}
|
|
{
|
|
|
|
dst := &retval.OtherLeaf
|
|
src := v.InnerQueryFragment.OtherLeaf
|
|
var err error
|
|
*dst, err = __marshalInnerQueryFragmentOtherLeafLeafContent(
|
|
&src)
|
|
if err != nil {
|
|
return nil, fmt.Errorf(
|
|
"Unable to marshal QueryFragment.InnerQueryFragment.OtherLeaf: %w", err)
|
|
}
|
|
}
|
|
return &retval, nil
|
|
}
|
|
|
|
// VideoFields includes the GraphQL fields of Video requested by the fragment VideoFields.
|
|
type VideoFields struct {
|
|
// ID is documented in the Content interface.
|
|
Id testutil.ID `json:"id"`
|
|
Name string `json:"name"`
|
|
Url string `json:"url"`
|
|
Duration int `json:"duration"`
|
|
Thumbnail VideoFieldsThumbnail `json:"thumbnail"`
|
|
ContentFieldsVideo `json:"-"`
|
|
}
|
|
|
|
func (v *VideoFields) UnmarshalJSON(b []byte) error {
|
|
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
|
|
var firstPass struct {
|
|
*VideoFields
|
|
graphql.NoUnmarshalJSON
|
|
}
|
|
firstPass.VideoFields = v
|
|
|
|
err := json.Unmarshal(b, &firstPass)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal(
|
|
b, &v.ContentFieldsVideo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type __premarshalVideoFields struct {
|
|
Id testutil.ID `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Duration int `json:"duration"`
|
|
|
|
Thumbnail VideoFieldsThumbnail `json:"thumbnail"`
|
|
}
|
|
|
|
func (v *VideoFields) MarshalJSON() ([]byte, error) {
|
|
premarshaled, err := v.__premarshalJSON()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(premarshaled)
|
|
}
|
|
|
|
func (v *VideoFields) __premarshalJSON() (*__premarshalVideoFields, error) {
|
|
var retval __premarshalVideoFields
|
|
|
|
retval.Id = v.Id
|
|
retval.Name = v.Name
|
|
retval.Url = v.Url
|
|
retval.Duration = v.Duration
|
|
retval.Thumbnail = v.Thumbnail
|
|
return &retval, nil
|
|
}
|
|
|
|
// VideoFieldsThumbnail includes the requested fields of the GraphQL type Thumbnail.
|
|
type VideoFieldsThumbnail struct {
|
|
Id testutil.ID `json:"id"`
|
|
}
|
|
|
|
func ComplexNamedFragments(
|
|
client graphql.Client,
|
|
) (*ComplexNamedFragmentsResponse, error) {
|
|
var err error
|
|
|
|
var retval ComplexNamedFragmentsResponse
|
|
err = client.MakeRequest(
|
|
nil,
|
|
"ComplexNamedFragments",
|
|
`
|
|
query ComplexNamedFragments {
|
|
... on Query {
|
|
... QueryFragment
|
|
}
|
|
}
|
|
fragment QueryFragment on Query {
|
|
... InnerQueryFragment
|
|
}
|
|
fragment InnerQueryFragment on Query {
|
|
randomItem {
|
|
__typename
|
|
id
|
|
name
|
|
... VideoFields
|
|
... ContentFields
|
|
}
|
|
randomLeaf {
|
|
__typename
|
|
... VideoFields
|
|
... MoreVideoFields
|
|
... ContentFields
|
|
}
|
|
otherLeaf: randomLeaf {
|
|
__typename
|
|
... on Video {
|
|
... MoreVideoFields
|
|
... ContentFields
|
|
}
|
|
... ContentFields
|
|
}
|
|
}
|
|
fragment VideoFields on Video {
|
|
id
|
|
name
|
|
url
|
|
duration
|
|
thumbnail {
|
|
id
|
|
}
|
|
... ContentFields
|
|
}
|
|
fragment ContentFields on Content {
|
|
name
|
|
url
|
|
}
|
|
fragment MoreVideoFields on Video {
|
|
id
|
|
parent {
|
|
name
|
|
url
|
|
... ContentFields
|
|
children {
|
|
__typename
|
|
... VideoFields
|
|
}
|
|
}
|
|
}
|
|
`,
|
|
&retval,
|
|
nil,
|
|
)
|
|
return &retval, err
|
|
}
|
|
|