package gqlclient
import "git.sr.ht/~emersion/gqlclient"
Index ¶
- type Client
- func New(endpoint string, hc *http.Client) *Client
- func (c *Client) Execute(ctx context.Context, op *Operation, data interface{}) error
- type Error
- type ErrorLocation
- type Operation
- type Upload
Examples ¶
Package Files ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a GraphQL HTTP client.
func New ¶
New creates a new GraphQL client with the specified endpoint.
If hc is nil, http.DefaultClient is used.
func (*Client) Execute ¶
Execute sends the operation to the GraphQL server.
The data returned by the server will be decoded into the data argument.
Example¶
Code:
var ctx context.Context var c *gqlclient.Client op := gqlclient.NewOperation(`query { me { name } }`) var data struct { Me struct { Name string } } if err := c.Execute(ctx, op, &data); err != nil { log.Fatal(err) } log.Print(data)
Example (Upload)¶
Code:
var ctx context.Context var c *gqlclient.Client op := gqlclient.NewOperation(`mutation ($file: Upload!) { send(file: $file) }`) op.Var("file", gqlclient.Upload{ Filename: "gopher.txt", MIMEType: "text/plain", Body: strings.NewReader("Hello, 世界"), }) if err := c.Execute(ctx, op, nil); err != nil { log.Fatal(err) }
Example (Vars)¶
Code:
var ctx context.Context var c *gqlclient.Client op := gqlclient.NewOperation(`query ($name: String!) { user(username: $name) { age } }`) op.Var("name", "emersion") var data struct { User struct { Age int } } if err := c.Execute(ctx, op, &data); err != nil { log.Fatal(err) } log.Print(data)
type Error ¶
type Error struct { Message string Locations []ErrorLocation Path []interface{} Extensions json.RawMessage }
Error is a GraphQL error.
func (*Error) Error ¶
type ErrorLocation ¶
ErrorLocation describes an error location in a GraphQL document.
Line and column numbers start from 1.
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation describes a GraphQL operation.
An operation is a query with variables.
func NewOperation ¶
NewOperation creates a new GraphQL operation.
func (*Operation) Var ¶
Var defines a new variable.
If the variable is already defined, Var panics.
type Upload ¶
Upload is a file upload.
See the GraphQL multipart request specification for details: https://github.com/jaydenseric/graphql-multipart-request-spec
func (Upload) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
Directories ¶
Path | Synopsis |
---|---|
cmd | |
cmd/gqlclient | |
cmd/gqlclientgen |
- Version
- v0.0.0-20220202181617-4e6e9c763dd2 (latest)
- Published
- Feb 2, 2022
- Platform
- linux/amd64
- Imports
- 9 packages (graph)
- Last checked
- 3 weeks ago –
Tools for package owners.