Documentation ¶
Overview ¶
Package graphql provides a GraphQL client implementation.
For more information, see package github.com/shurcooL/githubql, which is a specialized version targeting GitHub GraphQL API v4. That package is driving the feature development.
Status: In active early research and development. The API will change when opportunities for improvement are discovered; it is not yet frozen.
For now, see README for more details.
Index ¶
- func GenerateQueryFields(v interface{}) string
- type Boolean
- type Client
- func (c *Client) Mutate(ctx context.Context, m interface{}, variables map[string]interface{}) error
- func (c *Client) MutateCustom(ctx context.Context, m interface{}, query string, ...) error
- func (c *Client) Query(ctx context.Context, q interface{}, variables map[string]interface{}) error
- func (c *Client) QueryCustom(ctx context.Context, q interface{}, query string, ...) error
- type Float
- type ID
- type Int
- type Request
- type Response
- type String
- type Transport
- type TransportHTTP
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateQueryFields ¶
func GenerateQueryFields(v interface{}) string
GenerateQueryFields construct a minified graphql string type definition query string from the provided struct v.
E.g., struct{Foo Int, BarBaz *Boolean} -> "{foo,barBaz}".
You can concatenate snippets to produce custom queries, while still successfully avoiding most of the repetition of describing your Go type in graphql terms. To make a full query, you also need to prefix a variables section; the QueryCustom method will do this for you. Arguments, Aliases, and Fragments can also all be prepended to a Fields snippet; see http://graphql.org/learn/queries/ for more description of each of these concepts.
Types ¶
type Boolean ¶
type Boolean bool
Boolean represents true or false values.
func NewBoolean ¶
NewBoolean is a helper to make a new *Boolean.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a GraphQL client.
func NewClient ¶
NewClient creates a GraphQL client targeting the specified GraphQL server URL. If httpClient is nil, then http.DefaultClient is used.
func NewPluggableClient ¶
NewPluggableClient creates a GraphQL client using the transport implementation given. This is like NewClient, but can support any implementation, rather than just http. (This may also be useful for testing -- you can provide a transport which uses fixture data on the filesystem, for example!)
func (*Client) Mutate ¶
Mutate executes a single GraphQL mutation request, with a mutation derived from m, populating the response into it. m should be a pointer to struct that corresponds to the GraphQL schema.
func (*Client) MutateCustom ¶
func (c *Client) MutateCustom(ctx context.Context, m interface{}, query string, variables map[string]interface{}) error
MutateCustom executes a single GraphQL mutation request, with the query provided as a string, populating the response into m. m should be a pointer to struct that corresponds to the GraphQL schema, and the variables in the query must be provided by the variables map.
func (*Client) Query ¶
Query executes a single GraphQL query request, with a query derived from q, populating the response into it. q should be a pointer to struct that corresponds to the GraphQL schema.
func (*Client) QueryCustom ¶
func (c *Client) QueryCustom(ctx context.Context, q interface{}, query string, variables map[string]interface{}) error
QueryCustom executes a single GraphQL query request, with the query provided as a string, populating the response into q. slot should be a pointer to struct that corresponds to the GraphQL schema, and the variables in the query must be provided by the variables map.
type Float ¶
type Float float64
Float represents signed double-precision fractional values as specified by IEEE 754.
type ID ¶
type ID interface{}
ID represents a unique identifier that is Base64 obfuscated. It is often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as "VXNlci0xMA==") or integer (such as 4) input value will be accepted as an ID.
type Int ¶
type Int int32
Int represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.
type Request ¶
type Request struct { Query string `json:"query"` Variables map[string]interface{} `json:"variables,omitempty"` }
Request is a type used by the Transport interface. Users of the library don't need to use this type unless they're implementing a Transport.
Request gathers all fields used in a graphql request (the query together with assignments of any variables) together for serialization.
type Response ¶
type Response struct { Data json.RawMessage Errors errors }
Response is a type used by the Transport interface. Users of the library don't need to use this type unless they're implementing a Transport.
Response holds the main "data" of the response during the first phase of deserialization, and also recognizes any errors in the protocol response. (A second phase of deserialization maps the raw data into your go types; this is not handled by the Transport interface.)
type String ¶
type String string
String represents textual data as UTF-8 character sequences. This type is most often used by GraphQL to represent free-form human-readable text.
type Transport ¶
Transport is an interface that can be implemented to replace the serialization and network mechanism used by the client.
HTTP+JSON is the most common serialization and transport, and the default in this library, but you can define your own! There's no reason that GraphQL queries can't be issued over GRPC; mock transports that store and replay data may also be great for testing.
Directories ¶
Path | Synopsis |
---|---|
example
|
|
graphqldev
graphqldev is a test program currently being used for developing graphql package.
|
graphqldev is a test program currently being used for developing graphql package. |
Package ident provides functions for parsing and converting identifier names between various naming convention.
|
Package ident provides functions for parsing and converting identifier names between various naming convention. |
internal
|
|
jsonutil
Package jsonutil provides a function for decoding JSON into a GraphQL query data structure.
|
Package jsonutil provides a function for decoding JSON into a GraphQL query data structure. |