github.com/codykaup/genqlient@v0.6.2/generate/testdata/snapshots/TestGenerateWithConfig-StructReferencesAndOptionalPointer-testdata-queries-generated.go (about)

     1  // Code generated by github.com/codykaup/genqlient, DO NOT EDIT.
     2  
     3  package queries
     4  
     5  import (
     6  	"context"
     7  	"encoding/json"
     8  	"fmt"
     9  	"time"
    10  
    11  	"github.com/codykaup/genqlient/graphql"
    12  	"github.com/codykaup/genqlient/internal/testutil"
    13  )
    14  
    15  // InputObjectQueryResponse is returned by InputObjectQuery on success.
    16  type InputObjectQueryResponse struct {
    17  	// user looks up a user by some stuff.
    18  	//
    19  	// See UserQueryInput for what stuff is supported.
    20  	// If query is null, returns the current user.
    21  	User *InputObjectQueryUser `json:"user"`
    22  }
    23  
    24  // GetUser returns InputObjectQueryResponse.User, and is useful for accessing the field via an interface.
    25  func (v *InputObjectQueryResponse) GetUser() *InputObjectQueryUser { return v.User }
    26  
    27  // InputObjectQueryUser includes the requested fields of the GraphQL type User.
    28  // The GraphQL type's documentation follows.
    29  //
    30  // A User is a user!
    31  type InputObjectQueryUser struct {
    32  	// id is the user's ID.
    33  	//
    34  	// It is stable, unique, and opaque, like all good IDs.
    35  	Id string `json:"id"`
    36  }
    37  
    38  // GetId returns InputObjectQueryUser.Id, and is useful for accessing the field via an interface.
    39  func (v *InputObjectQueryUser) GetId() string { return v.Id }
    40  
    41  type PokemonInput struct {
    42  	Species string `json:"species"`
    43  	Level   int    `json:"level"`
    44  }
    45  
    46  // GetSpecies returns PokemonInput.Species, and is useful for accessing the field via an interface.
    47  func (v *PokemonInput) GetSpecies() string { return v.Species }
    48  
    49  // GetLevel returns PokemonInput.Level, and is useful for accessing the field via an interface.
    50  func (v *PokemonInput) GetLevel() int { return v.Level }
    51  
    52  // QueryWithStructsResponse is returned by QueryWithStructs on success.
    53  type QueryWithStructsResponse struct {
    54  	// user looks up a user by some stuff.
    55  	//
    56  	// See UserQueryInput for what stuff is supported.
    57  	// If query is null, returns the current user.
    58  	User *QueryWithStructsUser `json:"user"`
    59  }
    60  
    61  // GetUser returns QueryWithStructsResponse.User, and is useful for accessing the field via an interface.
    62  func (v *QueryWithStructsResponse) GetUser() *QueryWithStructsUser { return v.User }
    63  
    64  // QueryWithStructsUser includes the requested fields of the GraphQL type User.
    65  // The GraphQL type's documentation follows.
    66  //
    67  // A User is a user!
    68  type QueryWithStructsUser struct {
    69  	AuthMethods []*QueryWithStructsUserAuthMethodsAuthMethod `json:"authMethods"`
    70  }
    71  
    72  // GetAuthMethods returns QueryWithStructsUser.AuthMethods, and is useful for accessing the field via an interface.
    73  func (v *QueryWithStructsUser) GetAuthMethods() []*QueryWithStructsUserAuthMethodsAuthMethod {
    74  	return v.AuthMethods
    75  }
    76  
    77  // QueryWithStructsUserAuthMethodsAuthMethod includes the requested fields of the GraphQL type AuthMethod.
    78  type QueryWithStructsUserAuthMethodsAuthMethod struct {
    79  	Provider *string `json:"provider"`
    80  	Email    *string `json:"email"`
    81  }
    82  
    83  // GetProvider returns QueryWithStructsUserAuthMethodsAuthMethod.Provider, and is useful for accessing the field via an interface.
    84  func (v *QueryWithStructsUserAuthMethodsAuthMethod) GetProvider() *string { return v.Provider }
    85  
    86  // GetEmail returns QueryWithStructsUserAuthMethodsAuthMethod.Email, and is useful for accessing the field via an interface.
    87  func (v *QueryWithStructsUserAuthMethodsAuthMethod) GetEmail() *string { return v.Email }
    88  
    89  // Role is a type a user may have.
    90  type Role string
    91  
    92  const (
    93  	// What is a student?
    94  	//
    95  	// 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.
    96  	//
    97  	// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
    98  	RoleStudent Role = "STUDENT"
    99  	// Teacher is a teacher, who teaches the students.
   100  	RoleTeacher Role = "TEACHER"
   101  )
   102  
   103  // UserQueryInput is the argument to Query.users.
   104  //
   105  // Ideally this would support anything and everything!
   106  // Or maybe ideally it wouldn't.
   107  // Really I'm just talking to make this documentation longer.
   108  type UserQueryInput struct {
   109  	Email *string `json:"email"`
   110  	Name  *string `json:"name"`
   111  	// id looks the user up by ID.  It's a great way to look up users.
   112  	Id         *string       `json:"id"`
   113  	Role       *Role         `json:"role"`
   114  	Names      []*string     `json:"names"`
   115  	HasPokemon *PokemonInput `json:"hasPokemon,omitempty"`
   116  	Birthdate  *time.Time    `json:"-"`
   117  }
   118  
   119  // GetEmail returns UserQueryInput.Email, and is useful for accessing the field via an interface.
   120  func (v *UserQueryInput) GetEmail() *string { return v.Email }
   121  
   122  // GetName returns UserQueryInput.Name, and is useful for accessing the field via an interface.
   123  func (v *UserQueryInput) GetName() *string { return v.Name }
   124  
   125  // GetId returns UserQueryInput.Id, and is useful for accessing the field via an interface.
   126  func (v *UserQueryInput) GetId() *string { return v.Id }
   127  
   128  // GetRole returns UserQueryInput.Role, and is useful for accessing the field via an interface.
   129  func (v *UserQueryInput) GetRole() *Role { return v.Role }
   130  
   131  // GetNames returns UserQueryInput.Names, and is useful for accessing the field via an interface.
   132  func (v *UserQueryInput) GetNames() []*string { return v.Names }
   133  
   134  // GetHasPokemon returns UserQueryInput.HasPokemon, and is useful for accessing the field via an interface.
   135  func (v *UserQueryInput) GetHasPokemon() *PokemonInput { return v.HasPokemon }
   136  
   137  // GetBirthdate returns UserQueryInput.Birthdate, and is useful for accessing the field via an interface.
   138  func (v *UserQueryInput) GetBirthdate() *time.Time { return v.Birthdate }
   139  
   140  func (v *UserQueryInput) UnmarshalJSON(b []byte) error {
   141  
   142  	if string(b) == "null" {
   143  		return nil
   144  	}
   145  
   146  	var firstPass struct {
   147  		*UserQueryInput
   148  		Birthdate json.RawMessage `json:"birthdate"`
   149  		graphql.NoUnmarshalJSON
   150  	}
   151  	firstPass.UserQueryInput = v
   152  
   153  	err := json.Unmarshal(b, &firstPass)
   154  	if err != nil {
   155  		return err
   156  	}
   157  
   158  	{
   159  		dst := &v.Birthdate
   160  		src := firstPass.Birthdate
   161  		if len(src) != 0 && string(src) != "null" {
   162  			*dst = new(time.Time)
   163  			err = testutil.UnmarshalDate(
   164  				src, *dst)
   165  			if err != nil {
   166  				return fmt.Errorf(
   167  					"unable to unmarshal UserQueryInput.Birthdate: %w", err)
   168  			}
   169  		}
   170  	}
   171  	return nil
   172  }
   173  
   174  type __premarshalUserQueryInput struct {
   175  	Email *string `json:"email"`
   176  
   177  	Name *string `json:"name"`
   178  
   179  	Id *string `json:"id"`
   180  
   181  	Role *Role `json:"role"`
   182  
   183  	Names []*string `json:"names"`
   184  
   185  	HasPokemon *PokemonInput `json:"hasPokemon,omitempty"`
   186  
   187  	Birthdate json.RawMessage `json:"birthdate"`
   188  }
   189  
   190  func (v *UserQueryInput) MarshalJSON() ([]byte, error) {
   191  	premarshaled, err := v.__premarshalJSON()
   192  	if err != nil {
   193  		return nil, err
   194  	}
   195  	return json.Marshal(premarshaled)
   196  }
   197  
   198  func (v *UserQueryInput) __premarshalJSON() (*__premarshalUserQueryInput, error) {
   199  	var retval __premarshalUserQueryInput
   200  
   201  	retval.Email = v.Email
   202  	retval.Name = v.Name
   203  	retval.Id = v.Id
   204  	retval.Role = v.Role
   205  	retval.Names = v.Names
   206  	retval.HasPokemon = v.HasPokemon
   207  	{
   208  
   209  		dst := &retval.Birthdate
   210  		src := v.Birthdate
   211  		if src != nil {
   212  			var err error
   213  			*dst, err = testutil.MarshalDate(
   214  				src)
   215  			if err != nil {
   216  				return nil, fmt.Errorf(
   217  					"unable to marshal UserQueryInput.Birthdate: %w", err)
   218  			}
   219  		}
   220  	}
   221  	return &retval, nil
   222  }
   223  
   224  // __InputObjectQueryInput is used internally by genqlient
   225  type __InputObjectQueryInput struct {
   226  	Query *UserQueryInput `json:"query,omitempty"`
   227  }
   228  
   229  // GetQuery returns __InputObjectQueryInput.Query, and is useful for accessing the field via an interface.
   230  func (v *__InputObjectQueryInput) GetQuery() *UserQueryInput { return v.Query }
   231  
   232  // The query or mutation executed by InputObjectQuery.
   233  const InputObjectQuery_Operation = `
   234  query InputObjectQuery ($query: UserQueryInput) {
   235  	user(query: $query) {
   236  		id
   237  	}
   238  }
   239  `
   240  
   241  func InputObjectQuery(
   242  	ctx_ context.Context,
   243  	client_ graphql.Client,
   244  	query *UserQueryInput,
   245  ) (*InputObjectQueryResponse, error) {
   246  	req_ := &graphql.Request{
   247  		OpName: "InputObjectQuery",
   248  		Query:  InputObjectQuery_Operation,
   249  		Variables: &__InputObjectQueryInput{
   250  			Query: query,
   251  		},
   252  	}
   253  	var err_ error
   254  
   255  	var data_ InputObjectQueryResponse
   256  	resp_ := &graphql.Response{Data: &data_}
   257  
   258  	err_ = client_.MakeRequest(
   259  		ctx_,
   260  		req_,
   261  		resp_,
   262  	)
   263  
   264  	return &data_, err_
   265  }
   266  
   267  // The query or mutation executed by QueryWithStructs.
   268  const QueryWithStructs_Operation = `
   269  query QueryWithStructs {
   270  	user {
   271  		authMethods {
   272  			provider
   273  			email
   274  		}
   275  	}
   276  }
   277  `
   278  
   279  func QueryWithStructs(
   280  	ctx_ context.Context,
   281  	client_ graphql.Client,
   282  ) (*QueryWithStructsResponse, error) {
   283  	req_ := &graphql.Request{
   284  		OpName: "QueryWithStructs",
   285  		Query:  QueryWithStructs_Operation,
   286  	}
   287  	var err_ error
   288  
   289  	var data_ QueryWithStructsResponse
   290  	resp_ := &graphql.Response{Data: &data_}
   291  
   292  	err_ = client_.MakeRequest(
   293  		ctx_,
   294  		req_,
   295  		resp_,
   296  	)
   297  
   298  	return &data_, err_
   299  }
   300