graphql

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package graphql provides a GraphQL client with resilience patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VarRef

func VarRef(name string) interface{}

VarRef creates a variable reference for use in query arguments. This allows referencing query variables in field arguments.

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.

func (*Client) Query

func (c *Client) Query(ctx context.Context, query string, variables map[string]interface{}, result interface{}) error

Query executes a GraphQL query.

func (*Client) QueryWithOperation

func (c *Client) QueryWithOperation(ctx context.Context, query, operationName string, variables map[string]interface{}, result interface{}) error

QueryWithOperation executes a named GraphQL query.

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.

func (Error) Error

func (e Error) Error() string

Error implements the error interface.

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 Location

type Location struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

Location represents a location in a GraphQL document.

type QueryBuilder

type QueryBuilder struct {
	// contains filtered or unexported fields
}

QueryBuilder provides a fluent interface for building GraphQL queries.

func NewMutation

func NewMutation() *QueryBuilder

NewMutation creates a new mutation builder.

func NewQuery

func NewQuery() *QueryBuilder

NewQuery creates a new query builder.

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

func (r *Response) FirstError() *Error

FirstError returns the first error if present.

func (*Response) HasError

func (r *Response) HasError() bool

HasError checks if the response contains a specific error.

func (*Response) UnmarshalData

func (r *Response) UnmarshalData(v interface{}) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL