Documentation
¶
Overview ¶
Package graphql provides a GraphQL client with resilience patterns.
Index ¶
- func VarRef(name string) interface{}
- type Client
- func (c *Client) CircuitBreaker() *integration.CircuitBreaker
- func (c *Client) Config() integration.Config
- func (c *Client) Execute(ctx context.Context, req *Request, opts *ExecuteOptions) (*Response, error)
- func (c *Client) Mutate(ctx context.Context, mutation string, variables map[string]interface{}, ...) error
- func (c *Client) Query(ctx context.Context, query string, variables map[string]interface{}, ...) error
- func (c *Client) QueryWithOperation(ctx context.Context, query, operationName string, ...) error
- type Error
- type ExecuteOptions
- type FieldBuilder
- func (f *FieldBuilder) Alias(alias string) *FieldBuilder
- func (f *FieldBuilder) Arg(name string, value interface{}) *FieldBuilder
- func (f *FieldBuilder) Args(args map[string]interface{}) *FieldBuilder
- func (f *FieldBuilder) Done() *QueryBuilder
- func (f *FieldBuilder) Fragment(name string) *FieldBuilder
- func (f *FieldBuilder) Include(variableName string) *FieldBuilder
- func (f *FieldBuilder) Select(names ...string) *FieldBuilder
- func (f *FieldBuilder) Skip(variableName string) *FieldBuilder
- func (f *FieldBuilder) SubField(name string) *SubFieldBuilder
- func (f *FieldBuilder) VarArg(name, variableName string) *FieldBuilder
- type FragmentBuilder
- type GraphQLError
- type InlineFragment
- type Location
- type QueryBuilder
- func (q *QueryBuilder) Build() string
- func (q *QueryBuilder) Field(name string) *FieldBuilder
- func (q *QueryBuilder) Fields(names ...string) *QueryBuilder
- func (q *QueryBuilder) Fragment(name string) *QueryBuilder
- func (q *QueryBuilder) Name(name string) *QueryBuilder
- func (q *QueryBuilder) Variable(name, variableType string, defaultValue ...interface{}) *QueryBuilder
- type Request
- type Response
- type SubFieldBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a GraphQL client with resilience patterns.
func New ¶
func New(config integration.Config) (*Client, error)
New creates a new GraphQL client with the given configuration.
func (*Client) CircuitBreaker ¶
func (c *Client) CircuitBreaker() *integration.CircuitBreaker
CircuitBreaker returns the circuit breaker for this client.
func (*Client) Config ¶
func (c *Client) Config() integration.Config
Config returns the client configuration.
func (*Client) Execute ¶
func (c *Client) Execute(ctx context.Context, req *Request, opts *ExecuteOptions) (*Response, error)
Execute executes a GraphQL query or mutation.
func (*Client) Mutate ¶
func (c *Client) Mutate(ctx context.Context, mutation string, variables map[string]interface{}, result interface{}) error
Mutate executes a GraphQL mutation.
type Error ¶
type Error struct {
Message string `json:"message"`
Locations []Location `json:"locations,omitempty"`
Path []interface{} `json:"path,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
Error represents a GraphQL error.
type ExecuteOptions ¶
type ExecuteOptions struct {
Timeout time.Duration
SkipRetry bool
SkipCircuit bool
Headers http.Header
}
ExecuteOptions configures a GraphQL execution.
type FieldBuilder ¶
type FieldBuilder struct {
// contains filtered or unexported fields
}
FieldBuilder builds a field.
func (*FieldBuilder) Alias ¶
func (f *FieldBuilder) Alias(alias string) *FieldBuilder
Alias sets the field alias.
func (*FieldBuilder) Arg ¶
func (f *FieldBuilder) Arg(name string, value interface{}) *FieldBuilder
Arg adds an argument to the field.
func (*FieldBuilder) Args ¶
func (f *FieldBuilder) Args(args map[string]interface{}) *FieldBuilder
Args adds multiple arguments to the field.
func (*FieldBuilder) Done ¶
func (f *FieldBuilder) Done() *QueryBuilder
Done completes the field and returns the parent query builder.
func (*FieldBuilder) Fragment ¶
func (f *FieldBuilder) Fragment(name string) *FieldBuilder
Fragment adds a fragment reference.
func (*FieldBuilder) Include ¶
func (f *FieldBuilder) Include(variableName string) *FieldBuilder
Include adds @include directive.
func (*FieldBuilder) Select ¶
func (f *FieldBuilder) Select(names ...string) *FieldBuilder
Select adds sub-fields.
func (*FieldBuilder) Skip ¶
func (f *FieldBuilder) Skip(variableName string) *FieldBuilder
Skip adds @skip directive.
func (*FieldBuilder) SubField ¶
func (f *FieldBuilder) SubField(name string) *SubFieldBuilder
SubField adds a sub-field builder.
func (*FieldBuilder) VarArg ¶
func (f *FieldBuilder) VarArg(name, variableName string) *FieldBuilder
VarArg adds a variable argument to the field.
type FragmentBuilder ¶
type FragmentBuilder struct {
// contains filtered or unexported fields
}
FragmentBuilder builds a GraphQL fragment.
func NewFragment ¶
func NewFragment(name, onType string) *FragmentBuilder
NewFragment creates a new fragment builder.
func (*FragmentBuilder) Build ¶
func (f *FragmentBuilder) Build() string
Build builds the fragment definition.
func (*FragmentBuilder) Field ¶
func (f *FragmentBuilder) Field(name string, subFields ...string) *FragmentBuilder
Field adds a field with sub-selection.
func (*FragmentBuilder) Fields ¶
func (f *FragmentBuilder) Fields(names ...string) *FragmentBuilder
Fields adds fields to the fragment.
type GraphQLError ¶
type GraphQLError struct {
Errors []Error
}
GraphQLError represents a GraphQL error response.
func (*GraphQLError) Error ¶
func (e *GraphQLError) Error() string
Error implements the error interface.
type InlineFragment ¶
type InlineFragment struct {
// contains filtered or unexported fields
}
InlineFragment builds an inline fragment.
func NewInlineFragment ¶
func NewInlineFragment(onType string) *InlineFragment
NewInlineFragment creates a new inline fragment.
func (*InlineFragment) Build ¶
func (f *InlineFragment) Build() string
Build builds the inline fragment string.
func (*InlineFragment) Fields ¶
func (f *InlineFragment) Fields(names ...string) *InlineFragment
Fields adds fields to the inline fragment.
type QueryBuilder ¶
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder provides a fluent interface for building GraphQL queries.
func NewSubscription ¶
func NewSubscription() *QueryBuilder
NewSubscription creates a new subscription builder.
func (*QueryBuilder) Build ¶
func (q *QueryBuilder) Build() string
Build builds the GraphQL query string.
func (*QueryBuilder) Field ¶
func (q *QueryBuilder) Field(name string) *FieldBuilder
Field adds a field to the query.
func (*QueryBuilder) Fields ¶
func (q *QueryBuilder) Fields(names ...string) *QueryBuilder
Fields adds multiple simple fields.
func (*QueryBuilder) Fragment ¶
func (q *QueryBuilder) Fragment(name string) *QueryBuilder
Fragment adds a fragment reference.
func (*QueryBuilder) Name ¶
func (q *QueryBuilder) Name(name string) *QueryBuilder
Name sets the operation name.
func (*QueryBuilder) Variable ¶
func (q *QueryBuilder) Variable(name, variableType string, defaultValue ...interface{}) *QueryBuilder
Variable adds a variable definition.
type Request ¶
type Request struct {
Query string `json:"query"`
OperationName string `json:"operationName,omitempty"`
Variables map[string]interface{} `json:"variables,omitempty"`
}
Request represents a GraphQL request.
type Response ¶
type Response struct {
Data json.RawMessage `json:"data"`
Errors []Error `json:"errors,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
StatusCode int
Duration time.Duration
}
Response represents a GraphQL response.
func (*Response) FirstError ¶
FirstError returns the first error if present.
func (*Response) UnmarshalData ¶
UnmarshalData unmarshals the response data into the given value.
type SubFieldBuilder ¶
type SubFieldBuilder struct {
// contains filtered or unexported fields
}
SubFieldBuilder builds a sub-field.
func (*SubFieldBuilder) Alias ¶
func (sf *SubFieldBuilder) Alias(alias string) *SubFieldBuilder
Alias sets the sub-field alias.
func (*SubFieldBuilder) Arg ¶
func (sf *SubFieldBuilder) Arg(name string, value interface{}) *SubFieldBuilder
Arg adds an argument to the sub-field.
func (*SubFieldBuilder) Done ¶
func (sf *SubFieldBuilder) Done() *FieldBuilder
Done completes the sub-field and returns the parent field builder.
func (*SubFieldBuilder) Select ¶
func (sf *SubFieldBuilder) Select(names ...string) *SubFieldBuilder
Select adds nested fields.