Files
genqlient/example/generated.go
T
Craig Silverstein 587f77046b Expose the graphql operation as a constant in the generated genqlient file (#238)
This allows client code to see the operation (query or mutation) exactly
as genqlient sends it over the wire. This data was already available in
the generated safelist.json file, but now it's easily available from Go
code as well.
    
Fixes #236

I have:
- [x] Written a clear PR title and description (above)
- [x] Signed the [Khan Academy CLA](https://www.khanacademy.org/r/cla)
- [x] Added tests covering my changes, if applicable
- [x] Included a link to the issue fixed, if applicable
- [x] Included documentation, for new features
- [x] Added an entry to the changelog
2022-11-21 08:35:09 -08:00

140 lines
3.7 KiB
Go

// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
package main
import (
"context"
"time"
"github.com/Khan/genqlient/graphql"
)
// __getUserInput is used internally by genqlient
type __getUserInput struct {
Login string `json:"Login"`
}
// GetLogin returns __getUserInput.Login, and is useful for accessing the field via an interface.
func (v *__getUserInput) GetLogin() string { return v.Login }
// getUserResponse is returned by getUser on success.
type getUserResponse struct {
// Lookup a user by login.
User getUserUser `json:"user"`
}
// GetUser returns getUserResponse.User, and is useful for accessing the field via an interface.
func (v *getUserResponse) GetUser() getUserUser { return v.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"`
}
// GetTheirName returns getUserUser.TheirName, and is useful for accessing the field via an interface.
func (v *getUserUser) GetTheirName() string { return v.TheirName }
// GetCreatedAt returns getUserUser.CreatedAt, and is useful for accessing the field via an interface.
func (v *getUserUser) GetCreatedAt() time.Time { return v.CreatedAt }
// getViewerResponse is returned by getViewer on success.
type getViewerResponse struct {
// The currently authenticated user.
Viewer getViewerViewerUser `json:"viewer"`
}
// GetViewer returns getViewerResponse.Viewer, and is useful for accessing the field via an interface.
func (v *getViewerResponse) GetViewer() getViewerViewerUser { return v.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"`
}
// GetMyName returns getViewerViewerUser.MyName, and is useful for accessing the field via an interface.
func (v *getViewerViewerUser) GetMyName() string { return v.MyName }
// GetCreatedAt returns getViewerViewerUser.CreatedAt, and is useful for accessing the field via an interface.
func (v *getViewerViewerUser) GetCreatedAt() time.Time { return v.CreatedAt }
// The query or mutation executed by getUser.
const getUserOperation = `
query getUser ($Login: String!) {
user(login: $Login) {
theirName: name
createdAt
}
}
`
// getUser gets the given user's name from their username.
func getUser(
ctx context.Context,
client graphql.Client,
Login string,
) (*getUserResponse, error) {
req := &graphql.Request{
OpName: "getUser",
Query: getUserOperation,
Variables: &__getUserInput{
Login: Login,
},
}
var err error
var data getUserResponse
resp := &graphql.Response{Data: &data}
err = client.MakeRequest(
ctx,
req,
resp,
)
return &data, err
}
// The query or mutation executed by getViewer.
const getViewerOperation = `
query getViewer {
viewer {
MyName: name
createdAt
}
}
`
func getViewer(
ctx context.Context,
client graphql.Client,
) (*getViewerResponse, error) {
req := &graphql.Request{
OpName: "getViewer",
Query: getViewerOperation,
}
var err error
var data getViewerResponse
resp := &graphql.Response{Data: &data}
err = client.MakeRequest(
ctx,
req,
resp,
)
return &data, err
}