github.com/Desuuuu/genqlient@v0.5.3/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go (about) 1 // Code generated by github.com/Desuuuu/genqlient, DO NOT EDIT. 2 3 package test 4 5 import ( 6 "encoding/json" 7 "fmt" 8 9 "github.com/Desuuuu/genqlient/graphql" 10 "github.com/Desuuuu/genqlient/internal/testutil" 11 ) 12 13 // Role is a type a user may have. 14 type Role string 15 16 const ( 17 // What is a student? 18 // 19 // A student is primarily a person enrolled in a school or other educational institution and who is under learning with goals of acquiring knowledge, developing professions and achieving employment at desired field. In the broader sense, a student is anyone who applies themselves to the intensive intellectual engagement with some matter necessary to master it as part of some practical affair in which such mastery is basic or decisive. 20 // 21 // (from [Wikipedia](https://en.wikipedia.org/wiki/Student)) 22 RoleStudent Role = "STUDENT" 23 // Teacher is a teacher, who teaches the students. 24 RoleTeacher Role = "TEACHER" 25 ) 26 27 // StructOptionResponse is returned by StructOption on success. 28 type StructOptionResponse struct { 29 Root StructOptionRootTopic `json:"root"` 30 // user looks up a user by some stuff. 31 // 32 // See UserQueryInput for what stuff is supported. 33 // If query is null, returns the current user. 34 User StructOptionUser `json:"user"` 35 } 36 37 // GetRoot returns StructOptionResponse.Root, and is useful for accessing the field via an interface. 38 func (v *StructOptionResponse) GetRoot() StructOptionRootTopic { return v.Root } 39 40 // GetUser returns StructOptionResponse.User, and is useful for accessing the field via an interface. 41 func (v *StructOptionResponse) GetUser() StructOptionUser { return v.User } 42 43 // StructOptionRootTopic includes the requested fields of the GraphQL type Topic. 44 type StructOptionRootTopic struct { 45 // ID is documented in the Content interface. 46 Id testutil.ID `json:"id"` 47 Children []StructOptionRootTopicChildrenContent `json:"children"` 48 } 49 50 // GetId returns StructOptionRootTopic.Id, and is useful for accessing the field via an interface. 51 func (v *StructOptionRootTopic) GetId() testutil.ID { return v.Id } 52 53 // GetChildren returns StructOptionRootTopic.Children, and is useful for accessing the field via an interface. 54 func (v *StructOptionRootTopic) GetChildren() []StructOptionRootTopicChildrenContent { 55 return v.Children 56 } 57 58 // StructOptionRootTopicChildrenContent includes the requested fields of the GraphQL type Content. 59 // The GraphQL type's documentation follows. 60 // 61 // Content is implemented by various types like Article, Video, and Topic. 62 type StructOptionRootTopicChildrenContent struct { 63 Typename string `json:"__typename"` 64 // ID is the identifier of the content. 65 Id testutil.ID `json:"id"` 66 Parent StructOptionRootTopicChildrenContentParentTopic `json:"parent"` 67 } 68 69 // GetTypename returns StructOptionRootTopicChildrenContent.Typename, and is useful for accessing the field via an interface. 70 func (v *StructOptionRootTopicChildrenContent) GetTypename() string { return v.Typename } 71 72 // GetId returns StructOptionRootTopicChildrenContent.Id, and is useful for accessing the field via an interface. 73 func (v *StructOptionRootTopicChildrenContent) GetId() testutil.ID { return v.Id } 74 75 // GetParent returns StructOptionRootTopicChildrenContent.Parent, and is useful for accessing the field via an interface. 76 func (v *StructOptionRootTopicChildrenContent) GetParent() StructOptionRootTopicChildrenContentParentTopic { 77 return v.Parent 78 } 79 80 // StructOptionRootTopicChildrenContentParentTopic includes the requested fields of the GraphQL type Topic. 81 type StructOptionRootTopicChildrenContentParentTopic struct { 82 // ID is documented in the Content interface. 83 Id testutil.ID `json:"id"` 84 Children []StructOptionRootTopicChildrenContentParentTopicChildrenContent `json:"children"` 85 InterfaceChildren []StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent `json:"-"` 86 } 87 88 // GetId returns StructOptionRootTopicChildrenContentParentTopic.Id, and is useful for accessing the field via an interface. 89 func (v *StructOptionRootTopicChildrenContentParentTopic) GetId() testutil.ID { return v.Id } 90 91 // GetChildren returns StructOptionRootTopicChildrenContentParentTopic.Children, and is useful for accessing the field via an interface. 92 func (v *StructOptionRootTopicChildrenContentParentTopic) GetChildren() []StructOptionRootTopicChildrenContentParentTopicChildrenContent { 93 return v.Children 94 } 95 96 // GetInterfaceChildren returns StructOptionRootTopicChildrenContentParentTopic.InterfaceChildren, and is useful for accessing the field via an interface. 97 func (v *StructOptionRootTopicChildrenContentParentTopic) GetInterfaceChildren() []StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent { 98 return v.InterfaceChildren 99 } 100 101 func (v *StructOptionRootTopicChildrenContentParentTopic) UnmarshalJSON(b []byte) error { 102 103 if string(b) == "null" { 104 return nil 105 } 106 107 var firstPass struct { 108 *StructOptionRootTopicChildrenContentParentTopic 109 InterfaceChildren []json.RawMessage `json:"interfaceChildren"` 110 graphql.NoUnmarshalJSON 111 } 112 firstPass.StructOptionRootTopicChildrenContentParentTopic = v 113 114 err := json.Unmarshal(b, &firstPass) 115 if err != nil { 116 return err 117 } 118 119 { 120 dst := &v.InterfaceChildren 121 src := firstPass.InterfaceChildren 122 *dst = make( 123 []StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent, 124 len(src)) 125 for i, src := range src { 126 dst := &(*dst)[i] 127 if len(src) != 0 && string(src) != "null" { 128 err = __unmarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent( 129 src, dst) 130 if err != nil { 131 return fmt.Errorf( 132 "Unable to unmarshal StructOptionRootTopicChildrenContentParentTopic.InterfaceChildren: %w", err) 133 } 134 } 135 } 136 } 137 return nil 138 } 139 140 type __premarshalStructOptionRootTopicChildrenContentParentTopic struct { 141 Id testutil.ID `json:"id"` 142 143 Children []StructOptionRootTopicChildrenContentParentTopicChildrenContent `json:"children"` 144 145 InterfaceChildren []json.RawMessage `json:"interfaceChildren"` 146 } 147 148 func (v *StructOptionRootTopicChildrenContentParentTopic) MarshalJSON() ([]byte, error) { 149 premarshaled, err := v.__premarshalJSON() 150 if err != nil { 151 return nil, err 152 } 153 return json.Marshal(premarshaled) 154 } 155 156 func (v *StructOptionRootTopicChildrenContentParentTopic) __premarshalJSON() (*__premarshalStructOptionRootTopicChildrenContentParentTopic, error) { 157 var retval __premarshalStructOptionRootTopicChildrenContentParentTopic 158 159 retval.Id = v.Id 160 retval.Children = v.Children 161 { 162 163 dst := &retval.InterfaceChildren 164 src := v.InterfaceChildren 165 *dst = make( 166 []json.RawMessage, 167 len(src)) 168 for i, src := range src { 169 dst := &(*dst)[i] 170 var err error 171 *dst, err = __marshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent( 172 &src) 173 if err != nil { 174 return nil, fmt.Errorf( 175 "Unable to marshal StructOptionRootTopicChildrenContentParentTopic.InterfaceChildren: %w", err) 176 } 177 } 178 } 179 return &retval, nil 180 } 181 182 // StructOptionRootTopicChildrenContentParentTopicChildrenContent includes the requested fields of the GraphQL type Content. 183 // The GraphQL type's documentation follows. 184 // 185 // Content is implemented by various types like Article, Video, and Topic. 186 type StructOptionRootTopicChildrenContentParentTopicChildrenContent struct { 187 Typename string `json:"__typename"` 188 // ID is the identifier of the content. 189 Id testutil.ID `json:"id"` 190 } 191 192 // GetTypename returns StructOptionRootTopicChildrenContentParentTopicChildrenContent.Typename, and is useful for accessing the field via an interface. 193 func (v *StructOptionRootTopicChildrenContentParentTopicChildrenContent) GetTypename() string { 194 return v.Typename 195 } 196 197 // GetId returns StructOptionRootTopicChildrenContentParentTopicChildrenContent.Id, and is useful for accessing the field via an interface. 198 func (v *StructOptionRootTopicChildrenContentParentTopicChildrenContent) GetId() testutil.ID { 199 return v.Id 200 } 201 202 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle includes the requested fields of the GraphQL type Article. 203 type StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle struct { 204 Typename string `json:"__typename"` 205 // ID is the identifier of the content. 206 Id testutil.ID `json:"id"` 207 } 208 209 // GetTypename returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle.Typename, and is useful for accessing the field via an interface. 210 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) GetTypename() string { 211 return v.Typename 212 } 213 214 // GetId returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle.Id, and is useful for accessing the field via an interface. 215 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) GetId() testutil.ID { 216 return v.Id 217 } 218 219 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent includes the requested fields of the GraphQL interface Content. 220 // 221 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent is implemented by the following types: 222 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle 223 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 224 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic 225 // The GraphQL type's documentation follows. 226 // 227 // Content is implemented by various types like Article, Video, and Topic. 228 type StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent interface { 229 implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() 230 // GetTypename returns the receiver's concrete GraphQL type-name (see interface doc for possible values). 231 GetTypename() string 232 // GetId returns the interface-field "id" from its implementation. 233 // The GraphQL interface field's documentation follows. 234 // 235 // ID is the identifier of the content. 236 GetId() testutil.ID 237 GetContentArticle() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle, bool) 238 GetContentVideo() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo, bool) 239 GetContentTopic() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic, bool) 240 } 241 242 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() { 243 } 244 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) GetContentArticle() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle, bool) { 245 return v, true 246 } 247 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) GetContentVideo() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo, bool) { 248 return nil, false 249 } 250 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) GetContentTopic() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic, bool) { 251 return nil, false 252 } 253 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() { 254 } 255 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetContentArticle() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle, bool) { 256 return nil, false 257 } 258 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetContentVideo() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo, bool) { 259 return v, true 260 } 261 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetContentTopic() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic, bool) { 262 return nil, false 263 } 264 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() { 265 } 266 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) GetContentArticle() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle, bool) { 267 return nil, false 268 } 269 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) GetContentVideo() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo, bool) { 270 return nil, false 271 } 272 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) GetContentTopic() (*StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic, bool) { 273 return v, true 274 } 275 276 func __unmarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent(b []byte, v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent) error { 277 if string(b) == "null" { 278 return nil 279 } 280 281 var tn struct { 282 TypeName string `json:"__typename"` 283 } 284 err := json.Unmarshal(b, &tn) 285 if err != nil { 286 return err 287 } 288 289 switch tn.TypeName { 290 case "Article": 291 *v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) 292 return json.Unmarshal(b, *v) 293 case "Video": 294 *v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) 295 return json.Unmarshal(b, *v) 296 case "Topic": 297 *v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) 298 return json.Unmarshal(b, *v) 299 case "": 300 return fmt.Errorf( 301 "response was missing Content.__typename") 302 default: 303 return fmt.Errorf( 304 `unexpected concrete type for StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent: "%v"`, tn.TypeName) 305 } 306 } 307 308 func __marshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent(v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent) ([]byte, error) { 309 310 var typename string 311 switch v := (*v).(type) { 312 case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle: 313 typename = "Article" 314 315 result := struct { 316 TypeName string `json:"__typename"` 317 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle 318 }{typename, v} 319 return json.Marshal(result) 320 case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo: 321 typename = "Video" 322 323 premarshaled, err := v.__premarshalJSON() 324 if err != nil { 325 return nil, err 326 } 327 result := struct { 328 TypeName string `json:"__typename"` 329 *__premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 330 }{typename, premarshaled} 331 return json.Marshal(result) 332 case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic: 333 typename = "Topic" 334 335 result := struct { 336 TypeName string `json:"__typename"` 337 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic 338 }{typename, v} 339 return json.Marshal(result) 340 case nil: 341 return []byte("null"), nil 342 default: 343 return nil, fmt.Errorf( 344 `unexpected concrete type for StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent: "%T"`, v) 345 } 346 } 347 348 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic includes the requested fields of the GraphQL type Topic. 349 type StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic struct { 350 Typename string `json:"__typename"` 351 // ID is the identifier of the content. 352 Id testutil.ID `json:"id"` 353 } 354 355 // GetTypename returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic.Typename, and is useful for accessing the field via an interface. 356 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) GetTypename() string { 357 return v.Typename 358 } 359 360 // GetId returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic.Id, and is useful for accessing the field via an interface. 361 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) GetId() testutil.ID { 362 return v.Id 363 } 364 365 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo includes the requested fields of the GraphQL type Video. 366 type StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo struct { 367 Typename string `json:"__typename"` 368 // ID is the identifier of the content. 369 Id testutil.ID `json:"id"` 370 VideoFields `json:"-"` 371 } 372 373 // GetTypename returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo.Typename, and is useful for accessing the field via an interface. 374 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetTypename() string { 375 return v.Typename 376 } 377 378 // GetId returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo.Id, and is useful for accessing the field via an interface. 379 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetId() testutil.ID { 380 return v.Id 381 } 382 383 // GetDuration returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo.Duration, and is useful for accessing the field via an interface. 384 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetDuration() int { 385 return v.VideoFields.Duration 386 } 387 388 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) UnmarshalJSON(b []byte) error { 389 390 if string(b) == "null" { 391 return nil 392 } 393 394 var firstPass struct { 395 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 396 graphql.NoUnmarshalJSON 397 } 398 firstPass.StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo = v 399 400 err := json.Unmarshal(b, &firstPass) 401 if err != nil { 402 return err 403 } 404 405 err = json.Unmarshal( 406 b, &v.VideoFields) 407 if err != nil { 408 return err 409 } 410 return nil 411 } 412 413 type __premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo struct { 414 Typename string `json:"__typename"` 415 416 Id testutil.ID `json:"id"` 417 418 Duration int `json:"duration"` 419 } 420 421 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) MarshalJSON() ([]byte, error) { 422 premarshaled, err := v.__premarshalJSON() 423 if err != nil { 424 return nil, err 425 } 426 return json.Marshal(premarshaled) 427 } 428 429 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) __premarshalJSON() (*__premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo, error) { 430 var retval __premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 431 432 retval.Typename = v.Typename 433 retval.Id = v.Id 434 retval.Duration = v.VideoFields.Duration 435 return &retval, nil 436 } 437 438 // StructOptionUser includes the requested fields of the GraphQL type User. 439 // The GraphQL type's documentation follows. 440 // 441 // A User is a user! 442 type StructOptionUser struct { 443 Roles []Role `json:"roles"` 444 } 445 446 // GetRoles returns StructOptionUser.Roles, and is useful for accessing the field via an interface. 447 func (v *StructOptionUser) GetRoles() []Role { return v.Roles } 448 449 // VideoFields includes the GraphQL fields of Video requested by the fragment VideoFields. 450 type VideoFields struct { 451 Duration int `json:"duration"` 452 } 453 454 // GetDuration returns VideoFields.Duration, and is useful for accessing the field via an interface. 455 func (v *VideoFields) GetDuration() int { return v.Duration } 456 457 func StructOption( 458 client graphql.Client, 459 ) (*StructOptionResponse, error) { 460 req := &graphql.Request{ 461 OpName: "StructOption", 462 Query: ` 463 query StructOption { 464 root { 465 id 466 children { 467 __typename 468 id 469 parent { 470 id 471 children { 472 __typename 473 id 474 } 475 interfaceChildren: children { 476 __typename 477 id 478 ... VideoFields 479 } 480 } 481 } 482 } 483 user { 484 roles 485 } 486 } 487 fragment VideoFields on Video { 488 duration 489 } 490 `, 491 } 492 var err error 493 494 var data StructOptionResponse 495 resp := &graphql.Response{Data: &data} 496 497 err = client.MakeRequest( 498 nil, 499 req, 500 resp, 501 ) 502 503 return &data, err 504 } 505