github.com/codykaup/genqlient@v0.6.2/generate/testdata/snapshots/TestGenerate-Flatten.graphql-Flatten.graphql.go (about)

     1  // Code generated by github.com/codykaup/genqlient, DO NOT EDIT.
     2  
     3  package test
     4  
     5  import (
     6  	"encoding/json"
     7  	"fmt"
     8  
     9  	"github.com/codykaup/genqlient/graphql"
    10  	"github.com/codykaup/genqlient/internal/testutil"
    11  )
    12  
    13  // ChildVideoFields includes the GraphQL fields of Video requested by the fragment ChildVideoFields.
    14  type ChildVideoFields struct {
    15  	// ID is documented in the Content interface.
    16  	Id   testutil.ID `json:"id"`
    17  	Name string      `json:"name"`
    18  }
    19  
    20  // GetId returns ChildVideoFields.Id, and is useful for accessing the field via an interface.
    21  func (v *ChildVideoFields) GetId() testutil.ID { return v.Id }
    22  
    23  // GetName returns ChildVideoFields.Name, and is useful for accessing the field via an interface.
    24  func (v *ChildVideoFields) GetName() string { return v.Name }
    25  
    26  // ContentFields includes the GraphQL fields of Content requested by the fragment ContentFields.
    27  // The GraphQL type's documentation follows.
    28  //
    29  // Content is implemented by various types like Article, Video, and Topic.
    30  //
    31  // ContentFields is implemented by the following types:
    32  // ContentFieldsArticle
    33  // ContentFieldsVideo
    34  // ContentFieldsTopic
    35  type ContentFields interface {
    36  	implementsGraphQLInterfaceContentFields()
    37  	// GetName returns the interface-field "name" from its implementation.
    38  	GetName() string
    39  	// GetUrl returns the interface-field "url" from its implementation.
    40  	GetUrl() string
    41  }
    42  
    43  func (v *ContentFieldsArticle) implementsGraphQLInterfaceContentFields() {}
    44  func (v *ContentFieldsVideo) implementsGraphQLInterfaceContentFields()   {}
    45  func (v *ContentFieldsTopic) implementsGraphQLInterfaceContentFields()   {}
    46  
    47  func __unmarshalContentFields(b []byte, v *ContentFields) error {
    48  	if string(b) == "null" {
    49  		return nil
    50  	}
    51  
    52  	var tn struct {
    53  		TypeName string `json:"__typename"`
    54  	}
    55  	err := json.Unmarshal(b, &tn)
    56  	if err != nil {
    57  		return err
    58  	}
    59  
    60  	switch tn.TypeName {
    61  	case "Article":
    62  		*v = new(ContentFieldsArticle)
    63  		return json.Unmarshal(b, *v)
    64  	case "Video":
    65  		*v = new(ContentFieldsVideo)
    66  		return json.Unmarshal(b, *v)
    67  	case "Topic":
    68  		*v = new(ContentFieldsTopic)
    69  		return json.Unmarshal(b, *v)
    70  	case "":
    71  		return fmt.Errorf(
    72  			"response was missing Content.__typename")
    73  	default:
    74  		return fmt.Errorf(
    75  			`unexpected concrete type for ContentFields: "%v"`, tn.TypeName)
    76  	}
    77  }
    78  
    79  func __marshalContentFields(v *ContentFields) ([]byte, error) {
    80  
    81  	var typename string
    82  	switch v := (*v).(type) {
    83  	case *ContentFieldsArticle:
    84  		typename = "Article"
    85  
    86  		result := struct {
    87  			TypeName string `json:"__typename"`
    88  			*ContentFieldsArticle
    89  		}{typename, v}
    90  		return json.Marshal(result)
    91  	case *ContentFieldsVideo:
    92  		typename = "Video"
    93  
    94  		result := struct {
    95  			TypeName string `json:"__typename"`
    96  			*ContentFieldsVideo
    97  		}{typename, v}
    98  		return json.Marshal(result)
    99  	case *ContentFieldsTopic:
   100  		typename = "Topic"
   101  
   102  		result := struct {
   103  			TypeName string `json:"__typename"`
   104  			*ContentFieldsTopic
   105  		}{typename, v}
   106  		return json.Marshal(result)
   107  	case nil:
   108  		return []byte("null"), nil
   109  	default:
   110  		return nil, fmt.Errorf(
   111  			`unexpected concrete type for ContentFields: "%T"`, v)
   112  	}
   113  }
   114  
   115  // ContentFields includes the GraphQL fields of Article requested by the fragment ContentFields.
   116  // The GraphQL type's documentation follows.
   117  //
   118  // Content is implemented by various types like Article, Video, and Topic.
   119  type ContentFieldsArticle struct {
   120  	Name string `json:"name"`
   121  	Url  string `json:"url"`
   122  }
   123  
   124  // GetName returns ContentFieldsArticle.Name, and is useful for accessing the field via an interface.
   125  func (v *ContentFieldsArticle) GetName() string { return v.Name }
   126  
   127  // GetUrl returns ContentFieldsArticle.Url, and is useful for accessing the field via an interface.
   128  func (v *ContentFieldsArticle) GetUrl() string { return v.Url }
   129  
   130  // ContentFields includes the GraphQL fields of Topic requested by the fragment ContentFields.
   131  // The GraphQL type's documentation follows.
   132  //
   133  // Content is implemented by various types like Article, Video, and Topic.
   134  type ContentFieldsTopic struct {
   135  	Name string `json:"name"`
   136  	Url  string `json:"url"`
   137  }
   138  
   139  // GetName returns ContentFieldsTopic.Name, and is useful for accessing the field via an interface.
   140  func (v *ContentFieldsTopic) GetName() string { return v.Name }
   141  
   142  // GetUrl returns ContentFieldsTopic.Url, and is useful for accessing the field via an interface.
   143  func (v *ContentFieldsTopic) GetUrl() string { return v.Url }
   144  
   145  // ContentFields includes the GraphQL fields of Video requested by the fragment ContentFields.
   146  // The GraphQL type's documentation follows.
   147  //
   148  // Content is implemented by various types like Article, Video, and Topic.
   149  type ContentFieldsVideo struct {
   150  	Name string `json:"name"`
   151  	Url  string `json:"url"`
   152  }
   153  
   154  // GetName returns ContentFieldsVideo.Name, and is useful for accessing the field via an interface.
   155  func (v *ContentFieldsVideo) GetName() string { return v.Name }
   156  
   157  // GetUrl returns ContentFieldsVideo.Url, and is useful for accessing the field via an interface.
   158  func (v *ContentFieldsVideo) GetUrl() string { return v.Url }
   159  
   160  // InnerQueryFragment includes the GraphQL fields of Query requested by the fragment InnerQueryFragment.
   161  // The GraphQL type's documentation follows.
   162  //
   163  // Query's description is probably ignored by almost all callers.
   164  type InnerQueryFragment struct {
   165  	RandomVideo VideoFields        `json:"randomVideo"`
   166  	RandomItem  ContentFields      `json:"-"`
   167  	OtherVideo  ContentFieldsVideo `json:"otherVideo"`
   168  }
   169  
   170  // GetRandomVideo returns InnerQueryFragment.RandomVideo, and is useful for accessing the field via an interface.
   171  func (v *InnerQueryFragment) GetRandomVideo() VideoFields { return v.RandomVideo }
   172  
   173  // GetRandomItem returns InnerQueryFragment.RandomItem, and is useful for accessing the field via an interface.
   174  func (v *InnerQueryFragment) GetRandomItem() ContentFields { return v.RandomItem }
   175  
   176  // GetOtherVideo returns InnerQueryFragment.OtherVideo, and is useful for accessing the field via an interface.
   177  func (v *InnerQueryFragment) GetOtherVideo() ContentFieldsVideo { return v.OtherVideo }
   178  
   179  func (v *InnerQueryFragment) UnmarshalJSON(b []byte) error {
   180  
   181  	if string(b) == "null" {
   182  		return nil
   183  	}
   184  
   185  	var firstPass struct {
   186  		*InnerQueryFragment
   187  		RandomItem json.RawMessage `json:"randomItem"`
   188  		graphql.NoUnmarshalJSON
   189  	}
   190  	firstPass.InnerQueryFragment = v
   191  
   192  	err := json.Unmarshal(b, &firstPass)
   193  	if err != nil {
   194  		return err
   195  	}
   196  
   197  	{
   198  		dst := &v.RandomItem
   199  		src := firstPass.RandomItem
   200  		if len(src) != 0 && string(src) != "null" {
   201  			err = __unmarshalContentFields(
   202  				src, dst)
   203  			if err != nil {
   204  				return fmt.Errorf(
   205  					"unable to unmarshal InnerQueryFragment.RandomItem: %w", err)
   206  			}
   207  		}
   208  	}
   209  	return nil
   210  }
   211  
   212  type __premarshalInnerQueryFragment struct {
   213  	RandomVideo VideoFields `json:"randomVideo"`
   214  
   215  	RandomItem json.RawMessage `json:"randomItem"`
   216  
   217  	OtherVideo ContentFieldsVideo `json:"otherVideo"`
   218  }
   219  
   220  func (v *InnerQueryFragment) MarshalJSON() ([]byte, error) {
   221  	premarshaled, err := v.__premarshalJSON()
   222  	if err != nil {
   223  		return nil, err
   224  	}
   225  	return json.Marshal(premarshaled)
   226  }
   227  
   228  func (v *InnerQueryFragment) __premarshalJSON() (*__premarshalInnerQueryFragment, error) {
   229  	var retval __premarshalInnerQueryFragment
   230  
   231  	retval.RandomVideo = v.RandomVideo
   232  	{
   233  
   234  		dst := &retval.RandomItem
   235  		src := v.RandomItem
   236  		var err error
   237  		*dst, err = __marshalContentFields(
   238  			&src)
   239  		if err != nil {
   240  			return nil, fmt.Errorf(
   241  				"unable to marshal InnerQueryFragment.RandomItem: %w", err)
   242  		}
   243  	}
   244  	retval.OtherVideo = v.OtherVideo
   245  	return &retval, nil
   246  }
   247  
   248  // VideoFields includes the GraphQL fields of Video requested by the fragment VideoFields.
   249  type VideoFields struct {
   250  	// ID is documented in the Content interface.
   251  	Id     testutil.ID            `json:"id"`
   252  	Parent VideoFieldsParentTopic `json:"parent"`
   253  }
   254  
   255  // GetId returns VideoFields.Id, and is useful for accessing the field via an interface.
   256  func (v *VideoFields) GetId() testutil.ID { return v.Id }
   257  
   258  // GetParent returns VideoFields.Parent, and is useful for accessing the field via an interface.
   259  func (v *VideoFields) GetParent() VideoFieldsParentTopic { return v.Parent }
   260  
   261  // VideoFieldsParentTopic includes the requested fields of the GraphQL type Topic.
   262  type VideoFieldsParentTopic struct {
   263  	VideoChildren []ChildVideoFields `json:"videoChildren"`
   264  }
   265  
   266  // GetVideoChildren returns VideoFieldsParentTopic.VideoChildren, and is useful for accessing the field via an interface.
   267  func (v *VideoFieldsParentTopic) GetVideoChildren() []ChildVideoFields { return v.VideoChildren }
   268  
   269  // The query or mutation executed by ComplexNamedFragments.
   270  const ComplexNamedFragments_Operation = `
   271  query ComplexNamedFragments {
   272  	... QueryFragment
   273  }
   274  fragment QueryFragment on Query {
   275  	... InnerQueryFragment
   276  }
   277  fragment InnerQueryFragment on Query {
   278  	randomVideo {
   279  		... VideoFields
   280  	}
   281  	randomItem {
   282  		__typename
   283  		... ContentFields
   284  	}
   285  	otherVideo: randomVideo {
   286  		... ContentFields
   287  	}
   288  }
   289  fragment VideoFields on Video {
   290  	id
   291  	parent {
   292  		videoChildren {
   293  			... ChildVideoFields
   294  		}
   295  	}
   296  }
   297  fragment ContentFields on Content {
   298  	name
   299  	url
   300  }
   301  fragment ChildVideoFields on Video {
   302  	id
   303  	name
   304  }
   305  `
   306  
   307  func ComplexNamedFragments(
   308  	client_ graphql.Client,
   309  ) (*InnerQueryFragment, error) {
   310  	req_ := &graphql.Request{
   311  		OpName: "ComplexNamedFragments",
   312  		Query:  ComplexNamedFragments_Operation,
   313  	}
   314  	var err_ error
   315  
   316  	var data_ InnerQueryFragment
   317  	resp_ := &graphql.Response{Data: &data_}
   318  
   319  	err_ = client_.MakeRequest(
   320  		nil,
   321  		req_,
   322  		resp_,
   323  	)
   324  
   325  	return &data_, err_
   326  }
   327