grx

plugins

API reference for the plugins package, generated from Go doc comments.

import "github.com/grx-gql/grx/plugins"

Package plugins defines GraphQL execution lifecycle hooks.

Plugins run inside the GraphQL executor after an HTTP transport has decoded a request. Use them for GraphQL-aware concerns such as parsing, validation, execution, field resolution, response, and error observation. Use HTTP middleware for transport concerns such as headers, cookies, CORS, request IDs, and authentication before the GraphQL request is decoded.

Index

type Base

Base is a no-op implementation of Plugin. Embed it in a custom plugin to get default implementations of every hook and only override the ones you care about.

type Base struct{}

func (Base) Error

func (Base) Error(ctx context.Context, err error)

Error is a no-op.

func (Base) ExecutionStart

func (Base) ExecutionStart(ctx context.Context, req core.Request) error

ExecutionStart is a no-op.

func (Base) FieldResolveStart

func (Base) FieldResolveStart(ctx context.Context, field FieldContext) error

FieldResolveStart is a no-op.

func (Base) ParsingStart

func (Base) ParsingStart(ctx context.Context, req core.Request) error

ParsingStart is a no-op.

func (Base) RequestStart

func (Base) RequestStart(ctx context.Context, req core.Request) (context.Context, error)

RequestStart returns ctx unchanged.

func (Base) ResponseSend

func (Base) ResponseSend(ctx context.Context, res core.Response) error

ResponseSend is a no-op.

func (Base) ValidationStart

func (Base) ValidationStart(ctx context.Context, req core.Request) error

ValidationStart is a no-op.

type FieldContext

FieldContext describes a single field resolution inside a selection set. Path is the response path (using GraphQL response-path semantics) and FieldName is the GraphQL field name being resolved.

type FieldContext struct {
    Path      []string
    FieldName string
}

type Plugin

Plugin is the lifecycle interface a GraphQL observer or extension implements. Hooks are invoked in registration order; returning a non-nil error from any hook (other than RequestStart) aborts the current request and surfaces the error to the client. RequestStart may additionally return a derived context that becomes the parent context for every subsequent hook of the same request.

Implementations should be safe for concurrent use because a single Plugin instance is shared across all in-flight requests.

type Plugin interface {
    RequestStart(ctx context.Context, req core.Request) (context.Context, error)
    ParsingStart(ctx context.Context, req core.Request) error
    ValidationStart(ctx context.Context, req core.Request) error
    ExecutionStart(ctx context.Context, req core.Request) error
    FieldResolveStart(ctx context.Context, field FieldContext) error
    ResponseSend(ctx context.Context, res core.Response) error
    Error(ctx context.Context, err error)
}

type RequestContext

RequestContext carries per-request data passed to plugin hooks that operate at the request granularity.

type RequestContext struct {
    Request core.Request
}

Generated by gomarkdoc

Edit this page on GitHub

Last updated on

On this page