Documentation ¶
Overview ¶
Package gqlserver provides a GraphQL server. It is a singleton initialized via init() functions.
Index ¶
- Variables
- func AddCounters(cfg *CountersConfig)
- func AddMutation(f *graphql.Field)
- func AddQuery(f *graphql.Field)
- func AddSubscription(f *graphql.Field)
- func BindArguments[T any](m FieldTypes) graphql.FieldConfigArgument
- func BindFields[T any](m FieldTypes) graphql.Fields
- func BindInputFields[T any](m FieldTypes) graphql.InputObjectConfigFieldMap
- func FieldDefToField(d *graphql.FieldDefinition) *graphql.Field
- func ImplementsInterface[T any](ot *graphql.Object, it *Interface)
- func NewListNonNullBoth(ofType graphql.Type) graphql.Type
- func NewListNonNullElem(ofType graphql.Type) graphql.Type
- func NewListNonNullList(ofType graphql.Type) graphql.Type
- func NewStringEnum[T ~string](name, desc string, values ...T) *graphql.Enum
- func Optional(value any) any
- func Prepare()
- func PublishChan(f func(updates chan<- any)) (any, error)
- func PublishInterval(p graphql.ResolveParams, read graphql.FieldResolveFn, enders ...any) (results any, e error)
- func RetrieveNode(id string) (any, error)
- type CountersConfig
- type FieldTypes
- type Interface
- type NodeConfig
- type NodeType
- type NodeTypeBase
Constants ¶
This section is empty.
Variables ¶
var ( JSON = tools_scalars.ScalarJSON Bytes = go2gql_scalars.GraphQLBytesScalar Uint64 = go2gql_scalars.GraphQLUInt64Scalar Int64 = go2gql_scalars.GraphQLInt64Scalar Uint32 = go2gql_scalars.GraphQLUInt32Scalar NonNullJSON = graphql.NewNonNull(JSON) NonNullUint64 = graphql.NewNonNull(Uint64) NonNullInt64 = graphql.NewNonNull(Int64) NonNullUint32 = graphql.NewNonNull(Uint64) NonNullID = graphql.NewNonNull(graphql.ID) NonNullBoolean = graphql.NewNonNull(graphql.Boolean) NonNullInt = graphql.NewNonNull(graphql.Int) NonNullString = graphql.NewNonNull(graphql.String) )
Scalar types.
var Schema = &graphql.SchemaConfig{ Query: graphql.NewObject(graphql.ObjectConfig{ Name: "Query", Fields: graphql.Fields{}, }), Mutation: graphql.NewObject(graphql.ObjectConfig{ Name: "Mutation", Fields: graphql.Fields{}, }), Subscription: graphql.NewObject(graphql.ObjectConfig{ Name: "Subscription", Fields: graphql.Fields{}, }), }
Schema is the singleton of graphql.SchemaConfig. It is available until Prepare() is called.
Functions ¶
func AddCounters ¶
func AddCounters(cfg *CountersConfig)
AddCounters defines a counters-like field as both a query field and a subscription.
func AddSubscription ¶
AddSubscription adds a top-level subscription field.
func BindArguments ¶
func BindArguments[T any](m FieldTypes) graphql.FieldConfigArgument
BindArguments creates graphql.FieldConfigArgument from a struct.
func BindFields ¶
func BindFields[T any](m FieldTypes) graphql.Fields
BindFields creates graphql.Fields from a struct. Field resolvers can accept either T or *T as source object.
func BindInputFields ¶
func BindInputFields[T any](m FieldTypes) graphql.InputObjectConfigFieldMap
BindInputFields creates graphql.InputObjectConfigFieldMap from a struct.
func FieldDefToField ¶
func FieldDefToField(d *graphql.FieldDefinition) *graphql.Field
FieldDefToField converts FieldDefinition to *Field.
func ImplementsInterface ¶
ImplementsInterface records an object implementing an interface. This also appends the object to Schema.Types to ensure that it appears in the schema.
func NewListNonNullBoth ¶
NewListNonNullBoth constructs [T!]! type.
func NewListNonNullElem ¶
NewListNonNullElem constructs [T!] type.
func NewListNonNullList ¶
NewListNonNullList constructs [T]! type.
func NewStringEnum ¶
NewStringEnum constructs an enum type.
func Prepare ¶
func Prepare()
Prepare compiles the schema and adds handlers on http.DefaultServeMux.
func PublishChan ¶
PublishChan publishes a channel in reply to GraphQL subscription.
f is a callback function that sends its results into a channel. It should not close the channel - the channel will be closed by the caller when f returns.
func PublishInterval ¶
func PublishInterval(p graphql.ResolveParams, read graphql.FieldResolveFn, enders ...any) (results any, e error)
PublishInterval publishes results at an interval in reply to GraphQL subscription.
read is a callback function that returns a single result. enders are channels that indicate the subscription should be canceled, when a value is received or the channel is closed.
Types ¶
type CountersConfig ¶
type CountersConfig struct { Description string // Parent is the parent object to define a query field. // If nil, no query field is defined. Parent *graphql.Object // Name is the field name to be defined in Parent. // If empty, no query field is defined. Name string // Subscription is the field name to be defined as subscription. // If empty, no subscription is defined. Subscription string // NoDiff indicates diff=true is not supported. // This should be set if some fields are lazily-injected with FieldResolveFn, as subtract algorithm cannot see them. NoDiff bool // FindArgs declares GraphQL arguments for finding the source object. FindArgs graphql.FieldConfigArgument // Find finds source object from FindArgs in a subscription. // p.Source is unspecified. // p.Args contains arguments declared in both Args and FindArgs. // enders: see PublishInterval. Find func(p graphql.ResolveParams) (source any, enders []any, e error) // Type declares GraphQL return type. Type graphql.Output // Args declares GraphQL arguments for customizing counters. Args graphql.FieldConfigArgument // Read retrieves counters from p.Source. // p.Source is a value from Parent or a return value from Find. // p.Args contains arguments declared in Args. Read graphql.FieldResolveFn }
CountersConfig contains options to publish a counters-like type.
type FieldTypes ¶
FieldTypes contains known GraphQL types of fields.
type Interface ¶
Interface defines a GraphQL interface.
func NewInterface ¶
func NewInterface(ic graphql.InterfaceConfig) (it *Interface)
NewInterface creates a GraphQL interface. ic.Fields should contain necessary fields. ic.ResolveType will be overwritten.
func (*Interface) AppendTo ¶
func (it *Interface) AppendTo(oc *graphql.ObjectConfig)
AppendTo appends this interface to oc.Interfaces slice.
func (*Interface) CopyFieldsTo ¶
CopyFieldsTo adds fields of this interface into InterfaceConfig.Fields or ObjectConfig.Fields. If a field of same name exists at the destination, only Type and Description are overwritten. This may be used for inheritance between interfaces or for sharing implementation.
type NodeConfig ¶
type NodeConfig[T any] struct { // GetID extracts un-prefixed ID from the source object. GetID func(source T) string // Retrieve fetches an object from un-prefixed ID. // Returning zero value indicates the object does not exist. Retrieve func(id string) T // RetrieveInt fetches an object from un-prefixed ID parsed as integer. RetrieveInt func(id int) T // Delete deletes the source object. Delete func(source T) error }
NodeConfig contains options to construct a NodeType.
type NodeType ¶
type NodeType[T any] struct { NodeTypeBase // contains filtered or unexported fields }
NodeType defines a Node subtype.
func NewNodeType ¶
func NewNodeType[T any](oc graphql.ObjectConfig, nc NodeConfig[T]) (nt *NodeType[T])
NewNodeType creates a NodeType.
type NodeTypeBase ¶
NodeTypeBase contains non-generic fields of NodeType.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package gqlsingleton provides singleton objects in GraphQL server.
|
Package gqlsingleton provides singleton objects in GraphQL server. |