Documentation ¶
Index ¶
- type Alias
- type Argument
- type ArgumentFormatter
- type Client
- func (c *Client) Mutation(f Fielder) error
- func (c *Client) MutationContext(ctx context.Context, f Fielder) error
- func (c *Client) Query(first Fielder, more ...Fielder) error
- func (c *Client) QueryContext(ctx context.Context, first Fielder, more ...Fielder) error
- func (c *Client) RawRequest(ctx context.Context, query string) ([]byte, error)
- func (c *Client) Request(ctx context.Context, f Fielder, out interface{}) error
- type ClientOption
- type DestSetter
- type Enum
- type FieldFunc
- type FieldOption
- type Fielder
- type GenericResult
- type GraphQLError
- type GraphQLErrorLocation
- type GraphQLField
- type JSONMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alias ¶
type Alias string
func (Alias) UpdateField ¶
func (a Alias) UpdateField(f GraphQLField) GraphQLField
type Argument ¶
type Argument struct { Name string Value interface{} }
An Argument represents a GraphQL argument, containing a name and value.
func (Argument) UpdateField ¶
func (a Argument) UpdateField(f GraphQLField) GraphQLField
type ArgumentFormatter ¶
ArgumentFormatter - interface for a format method
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the object used for making all requests.
func NewClient ¶
func NewClient(url string, options ...ClientOption) *Client
NewClient returns a new client object.
func (*Client) Mutation ¶
Mutation accepts a GraphQLField, wraps it in a "mutation" field, performs the query, then scans the result into the field's dest.
func (*Client) MutationContext ¶ added in v0.0.4
func (*Client) Query ¶
Query takes one or more GraphQLField objects. It joins all the fields into a single query, sends it to the server, and unmarshals the results into Dest fields of the GraphQLField objects.
func (*Client) QueryContext ¶ added in v0.0.4
func (*Client) RawRequest ¶
RawRequest takes a byte slice with your graphQL query inside it, and returns a byte slice with the graphql response inside it, or an error.
type ClientOption ¶
type ClientOption func(*Client)
A ClientOption is a function that modifies a *Client.
func Header ¶
func Header(key, val string) ClientOption
func HttpClient ¶ added in v0.0.4
func HttpClient(httpClient *http.Client) ClientOption
type DestSetter ¶
type DestSetter func(GraphQLField) GraphQLField
The DestSetter type exists only so we can stick a UpdateField method on it.
func Dest ¶
func Dest(d interface{}) DestSetter
Dest is a helper function for making a DestSetter. Call it with a pointer to a thing as the argument, and use the return value as an argument to Query or Mutation.
func (DestSetter) UpdateField ¶
func (d DestSetter) UpdateField(f GraphQLField) GraphQLField
UpdateField sets the Dest field on a GraphQLField.
type Enum ¶
type Enum string
Enum is a string type alias for argument values that shouldn't have quotes put around them.
type FieldFunc ¶
type FieldFunc func(...FieldOption) GraphQLField
A FieldFunc can be Render-ed directly, or called with any number of Arguments and GraphQLFields to return a new Render-able GraphQLField.
func Field ¶
func Field(name string, outerOptions ...FieldOption) FieldFunc
Field is a shorthand for building a GraphQLField. It accepts a name, and any number of Arguments and GraphQLFields. It returns a FieldFunc that can be Render-ed directly, or called with more Arguments and GraphQLFields to return a Render-able GraphQLField.
func (FieldFunc) Field ¶
func (f FieldFunc) Field() GraphQLField
Field executes the FieldFunc with no arguments and returns its resulting Field.
func (FieldFunc) GetKey ¶
GetKey executes the FieldFunc and then returns the result of calling its GetKey method.
func (FieldFunc) Render ¶
Render takes a variable number of bools that indicate the number of indents to use in the query (their value doesn't matter), and returns the rendered field, or an error.
func (FieldFunc) UpdateField ¶
func (f FieldFunc) UpdateField(parent GraphQLField) GraphQLField
UpdateField makes FieldFunc satisfy the FieldOption interface, so FieldFuncs can plug themselves into parents as sub selections.
type FieldOption ¶
type FieldOption interface {
UpdateField(GraphQLField) GraphQLField
}
type Fielder ¶
type Fielder interface { Render(...bool) (string, error) GetKey() string Field() GraphQLField }
Fielder defines the functions that a thing must implement in order to be passed to our Query and Mutation functions.
type GenericResult ¶
type GenericResult struct { Data map[string]json.RawMessage `json:"data"` Errors []GraphQLError `json:"errors"` }
GenericResult matches the outermost structure of a GraphQL response payload.
type GraphQLError ¶
type GraphQLError struct { Message string `json:"message"` Locations []GraphQLErrorLocation `json:"locations"` Path []string `json:"path"` Extensions JSONMap `json:"extensions"` }
A GraphQLError represents an object returned in the "errors" list in a GraphQL response payload. It also implements the Go error interface.
func (GraphQLError) Error ¶
func (e GraphQLError) Error() string
Error renders the GraphQLError as a single string.
type GraphQLErrorLocation ¶
GraphQLErrorLocation is a sub-field of GraphQLError.
type GraphQLField ¶
type GraphQLField struct { Name string Arguments map[string]interface{} Fields []GraphQLField Alias Alias Dest interface{} }
GraphQLField is a graphQL field. Normally you will have these built for you by passing arguments to FieldFuncs instead of constructing them directly.
func (GraphQLField) Field ¶
func (f GraphQLField) Field() GraphQLField
Field returns the field's field.
func (GraphQLField) GetKey ¶
func (f GraphQLField) GetKey() string
GetKey returns the field's alias, if it has one, or otherwise its name.
func (GraphQLField) Render ¶
func (f GraphQLField) Render(indents ...bool) (string, error)
Render turns a Field into bytes that you can send in a network request.
func (GraphQLField) UpdateField ¶
func (f GraphQLField) UpdateField(parent GraphQLField) GraphQLField
UpdateField makes GraphQLField satisfy the FieldOption interface, which lets it plug itself into a parent field as a sub selection.