github.com/codykaup/genqlient@v0.6.2/generate/testdata/snapshots/TestGenerate-SimpleInlineFragment.graphql-SimpleInlineFragment.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 // SimpleInlineFragmentRandomItemArticle includes the requested fields of the GraphQL type Article. 14 type SimpleInlineFragmentRandomItemArticle struct { 15 Typename string `json:"__typename"` 16 // ID is the identifier of the content. 17 Id testutil.ID `json:"id"` 18 Name string `json:"name"` 19 Text string `json:"text"` 20 } 21 22 // GetTypename returns SimpleInlineFragmentRandomItemArticle.Typename, and is useful for accessing the field via an interface. 23 func (v *SimpleInlineFragmentRandomItemArticle) GetTypename() string { return v.Typename } 24 25 // GetId returns SimpleInlineFragmentRandomItemArticle.Id, and is useful for accessing the field via an interface. 26 func (v *SimpleInlineFragmentRandomItemArticle) GetId() testutil.ID { return v.Id } 27 28 // GetName returns SimpleInlineFragmentRandomItemArticle.Name, and is useful for accessing the field via an interface. 29 func (v *SimpleInlineFragmentRandomItemArticle) GetName() string { return v.Name } 30 31 // GetText returns SimpleInlineFragmentRandomItemArticle.Text, and is useful for accessing the field via an interface. 32 func (v *SimpleInlineFragmentRandomItemArticle) GetText() string { return v.Text } 33 34 // SimpleInlineFragmentRandomItemContent includes the requested fields of the GraphQL interface Content. 35 // 36 // SimpleInlineFragmentRandomItemContent is implemented by the following types: 37 // SimpleInlineFragmentRandomItemArticle 38 // SimpleInlineFragmentRandomItemTopic 39 // SimpleInlineFragmentRandomItemVideo 40 // The GraphQL type's documentation follows. 41 // 42 // Content is implemented by various types like Article, Video, and Topic. 43 type SimpleInlineFragmentRandomItemContent interface { 44 implementsGraphQLInterfaceSimpleInlineFragmentRandomItemContent() 45 // GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values). 46 GetTypename() string 47 // GetId returns the interface-field "id" from its implementation. 48 // The GraphQL interface field's documentation follows. 49 // 50 // ID is the identifier of the content. 51 GetId() testutil.ID 52 // GetName returns the interface-field "name" from its implementation. 53 GetName() string 54 } 55 56 func (v *SimpleInlineFragmentRandomItemArticle) implementsGraphQLInterfaceSimpleInlineFragmentRandomItemContent() { 57 } 58 func (v *SimpleInlineFragmentRandomItemTopic) implementsGraphQLInterfaceSimpleInlineFragmentRandomItemContent() { 59 } 60 func (v *SimpleInlineFragmentRandomItemVideo) implementsGraphQLInterfaceSimpleInlineFragmentRandomItemContent() { 61 } 62 63 func __unmarshalSimpleInlineFragmentRandomItemContent(b []byte, v *SimpleInlineFragmentRandomItemContent) error { 64 if string(b) == "null" { 65 return nil 66 } 67 68 var tn struct { 69 TypeName string `json:"__typename"` 70 } 71 err := json.Unmarshal(b, &tn) 72 if err != nil { 73 return err 74 } 75 76 switch tn.TypeName { 77 case "Article": 78 *v = new(SimpleInlineFragmentRandomItemArticle) 79 return json.Unmarshal(b, *v) 80 case "Topic": 81 *v = new(SimpleInlineFragmentRandomItemTopic) 82 return json.Unmarshal(b, *v) 83 case "Video": 84 *v = new(SimpleInlineFragmentRandomItemVideo) 85 return json.Unmarshal(b, *v) 86 case "": 87 return fmt.Errorf( 88 "response was missing Content.__typename") 89 default: 90 return fmt.Errorf( 91 `unexpected concrete type for SimpleInlineFragmentRandomItemContent: "%v"`, tn.TypeName) 92 } 93 } 94 95 func __marshalSimpleInlineFragmentRandomItemContent(v *SimpleInlineFragmentRandomItemContent) ([]byte, error) { 96 97 var typename string 98 switch v := (*v).(type) { 99 case *SimpleInlineFragmentRandomItemArticle: 100 typename = "Article" 101 102 result := struct { 103 TypeName string `json:"__typename"` 104 *SimpleInlineFragmentRandomItemArticle 105 }{typename, v} 106 return json.Marshal(result) 107 case *SimpleInlineFragmentRandomItemTopic: 108 typename = "Topic" 109 110 result := struct { 111 TypeName string `json:"__typename"` 112 *SimpleInlineFragmentRandomItemTopic 113 }{typename, v} 114 return json.Marshal(result) 115 case *SimpleInlineFragmentRandomItemVideo: 116 typename = "Video" 117 118 result := struct { 119 TypeName string `json:"__typename"` 120 *SimpleInlineFragmentRandomItemVideo 121 }{typename, v} 122 return json.Marshal(result) 123 case nil: 124 return []byte("null"), nil 125 default: 126 return nil, fmt.Errorf( 127 `unexpected concrete type for SimpleInlineFragmentRandomItemContent: "%T"`, v) 128 } 129 } 130 131 // SimpleInlineFragmentRandomItemTopic includes the requested fields of the GraphQL type Topic. 132 type SimpleInlineFragmentRandomItemTopic struct { 133 Typename string `json:"__typename"` 134 // ID is the identifier of the content. 135 Id testutil.ID `json:"id"` 136 Name string `json:"name"` 137 } 138 139 // GetTypename returns SimpleInlineFragmentRandomItemTopic.Typename, and is useful for accessing the field via an interface. 140 func (v *SimpleInlineFragmentRandomItemTopic) GetTypename() string { return v.Typename } 141 142 // GetId returns SimpleInlineFragmentRandomItemTopic.Id, and is useful for accessing the field via an interface. 143 func (v *SimpleInlineFragmentRandomItemTopic) GetId() testutil.ID { return v.Id } 144 145 // GetName returns SimpleInlineFragmentRandomItemTopic.Name, and is useful for accessing the field via an interface. 146 func (v *SimpleInlineFragmentRandomItemTopic) GetName() string { return v.Name } 147 148 // SimpleInlineFragmentRandomItemVideo includes the requested fields of the GraphQL type Video. 149 type SimpleInlineFragmentRandomItemVideo struct { 150 Typename string `json:"__typename"` 151 // ID is the identifier of the content. 152 Id testutil.ID `json:"id"` 153 Name string `json:"name"` 154 Duration int `json:"duration"` 155 } 156 157 // GetTypename returns SimpleInlineFragmentRandomItemVideo.Typename, and is useful for accessing the field via an interface. 158 func (v *SimpleInlineFragmentRandomItemVideo) GetTypename() string { return v.Typename } 159 160 // GetId returns SimpleInlineFragmentRandomItemVideo.Id, and is useful for accessing the field via an interface. 161 func (v *SimpleInlineFragmentRandomItemVideo) GetId() testutil.ID { return v.Id } 162 163 // GetName returns SimpleInlineFragmentRandomItemVideo.Name, and is useful for accessing the field via an interface. 164 func (v *SimpleInlineFragmentRandomItemVideo) GetName() string { return v.Name } 165 166 // GetDuration returns SimpleInlineFragmentRandomItemVideo.Duration, and is useful for accessing the field via an interface. 167 func (v *SimpleInlineFragmentRandomItemVideo) GetDuration() int { return v.Duration } 168 169 // SimpleInlineFragmentResponse is returned by SimpleInlineFragment on success. 170 type SimpleInlineFragmentResponse struct { 171 RandomItem SimpleInlineFragmentRandomItemContent `json:"-"` 172 } 173 174 // GetRandomItem returns SimpleInlineFragmentResponse.RandomItem, and is useful for accessing the field via an interface. 175 func (v *SimpleInlineFragmentResponse) GetRandomItem() SimpleInlineFragmentRandomItemContent { 176 return v.RandomItem 177 } 178 179 func (v *SimpleInlineFragmentResponse) UnmarshalJSON(b []byte) error { 180 181 if string(b) == "null" { 182 return nil 183 } 184 185 var firstPass struct { 186 *SimpleInlineFragmentResponse 187 RandomItem json.RawMessage `json:"randomItem"` 188 graphql.NoUnmarshalJSON 189 } 190 firstPass.SimpleInlineFragmentResponse = 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 = __unmarshalSimpleInlineFragmentRandomItemContent( 202 src, dst) 203 if err != nil { 204 return fmt.Errorf( 205 "unable to unmarshal SimpleInlineFragmentResponse.RandomItem: %w", err) 206 } 207 } 208 } 209 return nil 210 } 211 212 type __premarshalSimpleInlineFragmentResponse struct { 213 RandomItem json.RawMessage `json:"randomItem"` 214 } 215 216 func (v *SimpleInlineFragmentResponse) MarshalJSON() ([]byte, error) { 217 premarshaled, err := v.__premarshalJSON() 218 if err != nil { 219 return nil, err 220 } 221 return json.Marshal(premarshaled) 222 } 223 224 func (v *SimpleInlineFragmentResponse) __premarshalJSON() (*__premarshalSimpleInlineFragmentResponse, error) { 225 var retval __premarshalSimpleInlineFragmentResponse 226 227 { 228 229 dst := &retval.RandomItem 230 src := v.RandomItem 231 var err error 232 *dst, err = __marshalSimpleInlineFragmentRandomItemContent( 233 &src) 234 if err != nil { 235 return nil, fmt.Errorf( 236 "unable to marshal SimpleInlineFragmentResponse.RandomItem: %w", err) 237 } 238 } 239 return &retval, nil 240 } 241 242 // The query or mutation executed by SimpleInlineFragment. 243 const SimpleInlineFragment_Operation = ` 244 query SimpleInlineFragment { 245 randomItem { 246 __typename 247 id 248 name 249 ... on Article { 250 text 251 } 252 ... on Video { 253 duration 254 } 255 } 256 } 257 ` 258 259 func SimpleInlineFragment( 260 client_ graphql.Client, 261 ) (*SimpleInlineFragmentResponse, error) { 262 req_ := &graphql.Request{ 263 OpName: "SimpleInlineFragment", 264 Query: SimpleInlineFragment_Operation, 265 } 266 var err_ error 267 268 var data_ SimpleInlineFragmentResponse 269 resp_ := &graphql.Response{Data: &data_} 270 271 err_ = client_.MakeRequest( 272 nil, 273 req_, 274 resp_, 275 ) 276 277 return &data_, err_ 278 } 279