Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
package main import ( "context" "log" "git.sr.ht/~emersion/gqlclient" ) func main() { 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) }
Output:
Example (Upload) ¶
package main import ( "context" "log" "strings" "git.sr.ht/~emersion/gqlclient" ) func main() { 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) } }
Output:
Example (Vars) ¶
package main import ( "context" "log" "git.sr.ht/~emersion/gqlclient" ) func main() { 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) }
Output:
type Error ¶
type Error struct { Message string Locations []ErrorLocation Path []interface{} Extensions json.RawMessage }
Error is a GraphQL error.
type ErrorLocation ¶
type ErrorLocation struct {
Line, Column int
}
ErrorLocation describes an error location in a GraphQL document.
Line and column numbers start from 1.
type HTTPError ¶
type HTTPError struct { StatusCode int // contains filtered or unexported fields }
HTTPError is an HTTP response error.
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.
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.