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