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