Files
genqlient/example/generated.go
T
Ben Kraft d449acdda3 Clarify object type documentation
Craig pointed out this is a bit confusing when you don't have all the
fields.  Now we say so, but still include the type's description in case
it's useful.

Fixes #37.
2021-04-23 18:13:32 -07:00

95 lines
2.0 KiB
Go

package example
// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
import (
"context"
"time"
"github.com/Khan/genqlient/graphql"
)
// getUserResponse is returned by getUser on success.
type getUserResponse struct {
// Lookup a user by login.
User getUserUser `json:"user"`
}
// getUserUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A user is an individual's account on GitHub that owns repositories and can make new content.
type getUserUser struct {
// The user's public profile name.
TheirName string `json:"theirName"`
// Identifies the date and time when the object was created.
CreatedAt time.Time `json:"createdAt"`
}
// getViewerResponse is returned by getViewer on success.
type getViewerResponse struct {
// The currently authenticated user.
Viewer getViewerViewerUser `json:"viewer"`
}
// getViewerViewerUser includes the requested fields of the GraphQL type User.
// The GraphQL type's documentation follows.
//
// A user is an individual's account on GitHub that owns repositories and can make new content.
type getViewerViewerUser struct {
// The user's public profile name.
MyName string `json:"MyName"`
// Identifies the date and time when the object was created.
CreatedAt time.Time `json:"createdAt"`
}
func getViewer(
ctx context.Context,
client graphql.Client,
) (*getViewerResponse, error) {
var retval getViewerResponse
err := client.MakeRequest(
ctx,
"getViewer",
`
query getViewer {
viewer {
MyName: name
createdAt
}
}
`,
&retval,
nil,
)
return &retval, err
}
// getUser gets the given user's name from their username.
func getUser(
ctx context.Context,
client graphql.Client,
login string,
) (*getUserResponse, error) {
variables := map[string]interface{}{
"Login": login,
}
var retval getUserResponse
err := client.MakeRequest(
ctx,
"getUser",
`
query getUser ($Login: String!) {
user(login: $Login) {
theirName: name
createdAt
}
}
`,
&retval,
variables,
)
return &retval, err
}