github.com/Desuuuu/genqlient@v0.5.3/generate/testdata/snapshots/TestGenerate-Omitempty.graphql-Omitempty.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 // OmitEmptyQueryResponse is returned by OmitEmptyQuery on success. 15 type OmitEmptyQueryResponse struct { 16 // user looks up a user by some stuff. 17 // 18 // See UserQueryInput for what stuff is supported. 19 // If query is null, returns the current user. 20 User OmitEmptyQueryUser `json:"user"` 21 Users []OmitEmptyQueryUsersUser `json:"users"` 22 MaybeConvert time.Time `json:"maybeConvert"` 23 Convert2 time.Time `json:"convert2"` 24 } 25 26 // GetUser returns OmitEmptyQueryResponse.User, and is useful for accessing the field via an interface. 27 func (v *OmitEmptyQueryResponse) GetUser() OmitEmptyQueryUser { return v.User } 28 29 // GetUsers returns OmitEmptyQueryResponse.Users, and is useful for accessing the field via an interface. 30 func (v *OmitEmptyQueryResponse) GetUsers() []OmitEmptyQueryUsersUser { return v.Users } 31 32 // GetMaybeConvert returns OmitEmptyQueryResponse.MaybeConvert, and is useful for accessing the field via an interface. 33 func (v *OmitEmptyQueryResponse) GetMaybeConvert() time.Time { return v.MaybeConvert } 34 35 // GetConvert2 returns OmitEmptyQueryResponse.Convert2, and is useful for accessing the field via an interface. 36 func (v *OmitEmptyQueryResponse) GetConvert2() time.Time { return v.Convert2 } 37 38 // OmitEmptyQueryUser includes the requested fields of the GraphQL type User. 39 // The GraphQL type's documentation follows. 40 // 41 // A User is a user! 42 type OmitEmptyQueryUser struct { 43 // id is the user's ID. 44 // 45 // It is stable, unique, and opaque, like all good IDs. 46 Id testutil.ID `json:"id"` 47 } 48 49 // GetId returns OmitEmptyQueryUser.Id, and is useful for accessing the field via an interface. 50 func (v *OmitEmptyQueryUser) GetId() testutil.ID { return v.Id } 51 52 // OmitEmptyQueryUsersUser includes the requested fields of the GraphQL type User. 53 // The GraphQL type's documentation follows. 54 // 55 // A User is a user! 56 type OmitEmptyQueryUsersUser struct { 57 // id is the user's ID. 58 // 59 // It is stable, unique, and opaque, like all good IDs. 60 Id testutil.ID `json:"id"` 61 } 62 63 // GetId returns OmitEmptyQueryUsersUser.Id, and is useful for accessing the field via an interface. 64 func (v *OmitEmptyQueryUsersUser) GetId() testutil.ID { return v.Id } 65 66 // Role is a type a user may have. 67 type Role string 68 69 const ( 70 // What is a student? 71 // 72 // 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. 73 // 74 // (from [Wikipedia](https://en.wikipedia.org/wiki/Student)) 75 RoleStudent Role = "STUDENT" 76 // Teacher is a teacher, who teaches the students. 77 RoleTeacher Role = "TEACHER" 78 ) 79 80 // UserQueryInput is the argument to Query.users. 81 // 82 // Ideally this would support anything and everything! 83 // Or maybe ideally it wouldn't. 84 // Really I'm just talking to make this documentation longer. 85 type UserQueryInput struct { 86 Email string `json:"email,omitempty"` 87 Name string `json:"name,omitempty"` 88 // id looks the user up by ID. It's a great way to look up users. 89 Id testutil.ID `json:"id"` 90 Role Role `json:"role,omitempty"` 91 Names []string `json:"names,omitempty"` 92 HasPokemon testutil.Pokemon `json:"hasPokemon,omitempty"` 93 Birthdate time.Time `json:"-"` 94 } 95 96 // GetEmail returns UserQueryInput.Email, and is useful for accessing the field via an interface. 97 func (v *UserQueryInput) GetEmail() string { return v.Email } 98 99 // GetName returns UserQueryInput.Name, and is useful for accessing the field via an interface. 100 func (v *UserQueryInput) GetName() string { return v.Name } 101 102 // GetId returns UserQueryInput.Id, and is useful for accessing the field via an interface. 103 func (v *UserQueryInput) GetId() testutil.ID { return v.Id } 104 105 // GetRole returns UserQueryInput.Role, and is useful for accessing the field via an interface. 106 func (v *UserQueryInput) GetRole() Role { return v.Role } 107 108 // GetNames returns UserQueryInput.Names, and is useful for accessing the field via an interface. 109 func (v *UserQueryInput) GetNames() []string { return v.Names } 110 111 // GetHasPokemon returns UserQueryInput.HasPokemon, and is useful for accessing the field via an interface. 112 func (v *UserQueryInput) GetHasPokemon() testutil.Pokemon { return v.HasPokemon } 113 114 // GetBirthdate returns UserQueryInput.Birthdate, and is useful for accessing the field via an interface. 115 func (v *UserQueryInput) GetBirthdate() time.Time { return v.Birthdate } 116 117 func (v *UserQueryInput) UnmarshalJSON(b []byte) error { 118 119 if string(b) == "null" { 120 return nil 121 } 122 123 var firstPass struct { 124 *UserQueryInput 125 Birthdate json.RawMessage `json:"birthdate"` 126 graphql.NoUnmarshalJSON 127 } 128 firstPass.UserQueryInput = v 129 130 err := json.Unmarshal(b, &firstPass) 131 if err != nil { 132 return err 133 } 134 135 { 136 dst := &v.Birthdate 137 src := firstPass.Birthdate 138 if len(src) != 0 && string(src) != "null" { 139 err = testutil.UnmarshalDate( 140 src, dst) 141 if err != nil { 142 return fmt.Errorf( 143 "Unable to unmarshal UserQueryInput.Birthdate: %w", err) 144 } 145 } 146 } 147 return nil 148 } 149 150 type __premarshalUserQueryInput struct { 151 Email string `json:"email"` 152 153 Name string `json:"name"` 154 155 Id testutil.ID `json:"id"` 156 157 Role Role `json:"role"` 158 159 Names []string `json:"names"` 160 161 HasPokemon testutil.Pokemon `json:"hasPokemon"` 162 163 Birthdate json.RawMessage `json:"birthdate"` 164 } 165 166 func (v *UserQueryInput) MarshalJSON() ([]byte, error) { 167 premarshaled, err := v.__premarshalJSON() 168 if err != nil { 169 return nil, err 170 } 171 return json.Marshal(premarshaled) 172 } 173 174 func (v *UserQueryInput) __premarshalJSON() (*__premarshalUserQueryInput, error) { 175 var retval __premarshalUserQueryInput 176 177 retval.Email = v.Email 178 retval.Name = v.Name 179 retval.Id = v.Id 180 retval.Role = v.Role 181 retval.Names = v.Names 182 retval.HasPokemon = v.HasPokemon 183 { 184 185 dst := &retval.Birthdate 186 src := v.Birthdate 187 var err error 188 *dst, err = testutil.MarshalDate( 189 &src) 190 if err != nil { 191 return nil, fmt.Errorf( 192 "Unable to marshal UserQueryInput.Birthdate: %w", err) 193 } 194 } 195 return &retval, nil 196 } 197 198 // __OmitEmptyQueryInput is used internally by genqlient 199 type __OmitEmptyQueryInput struct { 200 Query UserQueryInput `json:"query,omitempty"` 201 Queries []UserQueryInput `json:"queries,omitempty"` 202 Dt time.Time `json:"dt,omitempty"` 203 Tz string `json:"tz,omitempty"` 204 TzNoOmitEmpty string `json:"tzNoOmitEmpty"` 205 } 206 207 // GetQuery returns __OmitEmptyQueryInput.Query, and is useful for accessing the field via an interface. 208 func (v *__OmitEmptyQueryInput) GetQuery() UserQueryInput { return v.Query } 209 210 // GetQueries returns __OmitEmptyQueryInput.Queries, and is useful for accessing the field via an interface. 211 func (v *__OmitEmptyQueryInput) GetQueries() []UserQueryInput { return v.Queries } 212 213 // GetDt returns __OmitEmptyQueryInput.Dt, and is useful for accessing the field via an interface. 214 func (v *__OmitEmptyQueryInput) GetDt() time.Time { return v.Dt } 215 216 // GetTz returns __OmitEmptyQueryInput.Tz, and is useful for accessing the field via an interface. 217 func (v *__OmitEmptyQueryInput) GetTz() string { return v.Tz } 218 219 // GetTzNoOmitEmpty returns __OmitEmptyQueryInput.TzNoOmitEmpty, and is useful for accessing the field via an interface. 220 func (v *__OmitEmptyQueryInput) GetTzNoOmitEmpty() string { return v.TzNoOmitEmpty } 221 222 func OmitEmptyQuery( 223 client graphql.Client, 224 query UserQueryInput, 225 queries []UserQueryInput, 226 dt time.Time, 227 tz string, 228 tzNoOmitEmpty string, 229 ) (*OmitEmptyQueryResponse, error) { 230 req := &graphql.Request{ 231 OpName: "OmitEmptyQuery", 232 Query: ` 233 query OmitEmptyQuery ($query: UserQueryInput, $queries: [UserQueryInput], $dt: DateTime, $tz: String, $tzNoOmitEmpty: String) { 234 user(query: $query) { 235 id 236 } 237 users(query: $queries) { 238 id 239 } 240 maybeConvert(dt: $dt, tz: $tz) 241 convert2: maybeConvert(dt: $dt, tz: $tzNoOmitEmpty) 242 } 243 `, 244 Variables: &__OmitEmptyQueryInput{ 245 Query: query, 246 Queries: queries, 247 Dt: dt, 248 Tz: tz, 249 TzNoOmitEmpty: tzNoOmitEmpty, 250 }, 251 } 252 var err error 253 254 var data OmitEmptyQueryResponse 255 resp := &graphql.Response{Data: &data} 256 257 err = client.MakeRequest( 258 nil, 259 req, 260 resp, 261 ) 262 263 return &data, err 264 } 265