65d934a705
I set these tests up in #270, but I realized there's a lot more we could test unrelated to that PR. In this commit I add some more tests. They're not really exhaustive yet, but they did catch a few bugs, which I fixed: - we weren't validating the package-name if you do set it (only if we guess it) - If you omitted `generated`, you would try to write generated code to the directory containing `genqlient.yaml`, which makes no sense; now we default to `generated.go`. In the real world it's probably good to set explicitly, but it's actually very convenient in tests that we don't have to, and maybe in small projects too.
69 lines
1.5 KiB
Go
69 lines
1.5 KiB
Go
// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
|
|
|
|
package queries
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Khan/genqlient/graphql"
|
|
"github.com/Khan/genqlient/internal/testutil"
|
|
)
|
|
|
|
// SimpleQueryResponse is returned by SimpleQuery on success.
|
|
type SimpleQueryResponse struct {
|
|
// user looks up a user by some stuff.
|
|
//
|
|
// See UserQueryInput for what stuff is supported.
|
|
// If query is null, returns the current user.
|
|
User SimpleQueryUser `json:"user"`
|
|
}
|
|
|
|
// GetUser returns SimpleQueryResponse.User, and is useful for accessing the field via an interface.
|
|
func (v *SimpleQueryResponse) GetUser() SimpleQueryUser { return v.User }
|
|
|
|
// SimpleQueryUser includes the requested fields of the GraphQL type User.
|
|
// The GraphQL type's documentation follows.
|
|
//
|
|
// A User is a user!
|
|
type SimpleQueryUser struct {
|
|
// id is the user's ID.
|
|
//
|
|
// It is stable, unique, and opaque, like all good IDs.
|
|
Id testutil.ID `json:"id"`
|
|
}
|
|
|
|
// GetId returns SimpleQueryUser.Id, and is useful for accessing the field via an interface.
|
|
func (v *SimpleQueryUser) GetId() testutil.ID { return v.Id }
|
|
|
|
// The query or mutation executed by SimpleQuery.
|
|
const SimpleQuery_Operation = `
|
|
query SimpleQuery {
|
|
user {
|
|
id
|
|
}
|
|
}
|
|
`
|
|
|
|
func SimpleQuery(
|
|
ctx context.Context,
|
|
client graphql.Client,
|
|
) (*SimpleQueryResponse, error) {
|
|
req := &graphql.Request{
|
|
OpName: "SimpleQuery",
|
|
Query: SimpleQuery_Operation,
|
|
}
|
|
var err error
|
|
|
|
var data SimpleQueryResponse
|
|
resp := &graphql.Response{Data: &data}
|
|
|
|
err = client.MakeRequest(
|
|
ctx,
|
|
req,
|
|
resp,
|
|
)
|
|
|
|
return &data, err
|
|
}
|
|
|