github.com/Desuuuu/genqlient@v0.5.3/generate/testdata/snapshots/TestGenerate-MultipleDirectives.graphql-MultipleDirectives.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 "time" 9 10 "github.com/Desuuuu/genqlient/graphql" 11 "github.com/Desuuuu/genqlient/internal/testutil" 12 ) 13 14 // UserQueryInput is the argument to Query.users. 15 // 16 // Ideally this would support anything and everything! 17 // Or maybe ideally it wouldn't. 18 // Really I'm just talking to make this documentation longer. 19 type MyInput struct { 20 Email *string `json:"email,omitempty"` 21 Name *string `json:"name,omitempty"` 22 // id looks the user up by ID. It's a great way to look up users. 23 Id *testutil.ID `json:"id,omitempty"` 24 Role *Role `json:"role,omitempty"` 25 Names []*string `json:"names,omitempty"` 26 HasPokemon *testutil.Pokemon `json:"hasPokemon,omitempty"` 27 Birthdate *time.Time `json:"-"` 28 } 29 30 // GetEmail returns MyInput.Email, and is useful for accessing the field via an interface. 31 func (v *MyInput) GetEmail() *string { return v.Email } 32 33 // GetName returns MyInput.Name, and is useful for accessing the field via an interface. 34 func (v *MyInput) GetName() *string { return v.Name } 35 36 // GetId returns MyInput.Id, and is useful for accessing the field via an interface. 37 func (v *MyInput) GetId() *testutil.ID { return v.Id } 38 39 // GetRole returns MyInput.Role, and is useful for accessing the field via an interface. 40 func (v *MyInput) GetRole() *Role { return v.Role } 41 42 // GetNames returns MyInput.Names, and is useful for accessing the field via an interface. 43 func (v *MyInput) GetNames() []*string { return v.Names } 44 45 // GetHasPokemon returns MyInput.HasPokemon, and is useful for accessing the field via an interface. 46 func (v *MyInput) GetHasPokemon() *testutil.Pokemon { return v.HasPokemon } 47 48 // GetBirthdate returns MyInput.Birthdate, and is useful for accessing the field via an interface. 49 func (v *MyInput) GetBirthdate() *time.Time { return v.Birthdate } 50 51 func (v *MyInput) UnmarshalJSON(b []byte) error { 52 53 if string(b) == "null" { 54 return nil 55 } 56 57 var firstPass struct { 58 *MyInput 59 Birthdate json.RawMessage `json:"birthdate"` 60 graphql.NoUnmarshalJSON 61 } 62 firstPass.MyInput = v 63 64 err := json.Unmarshal(b, &firstPass) 65 if err != nil { 66 return err 67 } 68 69 { 70 dst := &v.Birthdate 71 src := firstPass.Birthdate 72 if len(src) != 0 && string(src) != "null" { 73 *dst = new(time.Time) 74 err = testutil.UnmarshalDate( 75 src, *dst) 76 if err != nil { 77 return fmt.Errorf( 78 "Unable to unmarshal MyInput.Birthdate: %w", err) 79 } 80 } 81 } 82 return nil 83 } 84 85 type __premarshalMyInput struct { 86 Email *string `json:"email"` 87 88 Name *string `json:"name"` 89 90 Id *testutil.ID `json:"id"` 91 92 Role *Role `json:"role"` 93 94 Names []*string `json:"names"` 95 96 HasPokemon *testutil.Pokemon `json:"hasPokemon"` 97 98 Birthdate json.RawMessage `json:"birthdate"` 99 } 100 101 func (v *MyInput) MarshalJSON() ([]byte, error) { 102 premarshaled, err := v.__premarshalJSON() 103 if err != nil { 104 return nil, err 105 } 106 return json.Marshal(premarshaled) 107 } 108 109 func (v *MyInput) __premarshalJSON() (*__premarshalMyInput, error) { 110 var retval __premarshalMyInput 111 112 retval.Email = v.Email 113 retval.Name = v.Name 114 retval.Id = v.Id 115 retval.Role = v.Role 116 retval.Names = v.Names 117 retval.HasPokemon = v.HasPokemon 118 { 119 120 dst := &retval.Birthdate 121 src := v.Birthdate 122 if src != nil { 123 var err error 124 *dst, err = testutil.MarshalDate( 125 src) 126 if err != nil { 127 return nil, fmt.Errorf( 128 "Unable to marshal MyInput.Birthdate: %w", err) 129 } 130 } 131 } 132 return &retval, nil 133 } 134 135 // MyMultipleDirectivesResponse is returned by MultipleDirectives on success. 136 type MyMultipleDirectivesResponse struct { 137 // user looks up a user by some stuff. 138 // 139 // See UserQueryInput for what stuff is supported. 140 // If query is null, returns the current user. 141 User *MyMultipleDirectivesResponseUser `json:"user"` 142 Users []*MyMultipleDirectivesResponseUsersUser `json:"users"` 143 } 144 145 // GetUser returns MyMultipleDirectivesResponse.User, and is useful for accessing the field via an interface. 146 func (v *MyMultipleDirectivesResponse) GetUser() *MyMultipleDirectivesResponseUser { return v.User } 147 148 // GetUsers returns MyMultipleDirectivesResponse.Users, and is useful for accessing the field via an interface. 149 func (v *MyMultipleDirectivesResponse) GetUsers() []*MyMultipleDirectivesResponseUsersUser { 150 return v.Users 151 } 152 153 // MyMultipleDirectivesResponseUser includes the requested fields of the GraphQL type User. 154 // The GraphQL type's documentation follows. 155 // 156 // A User is a user! 157 type MyMultipleDirectivesResponseUser struct { 158 // id is the user's ID. 159 // 160 // It is stable, unique, and opaque, like all good IDs. 161 Id *testutil.ID `json:"id"` 162 } 163 164 // GetId returns MyMultipleDirectivesResponseUser.Id, and is useful for accessing the field via an interface. 165 func (v *MyMultipleDirectivesResponseUser) GetId() *testutil.ID { return v.Id } 166 167 // MyMultipleDirectivesResponseUsersUser includes the requested fields of the GraphQL type User. 168 // The GraphQL type's documentation follows. 169 // 170 // A User is a user! 171 type MyMultipleDirectivesResponseUsersUser struct { 172 // id is the user's ID. 173 // 174 // It is stable, unique, and opaque, like all good IDs. 175 Id *testutil.ID `json:"id"` 176 } 177 178 // GetId returns MyMultipleDirectivesResponseUsersUser.Id, and is useful for accessing the field via an interface. 179 func (v *MyMultipleDirectivesResponseUsersUser) GetId() *testutil.ID { return v.Id } 180 181 // Role is a type a user may have. 182 type Role string 183 184 const ( 185 // What is a student? 186 // 187 // 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. 188 // 189 // (from [Wikipedia](https://en.wikipedia.org/wiki/Student)) 190 RoleStudent Role = "STUDENT" 191 // Teacher is a teacher, who teaches the students. 192 RoleTeacher Role = "TEACHER" 193 ) 194 195 // UserQueryInput is the argument to Query.users. 196 // 197 // Ideally this would support anything and everything! 198 // Or maybe ideally it wouldn't. 199 // Really I'm just talking to make this documentation longer. 200 type UserQueryInput struct { 201 Email *string `json:"email,omitempty"` 202 Name *string `json:"name,omitempty"` 203 // id looks the user up by ID. It's a great way to look up users. 204 Id *testutil.ID `json:"id,omitempty"` 205 Role *Role `json:"role,omitempty"` 206 Names []*string `json:"names,omitempty"` 207 HasPokemon *testutil.Pokemon `json:"hasPokemon,omitempty"` 208 Birthdate *time.Time `json:"-"` 209 } 210 211 // GetEmail returns UserQueryInput.Email, and is useful for accessing the field via an interface. 212 func (v *UserQueryInput) GetEmail() *string { return v.Email } 213 214 // GetName returns UserQueryInput.Name, and is useful for accessing the field via an interface. 215 func (v *UserQueryInput) GetName() *string { return v.Name } 216 217 // GetId returns UserQueryInput.Id, and is useful for accessing the field via an interface. 218 func (v *UserQueryInput) GetId() *testutil.ID { return v.Id } 219 220 // GetRole returns UserQueryInput.Role, and is useful for accessing the field via an interface. 221 func (v *UserQueryInput) GetRole() *Role { return v.Role } 222 223 // GetNames returns UserQueryInput.Names, and is useful for accessing the field via an interface. 224 func (v *UserQueryInput) GetNames() []*string { return v.Names } 225 226 // GetHasPokemon returns UserQueryInput.HasPokemon, and is useful for accessing the field via an interface. 227 func (v *UserQueryInput) GetHasPokemon() *testutil.Pokemon { return v.HasPokemon } 228 229 // GetBirthdate returns UserQueryInput.Birthdate, and is useful for accessing the field via an interface. 230 func (v *UserQueryInput) GetBirthdate() *time.Time { return v.Birthdate } 231 232 func (v *UserQueryInput) UnmarshalJSON(b []byte) error { 233 234 if string(b) == "null" { 235 return nil 236 } 237 238 var firstPass struct { 239 *UserQueryInput 240 Birthdate json.RawMessage `json:"birthdate"` 241 graphql.NoUnmarshalJSON 242 } 243 firstPass.UserQueryInput = v 244 245 err := json.Unmarshal(b, &firstPass) 246 if err != nil { 247 return err 248 } 249 250 { 251 dst := &v.Birthdate 252 src := firstPass.Birthdate 253 if len(src) != 0 && string(src) != "null" { 254 *dst = new(time.Time) 255 err = testutil.UnmarshalDate( 256 src, *dst) 257 if err != nil { 258 return fmt.Errorf( 259 "Unable to unmarshal UserQueryInput.Birthdate: %w", err) 260 } 261 } 262 } 263 return nil 264 } 265 266 type __premarshalUserQueryInput struct { 267 Email *string `json:"email"` 268 269 Name *string `json:"name"` 270 271 Id *testutil.ID `json:"id"` 272 273 Role *Role `json:"role"` 274 275 Names []*string `json:"names"` 276 277 HasPokemon *testutil.Pokemon `json:"hasPokemon"` 278 279 Birthdate json.RawMessage `json:"birthdate"` 280 } 281 282 func (v *UserQueryInput) MarshalJSON() ([]byte, error) { 283 premarshaled, err := v.__premarshalJSON() 284 if err != nil { 285 return nil, err 286 } 287 return json.Marshal(premarshaled) 288 } 289 290 func (v *UserQueryInput) __premarshalJSON() (*__premarshalUserQueryInput, error) { 291 var retval __premarshalUserQueryInput 292 293 retval.Email = v.Email 294 retval.Name = v.Name 295 retval.Id = v.Id 296 retval.Role = v.Role 297 retval.Names = v.Names 298 retval.HasPokemon = v.HasPokemon 299 { 300 301 dst := &retval.Birthdate 302 src := v.Birthdate 303 if src != nil { 304 var err error 305 *dst, err = testutil.MarshalDate( 306 src) 307 if err != nil { 308 return nil, fmt.Errorf( 309 "Unable to marshal UserQueryInput.Birthdate: %w", err) 310 } 311 } 312 } 313 return &retval, nil 314 } 315 316 // __MultipleDirectivesInput is used internally by genqlient 317 type __MultipleDirectivesInput struct { 318 Query MyInput `json:"query,omitempty"` 319 Queries []*UserQueryInput `json:"queries,omitempty"` 320 } 321 322 // GetQuery returns __MultipleDirectivesInput.Query, and is useful for accessing the field via an interface. 323 func (v *__MultipleDirectivesInput) GetQuery() MyInput { return v.Query } 324 325 // GetQueries returns __MultipleDirectivesInput.Queries, and is useful for accessing the field via an interface. 326 func (v *__MultipleDirectivesInput) GetQueries() []*UserQueryInput { return v.Queries } 327 328 func MultipleDirectives( 329 client graphql.Client, 330 query MyInput, 331 queries []*UserQueryInput, 332 ) (*MyMultipleDirectivesResponse, error) { 333 req := &graphql.Request{ 334 OpName: "MultipleDirectives", 335 Query: ` 336 query MultipleDirectives ($query: UserQueryInput, $queries: [UserQueryInput]) { 337 user(query: $query) { 338 id 339 } 340 users(query: $queries) { 341 id 342 } 343 } 344 `, 345 Variables: &__MultipleDirectivesInput{ 346 Query: query, 347 Queries: queries, 348 }, 349 } 350 var err error 351 352 var data MyMultipleDirectivesResponse 353 resp := &graphql.Response{Data: &data} 354 355 err = client.MakeRequest( 356 nil, 357 req, 358 resp, 359 ) 360 361 return &data, err 362 } 363