github.com/Desuuuu/genqlient@v0.5.3/generate/testdata/snapshots/TestGenerate-InputObject.graphql-InputObject.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  // InputObjectQueryResponse is returned by InputObjectQuery on success.
    15  type InputObjectQueryResponse 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 InputObjectQueryUser `json:"user"`
    21  }
    22  
    23  // GetUser returns InputObjectQueryResponse.User, and is useful for accessing the field via an interface.
    24  func (v *InputObjectQueryResponse) GetUser() InputObjectQueryUser { return v.User }
    25  
    26  // InputObjectQueryUser includes the requested fields of the GraphQL type User.
    27  // The GraphQL type's documentation follows.
    28  //
    29  // A User is a user!
    30  type InputObjectQueryUser struct {
    31  	// id is the user's ID.
    32  	//
    33  	// It is stable, unique, and opaque, like all good IDs.
    34  	Id testutil.ID `json:"id"`
    35  }
    36  
    37  // GetId returns InputObjectQueryUser.Id, and is useful for accessing the field via an interface.
    38  func (v *InputObjectQueryUser) GetId() testutil.ID { return v.Id }
    39  
    40  // Role is a type a user may have.
    41  type Role string
    42  
    43  const (
    44  	// What is a student?
    45  	//
    46  	// 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.
    47  	//
    48  	// (from [Wikipedia](https://en.wikipedia.org/wiki/Student))
    49  	RoleStudent Role = "STUDENT"
    50  	// Teacher is a teacher, who teaches the students.
    51  	RoleTeacher Role = "TEACHER"
    52  )
    53  
    54  // UserQueryInput is the argument to Query.users.
    55  //
    56  // Ideally this would support anything and everything!
    57  // Or maybe ideally it wouldn't.
    58  // Really I'm just talking to make this documentation longer.
    59  type UserQueryInput struct {
    60  	Email string `json:"email"`
    61  	Name  string `json:"name"`
    62  	// id looks the user up by ID.  It's a great way to look up users.
    63  	Id         testutil.ID      `json:"id"`
    64  	Role       Role             `json:"role"`
    65  	Names      []string         `json:"names"`
    66  	HasPokemon testutil.Pokemon `json:"hasPokemon"`
    67  	Birthdate  time.Time        `json:"-"`
    68  }
    69  
    70  // GetEmail returns UserQueryInput.Email, and is useful for accessing the field via an interface.
    71  func (v *UserQueryInput) GetEmail() string { return v.Email }
    72  
    73  // GetName returns UserQueryInput.Name, and is useful for accessing the field via an interface.
    74  func (v *UserQueryInput) GetName() string { return v.Name }
    75  
    76  // GetId returns UserQueryInput.Id, and is useful for accessing the field via an interface.
    77  func (v *UserQueryInput) GetId() testutil.ID { return v.Id }
    78  
    79  // GetRole returns UserQueryInput.Role, and is useful for accessing the field via an interface.
    80  func (v *UserQueryInput) GetRole() Role { return v.Role }
    81  
    82  // GetNames returns UserQueryInput.Names, and is useful for accessing the field via an interface.
    83  func (v *UserQueryInput) GetNames() []string { return v.Names }
    84  
    85  // GetHasPokemon returns UserQueryInput.HasPokemon, and is useful for accessing the field via an interface.
    86  func (v *UserQueryInput) GetHasPokemon() testutil.Pokemon { return v.HasPokemon }
    87  
    88  // GetBirthdate returns UserQueryInput.Birthdate, and is useful for accessing the field via an interface.
    89  func (v *UserQueryInput) GetBirthdate() time.Time { return v.Birthdate }
    90  
    91  func (v *UserQueryInput) UnmarshalJSON(b []byte) error {
    92  
    93  	if string(b) == "null" {
    94  		return nil
    95  	}
    96  
    97  	var firstPass struct {
    98  		*UserQueryInput
    99  		Birthdate json.RawMessage `json:"birthdate"`
   100  		graphql.NoUnmarshalJSON
   101  	}
   102  	firstPass.UserQueryInput = v
   103  
   104  	err := json.Unmarshal(b, &firstPass)
   105  	if err != nil {
   106  		return err
   107  	}
   108  
   109  	{
   110  		dst := &v.Birthdate
   111  		src := firstPass.Birthdate
   112  		if len(src) != 0 && string(src) != "null" {
   113  			err = testutil.UnmarshalDate(
   114  				src, dst)
   115  			if err != nil {
   116  				return fmt.Errorf(
   117  					"Unable to unmarshal UserQueryInput.Birthdate: %w", err)
   118  			}
   119  		}
   120  	}
   121  	return nil
   122  }
   123  
   124  type __premarshalUserQueryInput struct {
   125  	Email string `json:"email"`
   126  
   127  	Name string `json:"name"`
   128  
   129  	Id testutil.ID `json:"id"`
   130  
   131  	Role Role `json:"role"`
   132  
   133  	Names []string `json:"names"`
   134  
   135  	HasPokemon testutil.Pokemon `json:"hasPokemon"`
   136  
   137  	Birthdate json.RawMessage `json:"birthdate"`
   138  }
   139  
   140  func (v *UserQueryInput) MarshalJSON() ([]byte, error) {
   141  	premarshaled, err := v.__premarshalJSON()
   142  	if err != nil {
   143  		return nil, err
   144  	}
   145  	return json.Marshal(premarshaled)
   146  }
   147  
   148  func (v *UserQueryInput) __premarshalJSON() (*__premarshalUserQueryInput, error) {
   149  	var retval __premarshalUserQueryInput
   150  
   151  	retval.Email = v.Email
   152  	retval.Name = v.Name
   153  	retval.Id = v.Id
   154  	retval.Role = v.Role
   155  	retval.Names = v.Names
   156  	retval.HasPokemon = v.HasPokemon
   157  	{
   158  
   159  		dst := &retval.Birthdate
   160  		src := v.Birthdate
   161  		var err error
   162  		*dst, err = testutil.MarshalDate(
   163  			&src)
   164  		if err != nil {
   165  			return nil, fmt.Errorf(
   166  				"Unable to marshal UserQueryInput.Birthdate: %w", err)
   167  		}
   168  	}
   169  	return &retval, nil
   170  }
   171  
   172  // __InputObjectQueryInput is used internally by genqlient
   173  type __InputObjectQueryInput struct {
   174  	Query UserQueryInput `json:"query"`
   175  }
   176  
   177  // GetQuery returns __InputObjectQueryInput.Query, and is useful for accessing the field via an interface.
   178  func (v *__InputObjectQueryInput) GetQuery() UserQueryInput { return v.Query }
   179  
   180  func InputObjectQuery(
   181  	client graphql.Client,
   182  	query UserQueryInput,
   183  ) (*InputObjectQueryResponse, error) {
   184  	req := &graphql.Request{
   185  		OpName: "InputObjectQuery",
   186  		Query: `
   187  query InputObjectQuery ($query: UserQueryInput) {
   188  	user(query: $query) {
   189  		id
   190  	}
   191  }
   192  `,
   193  		Variables: &__InputObjectQueryInput{
   194  			Query: query,
   195  		},
   196  	}
   197  	var err error
   198  
   199  	var data InputObjectQueryResponse
   200  	resp := &graphql.Response{Data: &data}
   201  
   202  	err = client.MakeRequest(
   203  		nil,
   204  		req,
   205  		resp,
   206  	)
   207  
   208  	return &data, err
   209  }
   210