graphql

package module
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 19 Imported by: 24

README

nautilus/graphql Build Status Coverage Status Go Report Card Go Reference

A package that wraps vektah/gqlparser with convenience methods for building GraphQL tools on the server, like nautilus/gateway.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IntrospectionQuery = `` /* 1141-byte string literal not displayed */

IntrospectionQuery is the query that is fired at an API to reconstruct its schema

Functions

func ApplyFragments

func ApplyFragments(selectionSet ast.SelectionSet, fragmentDefs ast.FragmentDefinitionList) (ast.SelectionSet, error)

ApplyFragments takes a list of selections and merges them into one, embedding any fragments it runs into along the way

func ExtractVariables

func ExtractVariables(args ast.ArgumentList) []string

ExtractVariables takes a list of arguments and returns a list of every variable used

func FormatSelectionSet added in v0.0.8

func FormatSelectionSet(selection ast.SelectionSet) string

FormatSelectionSet returns a pretty printed version of a selection set

func IntrospectAPI

func IntrospectAPI(queryer Queryer, opts ...*IntrospectOptions) (*ast.Schema, error)

IntrospectAPI send the introspection query to a Queryer and builds up the schema object described by the result

func LoadSchema

func LoadSchema(typedef string) (*ast.Schema, error)

LoadSchema takes an SDL string and returns the parsed version

func PrintQuery

func PrintQuery(document *ast.QueryDocument) (string, error)

PrintQuery creates a string representation of an operation

func SelectedFields

func SelectedFields(source ast.SelectionSet) []*ast.Field

Types

type CountRetrier added in v0.0.22

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

CountRetrier is a Retrier that stops after a number of attempts.

func NewCountRetrier added in v0.0.22

func NewCountRetrier(maxRetries uint) CountRetrier

NewCountRetrier returns a CountRetrier with the given maximum number of retries beyond the first attempt.

func (CountRetrier) ShouldRetry added in v0.0.22

func (c CountRetrier) ShouldRetry(err error, attempts uint) bool

type Error

type Error struct {
	Extensions map[string]interface{} `json:"extensions"`
	Message    string                 `json:"message"`
	Path       []interface{}          `json:"path,omitempty"`
}

Error represents a graphql error

func NewError

func NewError(code string, message string) *Error

NewError returns a graphql error with the given code and message

func (*Error) Error

func (e *Error) Error() string

type ErrorList

type ErrorList []error

ErrorList represents a list of errors

func (ErrorList) Error

func (list ErrorList) Error() string

Error returns a string representation of each error

type File added in v0.0.11

type File interface {
	io.Reader
	io.Closer
}

type HTTPQueryer

type HTTPQueryer interface {
	WithHTTPClient(client *http.Client) Queryer
}

HTTPQueryer is an interface for queryers that let you configure an underlying http.Client

type HTTPQueryerWithMiddlewares

type HTTPQueryerWithMiddlewares interface {
	WithHTTPClient(client *http.Client) Queryer
	WithMiddlewares(wares []NetworkMiddleware) Queryer
}

HTTPQueryerWithMiddlewares is an interface for queryers that let you configure an underlying http.Client and accept middlewares

type IntrospectOptions added in v0.0.14

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

IntrospectOptions represents the options for the IntrospectAPI function

func IntrospectWithContext added in v0.0.14

func IntrospectWithContext(ctx context.Context) *IntrospectOptions

IntrospectWithHTTPClient returns an instance of graphql.IntrospectOptions with given context to be used as a parameter for graphql.Queryer.Query function in the graphql.IntrospectAPI function

func IntrospectWithHTTPClient added in v0.0.14

func IntrospectWithHTTPClient(client *http.Client) *IntrospectOptions

IntrospectWithHTTPClient returns an instance of graphql.IntrospectOptions with given client to be pass to an instance of a graphql.Queryer by the IntrospectOptions.Apply function

func IntrospectWithMiddlewares added in v0.0.14

func IntrospectWithMiddlewares(wares ...NetworkMiddleware) *IntrospectOptions

IntrospectWithMiddlewares returns an instance of graphql.IntrospectOptions with given middlewares to be pass to an instance of a graphql.Queryer by the IntrospectOptions.Apply function

func IntrospectWithRetrier added in v0.0.22

func IntrospectWithRetrier(retrier Retrier) *IntrospectOptions

IntrospectWithRetrier returns an instance of graphql.IntrospectOptions with the given Retrier. For a fixed number of retries, see CountRetrier.

func (*IntrospectOptions) Apply added in v0.0.14

func (o *IntrospectOptions) Apply(queryer Queryer) Queryer

Apply applies the options to a given queryer

func (*IntrospectOptions) Context added in v0.0.14

func (o *IntrospectOptions) Context() context.Context

Context returns either a given context or an instance of the context.Background

type IntrospectionInputValue

type IntrospectionInputValue struct {
	Name         string               `json:"name"`
	Description  string               `json:"description"`
	DefaultValue string               `json:"defaultValue"`
	Type         IntrospectionTypeRef `json:"type"`
}

type IntrospectionQueryDirective

type IntrospectionQueryDirective struct {
	Name        string                    `json:"name"`
	Description string                    `json:"description"`
	Locations   []string                  `json:"locations"`
	Args        []IntrospectionInputValue `json:"args"`
}

type IntrospectionQueryEnumDefinition

type IntrospectionQueryEnumDefinition struct {
	Name              string `json:"name"`
	Description       string `json:"description"`
	IsDeprecated      bool   `json:"isDeprecated"`
	DeprecationReason string `json:"deprecationReason"`
}

type IntrospectionQueryFullType

type IntrospectionQueryFullType struct {
	Kind          string                             `json:"kind"`
	Name          string                             `json:"name"`
	Description   string                             `json:"description"`
	InputFields   []IntrospectionInputValue          `json:"inputFields"`
	Interfaces    []IntrospectionTypeRef             `json:"interfaces"`
	PossibleTypes []IntrospectionTypeRef             `json:"possibleTypes"`
	Fields        []IntrospectionQueryFullTypeField  `json:"fields"`
	EnumValues    []IntrospectionQueryEnumDefinition `json:"enumValues"`
}

type IntrospectionQueryFullTypeField

type IntrospectionQueryFullTypeField struct {
	Name              string                    `json:"name"`
	Description       string                    `json:"description"`
	Args              []IntrospectionInputValue `json:"args"`
	Type              IntrospectionTypeRef      `json:"type"`
	IsDeprecated      bool                      `json:"isDeprecated"`
	DeprecationReason string                    `json:"deprecationReason"`
}

type IntrospectionQueryResult

type IntrospectionQueryResult struct {
	Schema *IntrospectionQuerySchema `json:"__schema"`
}

type IntrospectionQueryRootType

type IntrospectionQueryRootType struct {
	Name string `json:"name"`
}

type IntrospectionQuerySchema

type IntrospectionQuerySchema struct {
	QueryType        IntrospectionQueryRootType    `json:"queryType"`
	MutationType     *IntrospectionQueryRootType   `json:"mutationType"`
	SubscriptionType *IntrospectionQueryRootType   `json:"subscriptionType"`
	Types            []IntrospectionQueryFullType  `json:"types"`
	Directives       []IntrospectionQueryDirective `json:"directives"`
}

type IntrospectionTypeRef

type IntrospectionTypeRef struct {
	Kind   string                `json:"kind"`
	Name   string                `json:"name"`
	OfType *IntrospectionTypeRef `json:"ofType"`
}

type MockSuccessQueryer

type MockSuccessQueryer struct {
	Value interface{}
}

MockSuccessQueryer responds with pre-defined value when executing a query

func (*MockSuccessQueryer) Query

func (q *MockSuccessQueryer) Query(ctx context.Context, input *QueryInput, receiver interface{}) error

Query looks up the name of the query in the map of responses and returns the value

type MultiOpQueryer

type MultiOpQueryer struct {
	MaxBatchSize  int
	BatchInterval time.Duration
	// contains filtered or unexported fields
}

MultiOpQueryer is a queryer that will batch subsequent query on some interval into a single network request to a single target

func NewMultiOpQueryer

func NewMultiOpQueryer(url string, interval time.Duration, maxBatchSize int) *MultiOpQueryer

NewMultiOpQueryer returns a MultiOpQueryer with the provided parameters

func (*MultiOpQueryer) Query

func (q *MultiOpQueryer) Query(ctx context.Context, input *QueryInput, receiver interface{}) error

Query bundles queries that happen within the given interval into a single network request whose body is a list of the operation payload.

func (*MultiOpQueryer) WithHTTPClient

func (q *MultiOpQueryer) WithHTTPClient(client *http.Client) Queryer

WithHTTPClient lets the user configure the client to use when making network requests

func (*MultiOpQueryer) WithMiddlewares

func (q *MultiOpQueryer) WithMiddlewares(mwares []NetworkMiddleware) Queryer

WithMiddlewares lets the user assign middlewares to the queryer

type NetworkMiddleware

type NetworkMiddleware func(*http.Request) error

NetworkMiddleware are functions can be passed to SingleRequestQueryer.WithMiddleware to affect its internal behavior

type NetworkQueryer

type NetworkQueryer struct {
	URL         string
	Middlewares []NetworkMiddleware
	Client      *http.Client
}

func (*NetworkQueryer) ExtractErrors

func (q *NetworkQueryer) ExtractErrors(result map[string]interface{}) error

ExtractErrors takes the result from a remote query and writes it to the provided pointer

func (*NetworkQueryer) SendMultipart added in v0.0.11

func (q *NetworkQueryer) SendMultipart(ctx context.Context, payload []byte, contentType string) ([]byte, error)

SendMultipart is responsible for sending multipart request to the desingated URL

func (*NetworkQueryer) SendQuery

func (q *NetworkQueryer) SendQuery(ctx context.Context, payload []byte) ([]byte, error)

SendQuery is responsible for sending the provided payload to the desingated URL

type QueryInput

type QueryInput struct {
	Query         string                 `json:"query"`
	QueryDocument *ast.QueryDocument     `json:"-"`
	OperationName string                 `json:"operationName"`
	Variables     map[string]interface{} `json:"variables"`
}

QueryInput provides all of the information required to fire a query

func (*QueryInput) Raw

func (i *QueryInput) Raw() interface{}

Raw returns the "raw underlying value of the key" when used by dataloader

func (*QueryInput) String

func (i *QueryInput) String() string

String returns a guaranteed unique string that can be used to identify the input

type Queryer

type Queryer interface {
	Query(context.Context, *QueryInput, interface{}) error
}

Queryer is a interface for objects that can perform

type QueryerFunc

type QueryerFunc func(*QueryInput) (interface{}, error)

QueryerFunc responds to the query by calling the provided function

func (QueryerFunc) Query

func (q QueryerFunc) Query(ctx context.Context, input *QueryInput, receiver interface{}) error

Query invokes the provided function and writes the response to the receiver

type QueryerWithMiddlewares

type QueryerWithMiddlewares interface {
	WithMiddlewares(wares []NetworkMiddleware) Queryer
}

QueryerWithMiddlewares is an interface for queryers that support network middlewares

type RemoteSchema

type RemoteSchema struct {
	Schema *ast.Schema
	URL    string
}

RemoteSchema encapsulates a particular schema that can be executed by sending network requests to the specified URL.

func IntrospectRemoteSchema

func IntrospectRemoteSchema(url string, opts ...*IntrospectOptions) (*RemoteSchema, error)

IntrospectRemoteSchema is used to build a RemoteSchema by firing the introspection query at a remote service and reconstructing the schema object from the response

func IntrospectRemoteSchemas

func IntrospectRemoteSchemas(urls ...string) ([]*RemoteSchema, error)

IntrospectRemoteSchemas takes a list of URLs and creates a RemoteSchema by invoking graphql.IntrospectRemoteSchema at that location.

func IntrospectRemoteSchemasWithOptions added in v0.0.14

func IntrospectRemoteSchemasWithOptions(urls []string, opts ...*IntrospectOptions) ([]*RemoteSchema, error)

IntrospectRemoteSchemasWithOptions takes a list of URLs and an optional list of graphql.IntrospectionOptions and creates a RemoteSchema by invoking graphql.IntrospectRemoteSchema at that location.

type Retrier added in v0.0.22

type Retrier interface {
	// ShouldRetry returns true if another attempt should run,
	// given 'err' from the previous attempt and the total attempt count (starts at 1).
	//
	// Consider the 'errors' package to unwrap the error. e.g. errors.As(), errors.Is()
	ShouldRetry(err error, attempts uint) bool
}

Retrier indicates whether or not to retry and attempt another query.

type SingleRequestQueryer

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

SingleRequestQueryer sends the query to a url and returns the response

func NewSingleRequestQueryer

func NewSingleRequestQueryer(url string) *SingleRequestQueryer

NewSingleRequestQueryer returns a SingleRequestQueryer pointed to the given url

func (*SingleRequestQueryer) Query

func (q *SingleRequestQueryer) Query(ctx context.Context, input *QueryInput, receiver interface{}) error

Query sends the query to the designated url and returns the response.

func (*SingleRequestQueryer) URL

func (q *SingleRequestQueryer) URL() string

func (*SingleRequestQueryer) WithHTTPClient

func (q *SingleRequestQueryer) WithHTTPClient(client *http.Client) Queryer

WithHTTPClient lets the user configure the underlying http client being used

func (*SingleRequestQueryer) WithMiddlewares

func (q *SingleRequestQueryer) WithMiddlewares(mwares []NetworkMiddleware) Queryer

WithMiddlewares returns a network queryer that will apply the provided middlewares

type Upload added in v0.0.11

type Upload struct {
	File     File
	FileName string
}

type UploadMap added in v0.0.11

type UploadMap []struct {
	// contains filtered or unexported fields
}

func (*UploadMap) Add added in v0.0.11

func (u *UploadMap) Add(upload Upload, varName string)

func (*UploadMap) NotEmpty added in v0.0.11

func (u *UploadMap) NotEmpty() bool

func (*UploadMap) UploadMap added in v0.0.11

func (u *UploadMap) UploadMap() map[string][]string

Jump to

Keyboard shortcuts

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