github.com/codykaup/genqlient@v0.6.2/generate/testdata/snapshots/TestGenerate-StructOption.graphql-StructOption.graphql.go (about) 1 // Code generated by github.com/codykaup/genqlient, DO NOT EDIT. 2 3 package test 4 5 import ( 6 "encoding/json" 7 "fmt" 8 9 "github.com/codykaup/genqlient/graphql" 10 "github.com/codykaup/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 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic 224 // StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 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 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) implementsGraphQLInterfaceStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenContent() { 242 } 243 func (v *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) 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 "Topic": 264 *v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic) 265 return json.Unmarshal(b, *v) 266 case "Video": 267 *v = new(StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo) 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 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic: 291 typename = "Topic" 292 293 result := struct { 294 TypeName string `json:"__typename"` 295 *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenTopic 296 }{typename, v} 297 return json.Marshal(result) 298 case *StructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo: 299 typename = "Video" 300 301 premarshaled, err := v.__premarshalJSON() 302 if err != nil { 303 return nil, err 304 } 305 result := struct { 306 TypeName string `json:"__typename"` 307 *__premarshalStructOptionRootTopicChildrenContentParentTopicInterfaceChildrenVideo 308 }{typename, premarshaled} 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 // The query or mutation executed by StructOption. 428 const StructOption_Operation = ` 429 query StructOption { 430 root { 431 id 432 children { 433 __typename 434 id 435 parent { 436 id 437 children { 438 __typename 439 id 440 } 441 interfaceChildren: children { 442 __typename 443 id 444 ... VideoFields 445 } 446 } 447 } 448 } 449 user { 450 roles 451 } 452 } 453 fragment VideoFields on Video { 454 duration 455 } 456 ` 457 458 func StructOption( 459 client_ graphql.Client, 460 ) (*StructOptionResponse, error) { 461 req_ := &graphql.Request{ 462 OpName: "StructOption", 463 Query: StructOption_Operation, 464 } 465 var err_ error 466 467 var data_ StructOptionResponse 468 resp_ := &graphql.Response{Data: &data_} 469 470 err_ = client_.MakeRequest( 471 nil, 472 req_, 473 resp_, 474 ) 475 476 return &data_, err_ 477 } 478