github.com/opiuman/genqlient@v1.0.0/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.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 // 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 } 238 239 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() { 240 } 241 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() { 242 } 243 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() { 244 } 245 246 func __unmarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent(b []byte, v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent) error { 247 if string(b) == "null" { 248 return nil 249 } 250 251 var tn struct { 252 TypeName string `json:"__typename"` 253 } 254 err := json.Unmarshal(b, &tn) 255 if err != nil { 256 return err 257 } 258 259 switch tn.TypeName { 260 case "Article": 261 *v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle) 262 return json.Unmarshal(b, *v) 263 case "Video": 264 *v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) 265 return json.Unmarshal(b, *v) 266 case "Topic": 267 *v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) 268 return json.Unmarshal(b, *v) 269 case "": 270 return fmt.Errorf( 271 "response was missing Content.__typename") 272 default: 273 return fmt.Errorf( 274 `unexpected concrete type for StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent: "%v"`, tn.TypeName) 275 } 276 } 277 278 func __marshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent(v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent) ([]byte, error) { 279 280 var typename string 281 switch v := (*v).(type) { 282 case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle: 283 typename = "Article" 284 285 result := struct { 286 TypeName string `json:"__typename"` 287 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenArticle 288 }{typename, v} 289 return json.Marshal(result) 290 case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo: 291 typename = "Video" 292 293 premarshaled, err := v.__premarshalJSON() 294 if err != nil { 295 return nil, err 296 } 297 result := struct { 298 TypeName string `json:"__typename"` 299 *__premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 300 }{typename, premarshaled} 301 return json.Marshal(result) 302 case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic: 303 typename = "Topic" 304 305 result := struct { 306 TypeName string `json:"__typename"` 307 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic 308 }{typename, v} 309 return json.Marshal(result) 310 case nil: 311 return []byte("null"), nil 312 default: 313 return nil, fmt.Errorf( 314 `unexpected concrete type for StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent: "%T"`, v) 315 } 316 } 317 318 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic includes the requested fields of the GraphQL type Topic. 319 type StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic struct { 320 Typename string `json:"__typename"` 321 // ID is the identifier of the content. 322 Id testutil.ID `json:"id"` 323 } 324 325 // GetTypename returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic.Typename, and is useful for accessing the field via an interface. 326 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) GetTypename() string { 327 return v.Typename 328 } 329 330 // GetId returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic.Id, and is useful for accessing the field via an interface. 331 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) GetId() testutil.ID { 332 return v.Id 333 } 334 335 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo includes the requested fields of the GraphQL type Video. 336 type StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo struct { 337 Typename string `json:"__typename"` 338 // ID is the identifier of the content. 339 Id testutil.ID `json:"id"` 340 VideoFields `json:"-"` 341 } 342 343 // GetTypename returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo.Typename, and is useful for accessing the field via an interface. 344 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetTypename() string { 345 return v.Typename 346 } 347 348 // GetId returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo.Id, and is useful for accessing the field via an interface. 349 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetId() testutil.ID { 350 return v.Id 351 } 352 353 // GetDuration returns StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo.Duration, and is useful for accessing the field via an interface. 354 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) GetDuration() int { 355 return v.VideoFields.Duration 356 } 357 358 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) UnmarshalJSON(b []byte) error { 359 360 if string(b) == "null" { 361 return nil 362 } 363 364 var firstPass struct { 365 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 366 graphql.NoUnmarshalJSON 367 } 368 firstPass.StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo = v 369 370 err := json.Unmarshal(b, &firstPass) 371 if err != nil { 372 return err 373 } 374 375 err = json.Unmarshal( 376 b, &v.VideoFields) 377 if err != nil { 378 return err 379 } 380 return nil 381 } 382 383 type __premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo struct { 384 Typename string `json:"__typename"` 385 386 Id testutil.ID `json:"id"` 387 388 Duration int `json:"duration"` 389 } 390 391 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) MarshalJSON() ([]byte, error) { 392 premarshaled, err := v.__premarshalJSON() 393 if err != nil { 394 return nil, err 395 } 396 return json.Marshal(premarshaled) 397 } 398 399 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) __premarshalJSON() (*__premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo, error) { 400 var retval __premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 401 402 retval.Typename = v.Typename 403 retval.Id = v.Id 404 retval.Duration = v.VideoFields.Duration 405 return &retval, nil 406 } 407 408 // StructOptionUser includes the requested fields of the GraphQL type User. 409 // The GraphQL type's documentation follows. 410 // 411 // A User is a user! 412 type StructOptionUser struct { 413 Roles []Role `json:"roles"` 414 } 415 416 // GetRoles returns StructOptionUser.Roles, and is useful for accessing the field via an interface. 417 func (v *StructOptionUser) GetRoles() []Role { return v.Roles } 418 419 // VideoFields includes the GraphQL fields of Video requested by the fragment VideoFields. 420 type VideoFields struct { 421 Duration int `json:"duration"` 422 } 423 424 // GetDuration returns VideoFields.Duration, and is useful for accessing the field via an interface. 425 func (v *VideoFields) GetDuration() int { return v.Duration } 426 427 func StructOption( 428 client graphql.Client, 429 ) (*StructOptionResponse, error) { 430 req := &graphql.Request{ 431 OpName: "StructOption", 432 Query: ` 433 query StructOption { 434 root { 435 id 436 children { 437 __typename 438 id 439 parent { 440 id 441 children { 442 __typename 443 id 444 } 445 interfaceChildren: children { 446 __typename 447 id 448 ... VideoFields 449 } 450 } 451 } 452 } 453 user { 454 roles 455 } 456 } 457 fragment VideoFields on Video { 458 duration 459 } 460 `, 461 } 462 var err error 463 464 var data StructOptionResponse 465 resp := &graphql.Response{Data: &data} 466 467 err = client.MakeRequest( 468 nil, 469 req, 470 resp, 471 ) 472 473 return &data, err 474 } 475