thistle – git.sr.ht/~adnano/thistle Index | Files | Directories

package thistle

import "git.sr.ht/~adnano/thistle"

Index

Variables

var Prelude = &ast.Source{
	Name:    "federation.graphql",
	Input:   federationGraphql,
	BuiltIn: true,
}

Functions

func AddHeader

func AddHeader(ctx context.Context, key, value string) context.Context

AddHeader adds a HTTP header to downstream GraphQL requests for the current GraphQL operation.

Types

type Client

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

Client is a GraphQL client.

func NewClient

func NewClient(hc *http.Client) *Client

NewClient creates a new GraphQL client.

If hc is nil, http.DefaultClient will be used.

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, url string, op *Operation, data interface{}) error

Execute executes a GraphQL operation.

The data returned by the server will be decoded into the data argument.

func (*Client) WithUserAgent

func (c *Client) WithUserAgent(userAgent string) *Client

WithUserAgent sets the user agent used by the client.

type Gateway

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

Gateway is a GraphQL federation gateway.

Gateway implements gqlgen/graphql.ExecutableSchema.

func NewGateway

func NewGateway() *Gateway

NewGateway creates a new GraphQL federation gateway.

func (*Gateway) Complexity

func (g *Gateway) Complexity(typeName, fieldName string, childComplexity int, args map[string]interface{}) (int, bool)

Complexity returns the query complexity (unimplemented)

func (*Gateway) Exec

Exec returns the execution handler.

func (*Gateway) Execute

func (g *Gateway) Execute(ctx context.Context) *graphql.Response

Execute executes a GraphQL operation.

func (*Gateway) Schema

func (g *Gateway) Schema() *ast.Schema

Schema returns the federated schema.

func (*Gateway) SetSchema

func (g *Gateway) SetSchema(schema *Schema)

SetSchema sets the federated schema used by the gateway.

SetSchema is safe for concurrent use by multiple goroutines.

func (*Gateway) WithClient

func (g *Gateway) WithClient(client *Client) *Gateway

WithClient configures the client used for downstream GraphQL operations.

func (*Gateway) WithDebugExtensions

func (g *Gateway) WithDebugExtensions(enabled bool) *Gateway

WithDebugExtensions configures debugging information for GraphQL requests.

If enabled, debug information will be added to the response extensions. The following information will be provided:

func (*Gateway) WithMaxRequests

func (g *Gateway) WithMaxRequests(maxRequests int64) *Gateway

WithMaxRequests configures the maximum number of requests to make per query.

type Operation

type Operation struct {
	Name      string                    `json:"operationName,omitempty"`
	Query     string                    `json:"query"`
	Variables map[string]interface{}    `json:"variables,omitempty"`
	Uploads   map[string]graphql.Upload `json:"-"`
}

Operation is a GraphQL operation.

type Response

type Response struct {
	Data   interface{}   `json:"data"`
	Errors gqlerror.List `json:"errors"`
}

Response is a GraphQL response.

type Schema

type Schema struct {
	ast.Schema
	// contains filtered or unexported fields
}

Schema represents a federated GraphQL schema.

func BuildSchema

func BuildSchema(services ...*Service) (*Schema, error)

BuildSchema builds and returns a new federated GraphQL schema.

func (*Schema) HasField

func (s *Schema) HasField(location, typeName, field string) bool

HasField reports whether the given location can resolve the given field.

func (*Schema) IsEntity

func (s *Schema) IsEntity(typeName string) bool

IsEntity reports whether the given type is an entity type.

func (*Schema) IsKey

func (s *Schema) IsKey(typeName string, field string) bool

IsKey reports whether the given field is a key field.

func (*Schema) Key

func (s *Schema) Key(typeName string) []string

Key returns a list of key fields for the given entity type.

func (*Schema) Requires

func (s *Schema) Requires(typeName string, field string) []string

Requires returns a list of fields required by the given field.

func (*Schema) Route

func (s *Schema) Route(parentType string, parentLocation string, input ast.SelectionSet) (map[string]ast.SelectionSet, error)

Route routes a selection set by location.

type Service

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

Service is a downstream GraphQL service.

func NewService

func NewService(name, url string) *Service

NewService creates a new downstream service.

func (*Service) Name

func (s *Service) Name() string

Name returns the downstream service name.

func (*Service) SDL

func (s *Service) SDL() string

SDL returns the downstream service definition.

func (*Service) SetSDL

func (s *Service) SetSDL(sdl string) error

SetSDL sets the service definition for the downstream service.

func (*Service) Status

func (s *Service) Status() Status

Status returns the downstream service status.

func (*Service) URL

func (s *Service) URL() string

URL returns the downstream service URL.

func (*Service) Update

func (s *Service) Update(ctx context.Context, client *Client) (bool, error)

Update fetches and validates the service definition from downstream and reports whether the service definition was updated.

type Status

type Status int

Status represents the status of a downstream service.

const (
	StatusNone Status = iota
	StatusOK
	StatusUnreachable
	StatusInvalid
)

Source Files

client.go directives.go execution.go format.go gateway.go introspection.go plan.go schema.go service.go

Directories

PathSynopsis
admin
fieldsetPackage fieldset provides functions for parsing _FieldSet scalars.
Version
v0.0.0-20230629043621-3712696d8056 (latest)
Published
Jun 29, 2023
Platform
linux/amd64
Imports
28 packages
Last checked
2 months ago

Tools for package owners.