github.com/opiuman/genqlient@v1.0.0/generate/testdata/snapshots/TestGenerate-unexported.graphql-unexported.graphql.go (about)

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