github.com/opiuman/genqlient@v1.0.0/generate/testdata/snapshots/TestGenerate-SimpleNamedFragment.graphql-SimpleNamedFragment.graphql.go (about) 1 // Code generated by github.com/opiuman/genqlient, DO NOT EDIT. 2 3 package test 4 5 import ( 6 "encoding/json" 7 "fmt" 8 9 "github.com/opiuman/genqlient/graphql" 10 "github.com/opiuman/genqlient/internal/testutil" 11 ) 12 13 // SimpleNamedFragmentRandomItemArticle includes the requested fields of the GraphQL type Article. 14 type SimpleNamedFragmentRandomItemArticle 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 } 20 21 // GetTypename returns SimpleNamedFragmentRandomItemArticle.Typename, and is useful for accessing the field via an interface. 22 func (v *SimpleNamedFragmentRandomItemArticle) GetTypename() string { return v.Typename } 23 24 // GetId returns SimpleNamedFragmentRandomItemArticle.Id, and is useful for accessing the field via an interface. 25 func (v *SimpleNamedFragmentRandomItemArticle) GetId() testutil.ID { return v.Id } 26 27 // GetName returns SimpleNamedFragmentRandomItemArticle.Name, and is useful for accessing the field via an interface. 28 func (v *SimpleNamedFragmentRandomItemArticle) GetName() string { return v.Name } 29 30 // SimpleNamedFragmentRandomItemContent includes the requested fields of the GraphQL interface Content. 31 // 32 // SimpleNamedFragmentRandomItemContent is implemented by the following types: 33 // SimpleNamedFragmentRandomItemArticle 34 // SimpleNamedFragmentRandomItemVideo 35 // SimpleNamedFragmentRandomItemTopic 36 // The GraphQL type's documentation follows. 37 // 38 // Content is implemented by various types like Article, Video, and Topic. 39 type SimpleNamedFragmentRandomItemContent interface { 40 implementsGraphQLInterfaceSimpleNamedFragmentRandomItemContent() 41 // GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values). 42 GetTypename() string 43 // GetId returns the interface-field "id" from its implementation. 44 // The GraphQL interface field's documentation follows. 45 // 46 // ID is the identifier of the content. 47 GetId() testutil.ID 48 // GetName returns the interface-field "name" from its implementation. 49 GetName() string 50 } 51 52 func (v *SimpleNamedFragmentRandomItemArticle) implementsGraphQLInterfaceSimpleNamedFragmentRandomItemContent() { 53 } 54 func (v *SimpleNamedFragmentRandomItemVideo) implementsGraphQLInterfaceSimpleNamedFragmentRandomItemContent() { 55 } 56 func (v *SimpleNamedFragmentRandomItemTopic) implementsGraphQLInterfaceSimpleNamedFragmentRandomItemContent() { 57 } 58 59 func __unmarshalSimpleNamedFragmentRandomItemContent(b []byte, v *SimpleNamedFragmentRandomItemContent) error { 60 if string(b) == "null" { 61 return nil 62 } 63 64 var tn struct { 65 TypeName string `json:"__typename"` 66 } 67 err := json.Unmarshal(b, &tn) 68 if err != nil { 69 return err 70 } 71 72 switch tn.TypeName { 73 case "Article": 74 *v = new(SimpleNamedFragmentRandomItemArticle) 75 return json.Unmarshal(b, *v) 76 case "Video": 77 *v = new(SimpleNamedFragmentRandomItemVideo) 78 return json.Unmarshal(b, *v) 79 case "Topic": 80 *v = new(SimpleNamedFragmentRandomItemTopic) 81 return json.Unmarshal(b, *v) 82 case "": 83 return fmt.Errorf( 84 "response was missing Content.__typename") 85 default: 86 return fmt.Errorf( 87 `unexpected concrete type for SimpleNamedFragmentRandomItemContent: "%v"`, tn.TypeName) 88 } 89 } 90 91 func __marshalSimpleNamedFragmentRandomItemContent(v *SimpleNamedFragmentRandomItemContent) ([]byte, error) { 92 93 var typename string 94 switch v := (*v).(type) { 95 case *SimpleNamedFragmentRandomItemArticle: 96 typename = "Article" 97 98 result := struct { 99 TypeName string `json:"__typename"` 100 *SimpleNamedFragmentRandomItemArticle 101 }{typename, v} 102 return json.Marshal(result) 103 case *SimpleNamedFragmentRandomItemVideo: 104 typename = "Video" 105 106 premarshaled, err := v.__premarshalJSON() 107 if err != nil { 108 return nil, err 109 } 110 result := struct { 111 TypeName string `json:"__typename"` 112 *__premarshalSimpleNamedFragmentRandomItemVideo 113 }{typename, premarshaled} 114 return json.Marshal(result) 115 case *SimpleNamedFragmentRandomItemTopic: 116 typename = "Topic" 117 118 result := struct { 119 TypeName string `json:"__typename"` 120 *SimpleNamedFragmentRandomItemTopic 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 SimpleNamedFragmentRandomItemContent: "%T"`, v) 128 } 129 } 130 131 // SimpleNamedFragmentRandomItemTopic includes the requested fields of the GraphQL type Topic. 132 type SimpleNamedFragmentRandomItemTopic 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 SimpleNamedFragmentRandomItemTopic.Typename, and is useful for accessing the field via an interface. 140 func (v *SimpleNamedFragmentRandomItemTopic) GetTypename() string { return v.Typename } 141 142 // GetId returns SimpleNamedFragmentRandomItemTopic.Id, and is useful for accessing the field via an interface. 143 func (v *SimpleNamedFragmentRandomItemTopic) GetId() testutil.ID { return v.Id } 144 145 // GetName returns SimpleNamedFragmentRandomItemTopic.Name, and is useful for accessing the field via an interface. 146 func (v *SimpleNamedFragmentRandomItemTopic) GetName() string { return v.Name } 147 148 // SimpleNamedFragmentRandomItemVideo includes the requested fields of the GraphQL type Video. 149 type SimpleNamedFragmentRandomItemVideo 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 VideoFields `json:"-"` 155 } 156 157 // GetTypename returns SimpleNamedFragmentRandomItemVideo.Typename, and is useful for accessing the field via an interface. 158 func (v *SimpleNamedFragmentRandomItemVideo) GetTypename() string { return v.Typename } 159 160 // GetId returns SimpleNamedFragmentRandomItemVideo.Id, and is useful for accessing the field via an interface. 161 func (v *SimpleNamedFragmentRandomItemVideo) GetId() testutil.ID { return v.Id } 162 163 // GetName returns SimpleNamedFragmentRandomItemVideo.Name, and is useful for accessing the field via an interface. 164 func (v *SimpleNamedFragmentRandomItemVideo) GetName() string { return v.Name } 165 166 // GetUrl returns SimpleNamedFragmentRandomItemVideo.Url, and is useful for accessing the field via an interface. 167 func (v *SimpleNamedFragmentRandomItemVideo) GetUrl() string { return v.VideoFields.Url } 168 169 // GetDuration returns SimpleNamedFragmentRandomItemVideo.Duration, and is useful for accessing the field via an interface. 170 func (v *SimpleNamedFragmentRandomItemVideo) GetDuration() int { return v.VideoFields.Duration } 171 172 // GetThumbnail returns SimpleNamedFragmentRandomItemVideo.Thumbnail, and is useful for accessing the field via an interface. 173 func (v *SimpleNamedFragmentRandomItemVideo) GetThumbnail() VideoFieldsThumbnail { 174 return v.VideoFields.Thumbnail 175 } 176 177 func (v *SimpleNamedFragmentRandomItemVideo) UnmarshalJSON(b []byte) error { 178 179 if string(b) == "null" { 180 return nil 181 } 182 183 var firstPass struct { 184 *SimpleNamedFragmentRandomItemVideo 185 graphql.NoUnmarshalJSON 186 } 187 firstPass.SimpleNamedFragmentRandomItemVideo = v 188 189 err := json.Unmarshal(b, &firstPass) 190 if err != nil { 191 return err 192 } 193 194 err = json.Unmarshal( 195 b, &v.VideoFields) 196 if err != nil { 197 return err 198 } 199 return nil 200 } 201 202 type __premarshalSimpleNamedFragmentRandomItemVideo struct { 203 Typename string `json:"__typename"` 204 205 Id testutil.ID `json:"id"` 206 207 Name string `json:"name"` 208 209 Url string `json:"url"` 210 211 Duration int `json:"duration"` 212 213 Thumbnail VideoFieldsThumbnail `json:"thumbnail"` 214 } 215 216 func (v *SimpleNamedFragmentRandomItemVideo) 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 *SimpleNamedFragmentRandomItemVideo) __premarshalJSON() (*__premarshalSimpleNamedFragmentRandomItemVideo, error) { 225 var retval __premarshalSimpleNamedFragmentRandomItemVideo 226 227 retval.Typename = v.Typename 228 retval.Id = v.Id 229 retval.Name = v.Name 230 retval.Url = v.VideoFields.Url 231 retval.Duration = v.VideoFields.Duration 232 retval.Thumbnail = v.VideoFields.Thumbnail 233 return &retval, nil 234 } 235 236 // SimpleNamedFragmentRandomLeafArticle includes the requested fields of the GraphQL type Article. 237 type SimpleNamedFragmentRandomLeafArticle struct { 238 Typename string `json:"__typename"` 239 } 240 241 // GetTypename returns SimpleNamedFragmentRandomLeafArticle.Typename, and is useful for accessing the field via an interface. 242 func (v *SimpleNamedFragmentRandomLeafArticle) GetTypename() string { return v.Typename } 243 244 // SimpleNamedFragmentRandomLeafLeafContent includes the requested fields of the GraphQL interface LeafContent. 245 // 246 // SimpleNamedFragmentRandomLeafLeafContent is implemented by the following types: 247 // SimpleNamedFragmentRandomLeafArticle 248 // SimpleNamedFragmentRandomLeafVideo 249 // The GraphQL type's documentation follows. 250 // 251 // LeafContent represents content items that can't have child-nodes. 252 type SimpleNamedFragmentRandomLeafLeafContent interface { 253 implementsGraphQLInterfaceSimpleNamedFragmentRandomLeafLeafContent() 254 // GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values). 255 GetTypename() string 256 } 257 258 func (v *SimpleNamedFragmentRandomLeafArticle) implementsGraphQLInterfaceSimpleNamedFragmentRandomLeafLeafContent() { 259 } 260 func (v *SimpleNamedFragmentRandomLeafVideo) implementsGraphQLInterfaceSimpleNamedFragmentRandomLeafLeafContent() { 261 } 262 263 func __unmarshalSimpleNamedFragmentRandomLeafLeafContent(b []byte, v *SimpleNamedFragmentRandomLeafLeafContent) error { 264 if string(b) == "null" { 265 return nil 266 } 267 268 var tn struct { 269 TypeName string `json:"__typename"` 270 } 271 err := json.Unmarshal(b, &tn) 272 if err != nil { 273 return err 274 } 275 276 switch tn.TypeName { 277 case "Article": 278 *v = new(SimpleNamedFragmentRandomLeafArticle) 279 return json.Unmarshal(b, *v) 280 case "Video": 281 *v = new(SimpleNamedFragmentRandomLeafVideo) 282 return json.Unmarshal(b, *v) 283 case "": 284 return fmt.Errorf( 285 "response was missing LeafContent.__typename") 286 default: 287 return fmt.Errorf( 288 `unexpected concrete type for SimpleNamedFragmentRandomLeafLeafContent: "%v"`, tn.TypeName) 289 } 290 } 291 292 func __marshalSimpleNamedFragmentRandomLeafLeafContent(v *SimpleNamedFragmentRandomLeafLeafContent) ([]byte, error) { 293 294 var typename string 295 switch v := (*v).(type) { 296 case *SimpleNamedFragmentRandomLeafArticle: 297 typename = "Article" 298 299 result := struct { 300 TypeName string `json:"__typename"` 301 *SimpleNamedFragmentRandomLeafArticle 302 }{typename, v} 303 return json.Marshal(result) 304 case *SimpleNamedFragmentRandomLeafVideo: 305 typename = "Video" 306 307 premarshaled, err := v.__premarshalJSON() 308 if err != nil { 309 return nil, err 310 } 311 result := struct { 312 TypeName string `json:"__typename"` 313 *__premarshalSimpleNamedFragmentRandomLeafVideo 314 }{typename, premarshaled} 315 return json.Marshal(result) 316 case nil: 317 return []byte("null"), nil 318 default: 319 return nil, fmt.Errorf( 320 `unexpected concrete type for SimpleNamedFragmentRandomLeafLeafContent: "%T"`, v) 321 } 322 } 323 324 // SimpleNamedFragmentRandomLeafVideo includes the requested fields of the GraphQL type Video. 325 type SimpleNamedFragmentRandomLeafVideo struct { 326 Typename string `json:"__typename"` 327 VideoFields `json:"-"` 328 } 329 330 // GetTypename returns SimpleNamedFragmentRandomLeafVideo.Typename, and is useful for accessing the field via an interface. 331 func (v *SimpleNamedFragmentRandomLeafVideo) GetTypename() string { return v.Typename } 332 333 // GetId returns SimpleNamedFragmentRandomLeafVideo.Id, and is useful for accessing the field via an interface. 334 func (v *SimpleNamedFragmentRandomLeafVideo) GetId() testutil.ID { return v.VideoFields.Id } 335 336 // GetName returns SimpleNamedFragmentRandomLeafVideo.Name, and is useful for accessing the field via an interface. 337 func (v *SimpleNamedFragmentRandomLeafVideo) GetName() string { return v.VideoFields.Name } 338 339 // GetUrl returns SimpleNamedFragmentRandomLeafVideo.Url, and is useful for accessing the field via an interface. 340 func (v *SimpleNamedFragmentRandomLeafVideo) GetUrl() string { return v.VideoFields.Url } 341 342 // GetDuration returns SimpleNamedFragmentRandomLeafVideo.Duration, and is useful for accessing the field via an interface. 343 func (v *SimpleNamedFragmentRandomLeafVideo) GetDuration() int { return v.VideoFields.Duration } 344 345 // GetThumbnail returns SimpleNamedFragmentRandomLeafVideo.Thumbnail, and is useful for accessing the field via an interface. 346 func (v *SimpleNamedFragmentRandomLeafVideo) GetThumbnail() VideoFieldsThumbnail { 347 return v.VideoFields.Thumbnail 348 } 349 350 func (v *SimpleNamedFragmentRandomLeafVideo) UnmarshalJSON(b []byte) error { 351 352 if string(b) == "null" { 353 return nil 354 } 355 356 var firstPass struct { 357 *SimpleNamedFragmentRandomLeafVideo 358 graphql.NoUnmarshalJSON 359 } 360 firstPass.SimpleNamedFragmentRandomLeafVideo = v 361 362 err := json.Unmarshal(b, &firstPass) 363 if err != nil { 364 return err 365 } 366 367 err = json.Unmarshal( 368 b, &v.VideoFields) 369 if err != nil { 370 return err 371 } 372 return nil 373 } 374 375 type __premarshalSimpleNamedFragmentRandomLeafVideo struct { 376 Typename string `json:"__typename"` 377 378 Id testutil.ID `json:"id"` 379 380 Name string `json:"name"` 381 382 Url string `json:"url"` 383 384 Duration int `json:"duration"` 385 386 Thumbnail VideoFieldsThumbnail `json:"thumbnail"` 387 } 388 389 func (v *SimpleNamedFragmentRandomLeafVideo) MarshalJSON() ([]byte, error) { 390 premarshaled, err := v.__premarshalJSON() 391 if err != nil { 392 return nil, err 393 } 394 return json.Marshal(premarshaled) 395 } 396 397 func (v *SimpleNamedFragmentRandomLeafVideo) __premarshalJSON() (*__premarshalSimpleNamedFragmentRandomLeafVideo, error) { 398 var retval __premarshalSimpleNamedFragmentRandomLeafVideo 399 400 retval.Typename = v.Typename 401 retval.Id = v.VideoFields.Id 402 retval.Name = v.VideoFields.Name 403 retval.Url = v.VideoFields.Url 404 retval.Duration = v.VideoFields.Duration 405 retval.Thumbnail = v.VideoFields.Thumbnail 406 return &retval, nil 407 } 408 409 // SimpleNamedFragmentResponse is returned by SimpleNamedFragment on success. 410 type SimpleNamedFragmentResponse struct { 411 RandomItem SimpleNamedFragmentRandomItemContent `json:"-"` 412 RandomLeaf SimpleNamedFragmentRandomLeafLeafContent `json:"-"` 413 } 414 415 // GetRandomItem returns SimpleNamedFragmentResponse.RandomItem, and is useful for accessing the field via an interface. 416 func (v *SimpleNamedFragmentResponse) GetRandomItem() SimpleNamedFragmentRandomItemContent { 417 return v.RandomItem 418 } 419 420 // GetRandomLeaf returns SimpleNamedFragmentResponse.RandomLeaf, and is useful for accessing the field via an interface. 421 func (v *SimpleNamedFragmentResponse) GetRandomLeaf() SimpleNamedFragmentRandomLeafLeafContent { 422 return v.RandomLeaf 423 } 424 425 func (v *SimpleNamedFragmentResponse) UnmarshalJSON(b []byte) error { 426 427 if string(b) == "null" { 428 return nil 429 } 430 431 var firstPass struct { 432 *SimpleNamedFragmentResponse 433 RandomItem json.RawMessage `json:"randomItem"` 434 RandomLeaf json.RawMessage `json:"randomLeaf"` 435 graphql.NoUnmarshalJSON 436 } 437 firstPass.SimpleNamedFragmentResponse = v 438 439 err := json.Unmarshal(b, &firstPass) 440 if err != nil { 441 return err 442 } 443 444 { 445 dst := &v.RandomItem 446 src := firstPass.RandomItem 447 if len(src) != 0 && string(src) != "null" { 448 err = __unmarshalSimpleNamedFragmentRandomItemContent( 449 src, dst) 450 if err != nil { 451 return fmt.Errorf( 452 "Unable to unmarshal SimpleNamedFragmentResponse.RandomItem: %w", err) 453 } 454 } 455 } 456 457 { 458 dst := &v.RandomLeaf 459 src := firstPass.RandomLeaf 460 if len(src) != 0 && string(src) != "null" { 461 err = __unmarshalSimpleNamedFragmentRandomLeafLeafContent( 462 src, dst) 463 if err != nil { 464 return fmt.Errorf( 465 "Unable to unmarshal SimpleNamedFragmentResponse.RandomLeaf: %w", err) 466 } 467 } 468 } 469 return nil 470 } 471 472 type __premarshalSimpleNamedFragmentResponse struct { 473 RandomItem json.RawMessage `json:"randomItem"` 474 475 RandomLeaf json.RawMessage `json:"randomLeaf"` 476 } 477 478 func (v *SimpleNamedFragmentResponse) MarshalJSON() ([]byte, error) { 479 premarshaled, err := v.__premarshalJSON() 480 if err != nil { 481 return nil, err 482 } 483 return json.Marshal(premarshaled) 484 } 485 486 func (v *SimpleNamedFragmentResponse) __premarshalJSON() (*__premarshalSimpleNamedFragmentResponse, error) { 487 var retval __premarshalSimpleNamedFragmentResponse 488 489 { 490 491 dst := &retval.RandomItem 492 src := v.RandomItem 493 var err error 494 *dst, err = __marshalSimpleNamedFragmentRandomItemContent( 495 &src) 496 if err != nil { 497 return nil, fmt.Errorf( 498 "Unable to marshal SimpleNamedFragmentResponse.RandomItem: %w", err) 499 } 500 } 501 { 502 503 dst := &retval.RandomLeaf 504 src := v.RandomLeaf 505 var err error 506 *dst, err = __marshalSimpleNamedFragmentRandomLeafLeafContent( 507 &src) 508 if err != nil { 509 return nil, fmt.Errorf( 510 "Unable to marshal SimpleNamedFragmentResponse.RandomLeaf: %w", err) 511 } 512 } 513 return &retval, nil 514 } 515 516 // VideoFields includes the GraphQL fields of Video requested by the fragment VideoFields. 517 type VideoFields struct { 518 // ID is documented in the Content interface. 519 Id testutil.ID `json:"id"` 520 Name string `json:"name"` 521 Url string `json:"url"` 522 Duration int `json:"duration"` 523 Thumbnail VideoFieldsThumbnail `json:"thumbnail"` 524 } 525 526 // GetId returns VideoFields.Id, and is useful for accessing the field via an interface. 527 func (v *VideoFields) GetId() testutil.ID { return v.Id } 528 529 // GetName returns VideoFields.Name, and is useful for accessing the field via an interface. 530 func (v *VideoFields) GetName() string { return v.Name } 531 532 // GetUrl returns VideoFields.Url, and is useful for accessing the field via an interface. 533 func (v *VideoFields) GetUrl() string { return v.Url } 534 535 // GetDuration returns VideoFields.Duration, and is useful for accessing the field via an interface. 536 func (v *VideoFields) GetDuration() int { return v.Duration } 537 538 // GetThumbnail returns VideoFields.Thumbnail, and is useful for accessing the field via an interface. 539 func (v *VideoFields) GetThumbnail() VideoFieldsThumbnail { return v.Thumbnail } 540 541 // VideoFieldsThumbnail includes the requested fields of the GraphQL type Thumbnail. 542 type VideoFieldsThumbnail struct { 543 Id testutil.ID `json:"id"` 544 } 545 546 // GetId returns VideoFieldsThumbnail.Id, and is useful for accessing the field via an interface. 547 func (v *VideoFieldsThumbnail) GetId() testutil.ID { return v.Id } 548 549 func SimpleNamedFragment( 550 client graphql.Client, 551 ) (*SimpleNamedFragmentResponse, error) { 552 req := &graphql.Request{ 553 OpName: "SimpleNamedFragment", 554 Query: ` 555 query SimpleNamedFragment { 556 randomItem { 557 __typename 558 id 559 name 560 ... VideoFields 561 } 562 randomLeaf { 563 __typename 564 ... VideoFields 565 } 566 } 567 fragment VideoFields on Video { 568 id 569 name 570 url 571 duration 572 thumbnail { 573 id 574 } 575 } 576 `, 577 } 578 var err error 579 580 var data SimpleNamedFragmentResponse 581 resp := &graphql.Response{Data: &data} 582 583 err = client.MakeRequest( 584 nil, 585 req, 586 resp, 587 ) 588 589 return &data, err 590 } 591