Documentation ¶
Index ¶
- Variables
- type Connection
- type ConnectionArgs
- type Edge
- type EnumMapping
- type FieldFuncOption
- func BatchFilterField(name string, batchFilter interface{}, options ...FieldFuncOption) FieldFuncOption
- func BatchFilterFieldWithFallback(name string, batchFilter interface{}, filter interface{}, ...) FieldFuncOption
- func BatchSortField(name string, batchSort interface{}, options ...FieldFuncOption) FieldFuncOption
- func BatchSortFieldWithFallback(name string, batchSort interface{}, sort interface{}, ...) FieldFuncOption
- func FilterField(name string, filter interface{}, options ...FieldFuncOption) FieldFuncOption
- func SortField(name string, sort interface{}, options ...FieldFuncOption) FieldFuncOption
- type Methods
- type NumParallelInvocationsFunc
- type Object
- func (s *Object) BatchFieldFunc(name string, batchFunc interface{}, options ...FieldFuncOption)
- func (s *Object) BatchFieldFuncWithFallback(name string, batchFunc interface{}, fallbackFunc interface{}, ...)
- func (s *Object) FieldFunc(name string, f interface{}, options ...FieldFuncOption)
- func (s *Object) Key(f string)
- func (s *Object) ManualPaginationWithFallback(name string, manualPaginatedFunc interface{}, fallbackFunc interface{}, ...)
- func (o *Object) PaginateFieldFunc(name string, f interface{})deprecated
- type ObjectOption
- type PageInfo
- type PaginationArgs
- type PaginationInfo
- type PostProcessOptions
- type SafeBatchNodesToKeep
- type Schema
- func (s *Schema) Build() (*graphql.Schema, error)
- func (s *Schema) Enum(val interface{}, enumMap interface{})
- func (s *Schema) MustBuild() *graphql.Schema
- func (s *Schema) Mutation() *Object
- func (s *Schema) Object(name string, typ interface{}, options ...ObjectOption) *Object
- func (s *Schema) Query() *Object
- type SortOrder
- type Union
- type UseFallbackFlag
Constants ¶
This section is empty.
Variables ¶
var Expensive fieldFuncOptionFunc = func(m *method) { m.Expensive = true }
Expensive is an option that can be passed to a FieldFunc to indicate that the function is expensive to execute, so it should be parallelized.
var NonNullable fieldFuncOptionFunc = func(m *method) { m.MarkedNonNullable = true }
NonNullable is an option that can be passed to a FieldFunc to indicate that its return value is required, even if the return value is a pointer type.
var Paginated fieldFuncOptionFunc = func(m *method) { m.Paginated = true }
Paginated is an option that can be passed to a FieldFunc to indicate that its return value should be paginated.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
Connection conforms to the GraphQL Connection type in the Relay Pagination spec.
type ConnectionArgs ¶
type ConnectionArgs struct { // first: n First *int64 // last: n Last *int64 // after: cursor After *string // before: cursor Before *string // User-facing args. Args interface{} // filterText: "text search" FilterText *string // FilterTextFields: ["filter name"] FilterTextFields *[]string // sortBy: "fieldName" SortBy *string // sortOrder: "asc" | "desc" SortOrder *SortOrder }
ConnectionArgs conform to the pagination arguments as specified by the Relay Spec for Connection types. https://facebook.github.io/relay/graphql/connections.htm#sec-Arguments
type Edge ¶
type Edge struct { Node interface{} Cursor string }
Edge consists of a node paired with its b64 encoded cursor.
type EnumMapping ¶
EnumMapping is a representation of an enum that includes both the mapping and reverse mapping.
type FieldFuncOption ¶
type FieldFuncOption interface {
// contains filtered or unexported methods
}
FieldFuncOption is an interface for the variadic options that can be passed to a FieldFunc for configuring options on that function.
func BatchFilterField ¶ added in v0.5.1
func BatchFilterField(name string, batchFilter interface{}, options ...FieldFuncOption) FieldFuncOption
func BatchFilterFieldWithFallback ¶ added in v0.5.1
func BatchFilterFieldWithFallback(name string, batchFilter interface{}, filter interface{}, flag func(context.Context) bool, options ...FieldFuncOption) FieldFuncOption
func BatchSortField ¶ added in v0.5.1
func BatchSortField(name string, batchSort interface{}, options ...FieldFuncOption) FieldFuncOption
func BatchSortFieldWithFallback ¶ added in v0.5.1
func BatchSortFieldWithFallback(name string, batchSort interface{}, sort interface{}, flag func(context.Context) bool, options ...FieldFuncOption) FieldFuncOption
func FilterField ¶ added in v0.5.1
func FilterField(name string, filter interface{}, options ...FieldFuncOption) FieldFuncOption
func SortField ¶ added in v0.5.1
func SortField(name string, sort interface{}, options ...FieldFuncOption) FieldFuncOption
type Methods ¶
type Methods map[string]*method
A Methods map represents the set of methods exposed on a Object.
type NumParallelInvocationsFunc ¶ added in v0.5.1
NumParallelInvocationsFunc is a configuration option for non-expensive and batch fields that controls how many goroutines will get created for the field execution. The nodes for the field execution will be evenly split across the different goroutines.
type Object ¶
type Object struct { Name string // Optional, defaults to Type's name. Description string Type interface{} Methods Methods // Deprecated, use FieldFunc instead. ServiceName string // contains filtered or unexported fields }
A Object represents a Go type and set of methods to be converted into an Object in a GraphQL schema.
func (*Object) BatchFieldFunc ¶ added in v0.5.1
func (s *Object) BatchFieldFunc(name string, batchFunc interface{}, options ...FieldFuncOption)
func (*Object) BatchFieldFuncWithFallback ¶ added in v0.5.1
func (s *Object) BatchFieldFuncWithFallback(name string, batchFunc interface{}, fallbackFunc interface{}, flag UseFallbackFlag, options ...FieldFuncOption)
func (*Object) FieldFunc ¶
func (s *Object) FieldFunc(name string, f interface{}, options ...FieldFuncOption)
FieldFunc exposes a field on an object. The function f can take a number of optional arguments: func([ctx context.Context], [o *Type], [args struct {}]) ([Result], [error])
For example, for an object of type User, a fullName field might take just an instance of the object:
user.FieldFunc("fullName", func(u *User) string { return u.FirstName + " " + u.LastName })
An addUser mutation field might take both a context and arguments:
mutation.FieldFunc("addUser", func(ctx context.Context, args struct{ FirstName string LastName string }) (int, error) { userID, err := db.AddUser(ctx, args.FirstName, args.LastName) return userID, err })
func (*Object) Key ¶
Key registers the key field on an object. The field should be specified by the name of the graphql field. For example, for an object User:
type struct User { UserKey int64 }
The key will be registered as: object.Key("userKey")
func (*Object) ManualPaginationWithFallback ¶ added in v0.5.1
func (s *Object) ManualPaginationWithFallback(name string, manualPaginatedFunc interface{}, fallbackFunc interface{}, flag UseFallbackFlag, options ...FieldFuncOption)
func (*Object) PaginateFieldFunc
deprecated
PaginateFieldFunc registers a function that is also paginated according to the Relay Connection Spec. The field is registered as a Connection Type and first, last, before and after are automatically added as arguments to the function. The return type to the function must be a list. The element of the list is wrapped as a Node Type. If the resolver needs to use the pagination arguments, then the PaginationArgs struct must be embedded in the args struct passed in the resolver function, and the PaginationInfo struct needs to be returned in the resolver func.
Deprecated: Use FieldFunc(name, func, Paginated) instead.
type ObjectOption ¶ added in v0.5.1
type ObjectOption interface {
// contains filtered or unexported methods
}
OpjectOption is an interface for the variadic options that can be passed to a Object for configuring options on that object.
func FetchObjectFromKeys ¶ added in v0.5.1
func FetchObjectFromKeys(f interface{}, options ...ObjectOption) ObjectOption
func SkipAutoFields ¶ added in v0.5.2
func SkipAutoFields(skip bool) ObjectOption
type PageInfo ¶
type PageInfo struct { HasNextPage bool EndCursor string HasPrevPage bool StartCursor string Pages []string }
PageInfo contains information for pagination on a connection type. The list of Pages is used for page-number based pagination where the ith index corresponds to the start cursor of (i+1)st page.
type PaginationArgs ¶
type PaginationArgs struct { First *int64 Last *int64 After *string Before *string FilterText *string FilterTextFields *[]string SortBy *string SortOrder *SortOrder }
PaginationArgs are used in externally set connections by embedding them in an args struct. They are mapped onto ConnectionArgs, which follows the Relay spec for connection types.
type PaginationInfo ¶
type PaginationInfo struct { TotalCountFunc func() int64 HasNextPage bool HasPrevPage bool Pages []string }
PaginationInfo can be returned in a PaginateFieldFunc. The TotalCount function returns the totalCount field on the connection Type. If the resolver makes a SQL Query, then HasNextPage and HasPrevPage can be resolved in an efficient manner by requesting first/last:n + 1 items in the query. Then the flags can be filled in by checking the result size.
func (PaginationInfo) TotalCount ¶
func (i PaginationInfo) TotalCount() (int64, error)
type PostProcessOptions ¶ added in v0.5.1
type PostProcessOptions struct { // Whether or not Thunder should apply filtering on the output. This flag can // be used by externally managed resolvers when they decide to fall back to Thunder's // filtering based on the query arguments. ApplyTextFilter bool // Whether or not Thunder should set the Page Info's fields based on the output. // An exception to this are start and end cursors, which will be set by Thunder // regardless of the SetPageInfo flag. SetPageInfo bool }
PostProcessOptions is used to instruct Thunder to perform additional operations on the output in the case of manually paginated resolvers. This struct should be returned as the second result from a manually-paginated field func.
type SafeBatchNodesToKeep ¶ added in v0.5.1
type SafeBatchNodesToKeep struct {
// contains filtered or unexported fields
}
type Schema ¶
type Schema struct { Name string // contains filtered or unexported fields }
Schema is a struct that can be used to build out a GraphQL schema. Functions can be registered against the "Mutation" and "Query" objects in order to build out a full GraphQL schema.
func NewSchemaWithName ¶ added in v0.5.1
NewSchema creates a new schema with a schema name
func (*Schema) Build ¶
Build takes the schema we have built on our Query and Mutation starting points and builds a full graphql.Schema we can use to execute and run queries. Essentially we read through all the methods we've attached to our Query and Mutation Objects and ensure that those functions are returning other Objects that we can resolve in our GraphQL graph.
func (*Schema) Enum ¶
func (s *Schema) Enum(val interface{}, enumMap interface{})
Enum registers an enumType in the schema. The val should be any arbitrary value of the enumType to be used for reflection, and the enumMap should be the corresponding map of the enums.
For example a enum could be declared as follows:
type enumType int32 const ( one enumType = 1 two enumType = 2 three enumType = 3 )
Then the Enum can be registered as:
s.Enum(enumType(1), map[string]interface{}{ "one": enumType(1), "two": enumType(2), "three": enumType(3), })
func (*Schema) Mutation ¶
Mutation returns an Object struct that we can use to register all the top level graphql mutations functions we'd like to expose.
func (*Schema) Object ¶
func (s *Schema) Object(name string, typ interface{}, options ...ObjectOption) *Object
Object registers a struct as a GraphQL Object in our Schema. (https://facebook.github.io/graphql/June2018/#sec-Objects) We'll read the fields of the struct to determine it's basic "Fields" and we'll return an Object struct that we can use to register custom relationships and fields on the object.
type Union ¶
type Union struct{}
Union is a special marker struct that can be embedded into to denote that a type should be treated as a union type by the schemabuilder.
For example, to denote that a return value that may be a *Asset or *Vehicle might look like:
type GatewayUnion struct { schemabuilder.Union *Asset *Vehicle }
Fields returning a union type should expect to return this type as a one-hot struct, i.e. only Asset or Vehicle should be specified, but not both.