grx

schema

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

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

Package schema describes the runtime metadata that the executor uses to resolve GraphQL operations. It also exposes the Build entry point that reflects user-defined Go types into this metadata.

The types here mirror the GraphQL type system from the October 2021 specification. Reflection is confined to schema-build time so the executor's per-request hot path stays allocation-aware.

Index

type Builder

Builder accumulates the type registry while a Schema is being assembled. It is not safe for concurrent use; construct one per Build call.

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

type Config

Config holds the user-supplied root resolvers that Build reflects into a runtime Schema. Query is required; Mutation and Subscription are optional.

type Config struct {
    // Query is the root query resolver value. Its exported methods are
    // reflected into fields on the GraphQL Query root type.
    Query any
    // Mutation is the root mutation resolver value. Optional.
    Mutation any
    // Subscription is the root subscription resolver value. Optional.
    Subscription any
}

type Field

Field describes a single field on an object, interface, or input object. Args is empty when the field takes no arguments.

type Field struct {
    Name     string
    Type     Type
    Args     []InputValue
    Resolver Resolver
}

type InputObject

InputObject describes a GraphQL input object type. The Resolver field of each entry in Fields is unused; only Name and Type are meaningful.

type InputObject struct {
    TypeName string
    Fields   map[string]*Field
}

func (*InputObject) Kind

func (i *InputObject) Kind() Kind

Kind returns InputObjectKind.

func (*InputObject) Name

func (i *InputObject) Name() string

Name returns the input object type name.

type InputValue

InputValue describes a single argument or input-object field. DefaultValue is nil when the input has no default.

type InputValue struct {
    Name         string
    Type         Type
    DefaultValue any
}

type Interface

Interface describes a GraphQL interface type.

type Interface struct {
    TypeName string
    Fields   map[string]*Field
}

func (*Interface) Kind

func (i *Interface) Kind() Kind

Kind returns InterfaceKind.

func (*Interface) Name

func (i *Interface) Name() string

Name returns the interface type name.

type Kind

Kind identifies a GraphQL type kind, matching the introspection __TypeKind enum.

type Kind string

ScalarKind

GraphQL type kinds. See https://spec.graphql.org/October2021/#sec-Types.

const (
    ScalarKind      Kind = "SCALAR"
    ObjectKind      Kind = "OBJECT"
    InterfaceKind   Kind = "INTERFACE"
    UnionKind       Kind = "UNION"
    EnumKind        Kind = "ENUM"
    InputObjectKind Kind = "INPUT_OBJECT"
    ListKind        Kind = "LIST"
    NonNullKind     Kind = "NON_NULL"
)

type List

List wraps another Type to represent a GraphQL list (`[T]`).

type List struct {
    OfType Type
}

func (*List) Kind

func (l *List) Kind() Kind

Kind returns ListKind.

func (*List) Name

func (l *List) Name() string

Name returns the printable list type name, e.g. "[Int]" or "[User!]".

type NonNull

NonNull wraps another Type to represent a GraphQL non-null type (`T!`). Resolving a NonNull field to nil produces a runtime error.

type NonNull struct {
    OfType Type
}

func (*NonNull) Kind

func (n *NonNull) Kind() Kind

Kind returns NonNullKind.

func (*NonNull) Name

func (n *NonNull) Name() string

Name returns the printable non-null type name, e.g. "Int!" or "[User]!".

type Object

Object describes a GraphQL object type. Fields is keyed by GraphQL field name (already lowercased from the originating Go method name).

type Object struct {
    TypeName string
    Fields   map[string]*Field
}

func (*Object) Kind

func (o *Object) Kind() Kind

Kind returns ObjectKind.

func (*Object) Name

func (o *Object) Name() string

Name returns the object type name.

type ResolveParams

ResolveParams carries the inputs delivered to a Resolver. Source is the parent object value (nil at the root) and Args is the validated argument map for the field.

type ResolveParams struct {
    Source any
    Args   map[string]any
}

type Resolver

Resolver is the function the executor invokes to produce the value of a single field. Implementations should be safe for concurrent use.

type Resolver func(ctx context.Context, params ResolveParams) (any, error)

type Scalar

Scalar represents a GraphQL scalar type such as String, Int, Float, Boolean, ID, or a custom user-defined scalar.

type Scalar struct {
    TypeName string
}

func (*Scalar) Kind

func (s *Scalar) Kind() Kind

Kind returns ScalarKind.

func (*Scalar) Name

func (s *Scalar) Name() string

Name returns the scalar type name.

type Schema

Schema is the fully built type system the executor operates on. Query is required; Mutation and Subscription are nil when the user did not supply the corresponding root. Types is the type registry keyed by GraphQL type name and is used by the introspection fast-path.

type Schema struct {
    Query        *Object
    Mutation     *Object
    Subscription *Object
    Types        map[string]Type
}

func Build

func Build(config Config) (*Schema, error)

Build reflects the supplied resolver values into a runtime Schema. It returns an error when the configuration is inconsistent (e.g. missing Query root, both Schema and root fields supplied) or when a resolver cannot be reflected into the GraphQL type system.

type Type

Type is the common interface implemented by every GraphQL type. Name returns the printable type name (e.g. "User", "[Int!]!") and Kind returns the Kind discriminator.

type Type interface {
    Name() string
    Kind() Kind
}

type Union

Union describes a GraphQL union type as the set of object types it can resolve to.

type Union struct {
    TypeName string
    Types    []*Object
}

func (*Union) Kind

func (u *Union) Kind() Kind

Kind returns UnionKind.

func (*Union) Name

func (u *Union) Name() string

Name returns the union type name.

Generated by gomarkdoc

Edit this page on GitHub

Last updated on

On this page