Documentation ¶
Index ¶
- Variables
- func ArgsConfig(i interface{}) graphql.FieldConfigArgument
- func JSONParseLiteral(valueAST ast.Value) interface{}
- func JSONParseValue(value interface{}) interface{}
- func JSONSerialize(value interface{}) interface{}
- func LoadArgs(p graphql.ResolveParams, c interface{}) error
- func LoadBool(i interface{}) (bool, error)
- func LoadBoolPointer(i interface{}) (*bool, error)
- func LoadFloat(i interface{}) (float64, error)
- func LoadInt(i interface{}) (int, error)
- func LoadNullInt(i interface{}) (null.Int, error)
- func LoadNullString(i interface{}) (null.String, error)
- func LoadRawJSON(i interface{}) (pqjson.RawMessage, error)
- func LoadString(i interface{}) (string, error)
- func LoadTime(i interface{}) (time.Time, error)
- func LoadUInt(i interface{}) (uint, error)
- func OutputType(name, desc string, val interface{}) graphql.Output
- func RegisterArgParser(f interface{}, gqlType graphql.Output) error
- func RegisterKnownType(val interface{}, gqlType graphql.Output)
- func SafeArgsConfig(i interface{}) (graphql.FieldConfigArgument, error)
- func Union(name, desc string, vals ...interface{}) *graphql.Union
- type ArgLoader
- func (e *ArgLoader) ArgsConfig(i interface{}) graphql.FieldConfigArgument
- func (e *ArgLoader) LoadArgs(p graphql.ResolveParams, c interface{}) error
- func (e *ArgLoader) RegisterArgParser(f interface{}, gqlType graphql.Output) error
- func (e *ArgLoader) SafeArgsConfig(i interface{}) (graphql.FieldConfigArgument, error)
- type TypeBuilder
Constants ¶
This section is empty.
Variables ¶
var BaseLoaders = []struct { LoaderFunc interface{} GqlType graphql.Output }{ {LoaderFunc: LoadBool, GqlType: graphql.Boolean}, {LoaderFunc: LoadBoolPointer, GqlType: graphql.Boolean}, {LoaderFunc: LoadString, GqlType: graphql.String}, {LoaderFunc: LoadInt, GqlType: graphql.Int}, {LoaderFunc: LoadFloat, GqlType: graphql.Float}, {LoaderFunc: LoadTime, GqlType: Timestamp}, }
BaseLoaders are for the 4 scalar types built into GraphQL.
var DefaultLoaders = []struct { LoaderFunc interface{} GqlType graphql.Output }{ {LoaderFunc: LoadRawJSON, GqlType: JSON}, {LoaderFunc: LoadUInt, GqlType: graphql.Int}, }
DefaultLoaders are for extra types beyond the 4 scalar types built into GraphQL.
var JSON = graphql.NewScalar( graphql.ScalarConfig{ Name: "JSON", Description: "JSON is a custom scalar for attaching json blobs as leaves on a graphql API request or response.", Serialize: JSONSerialize, ParseValue: JSONParseValue, ParseLiteral: JSONParseLiteral, })
JSON is a custom scalar type for using custom json blobs as leaves on our responses.
var Timestamp = graphql.NewScalar(graphql.ScalarConfig{
Name: "Timestamp",
Description: "Timestamp is an ISO8601-formatted date/time string. Values that omit a time zone are assumed to be UTC.",
Serialize: timeSerialize,
ParseValue: timeParseValue,
ParseLiteral: timeParseLiteral,
})
Timestamp is our custom scalar for handling datetimes.
Functions ¶
func ArgsConfig ¶
func ArgsConfig(i interface{}) graphql.FieldConfigArgument
ArgsConfig takes a struct instance with appropriate struct tags on its fields and returns a map of argument names to graphql argument configs, for assigning to the Args field in a graphql.Field. If there is an error generating the argument configs, this function will panic. It uses the default arg loader.
func JSONParseLiteral ¶
JSONParseLiteral converts fragments of a graphql AST into a json Raw Message. It's used for parsing input objects for our custom scalar JSON type. The assumption is that the graphql query object is close enough to json that we can convert it.
func JSONParseValue ¶
func JSONParseValue(value interface{}) interface{}
JSONParseValue implements the ParseValue so that JSON can satisfy the graphql.Scalar interface. This method gets called when parsing JSON type obejcts out of query variables This is also called when doing the query: variables: pattern. Assume that this can be Marshalled like below
func JSONSerialize ¶
func JSONSerialize(value interface{}) interface{}
JSONSerialize serializes objects into the custom JSON blob graphql scalar type.
func LoadArgs ¶
func LoadArgs(p graphql.ResolveParams, c interface{}) error
LoadArgs loads arguments from the ResolveParam's map into the provided struct. It uses the default arg loader.
func LoadBoolPointer ¶
LoadBoolPointer loads `*bool` from graphql arg
func LoadNullInt ¶
LoadNullInt loads `null.Int` from graphql arg
func LoadNullString ¶
LoadNullString will attempt to load a `null.String` from graphql arg
func LoadRawJSON ¶
func LoadRawJSON(i interface{}) (pqjson.RawMessage, error)
LoadRawJSON loads `pqjson.RawMessage` from graphql arg
func LoadString ¶
LoadString loads `string` from graphql arg
func OutputType ¶
OutputType builds a GraphQL type for you from the given name, desc, and val. val may be a struct instance, slice, array, pointer, or an alias to a builtin type like int or string.
func RegisterArgParser ¶
RegisterArgParser takes a func (string) (<anytype>, error) and registers it on the ArgLoader as the parser for <anytype>. It uses the default arg loader.
func RegisterKnownType ¶
RegisterKnownType takes any value, and the GraphQL type that should represent it, and will use that when building types.
func SafeArgsConfig ¶
func SafeArgsConfig(i interface{}) (graphql.FieldConfigArgument, error)
SafeArgsConfig -- this takes a struct instance w/ tags and returns a map of argument names. This will not cause a panic upon error. It uses the default arg loader.
Types ¶
type ArgLoader ¶
type ArgLoader struct {
// contains filtered or unexported fields
}
ArgLoader is a helper for reading arguments from a graphql.ResolveParams, converting them to Go types, and setting their values to fields on a user-provided struct.
func (*ArgLoader) ArgsConfig ¶
func (e *ArgLoader) ArgsConfig(i interface{}) graphql.FieldConfigArgument
ArgsConfig takes a struct instance with appropriate struct tags on its fields and returns a map of argument names to graphql argument configs, for assigning to the Args field in a graphql.Field. If there is an error generating the argument configs, this function will panic.
func (*ArgLoader) LoadArgs ¶
func (e *ArgLoader) LoadArgs(p graphql.ResolveParams, c interface{}) error
LoadArgs loads arguments from the provided map into the provided struct.
func (*ArgLoader) RegisterArgParser ¶
RegisterArgParser takes a func (string) (<anytype>, error) and registers it on the ArgLoader as the parser for <anytype>
func (*ArgLoader) SafeArgsConfig ¶
func (e *ArgLoader) SafeArgsConfig(i interface{}) (graphql.FieldConfigArgument, error)
SafeArgsConfig -- this takes a struct instance w/ tags and returns a map of argument names. This will not cause a panic upon error
type TypeBuilder ¶
type TypeBuilder struct {
// contains filtered or unexported fields
}
A TypeBuilder helps create graphql-go output types
func NewTypeBuilder ¶
func NewTypeBuilder() *TypeBuilder
NewTypeBuilder creates a new TypeBuilder and registers known types on it.
func (*TypeBuilder) OutputType ¶
func (tb *TypeBuilder) OutputType(name, desc string, val interface{}) graphql.Output
OutputType builds a GraphQL type for you from the given name, desc, and val. val may be a struct instance, slice, array, pointer, or an alias to a builtin type like int or string.
func (*TypeBuilder) RegisterKnownType ¶
func (tb *TypeBuilder) RegisterKnownType(val interface{}, gqlType graphql.Output)
RegisterKnownType takes any value, and the GraphQL type that should represent it, and will use that when building types.