Documentation
¶
Overview ¶
The file is vendored from https://github.com/graphql-go/handler/blob/v0.2.4/handler.go
Notable changes: - Remove the type Config. You construct Handler directly. - Remove features that we do not use, such as pretty, graphiql, playground. - Remove ContentTypeFormURLEncoded, and its associated handling.
Index ¶
- Constants
- Variables
- func GetDateTimeInUTCFromInput(input map[string]interface{}, key string) *time.Time
- func HTTPDo(client *http.Client, r *http.Request, params DoParams) (result *graphql.Result, err error)
- func NewConnectionDef(schema *graphql.Object) *relay.GraphQLConnectionDefinitions
- func NewJSONObjectScalar(name string, description string) *graphql.Scalar
- func WithContext(ctx context.Context, gqlContext GraphQLContext) context.Context
- type APIErrorExtension
- func (a APIErrorExtension) ExecutionDidStart(ctx context.Context) (context.Context, graphql.ExecutionFinishFunc)
- func (a APIErrorExtension) GetResult(ctx context.Context) interface{}
- func (a APIErrorExtension) HasResult() bool
- func (a APIErrorExtension) Init(ctx context.Context, params *graphql.Params) context.Context
- func (a APIErrorExtension) Name() string
- func (a APIErrorExtension) ParseDidStart(ctx context.Context) (context.Context, graphql.ParseFinishFunc)
- func (a APIErrorExtension) ResolveFieldDidStart(ctx context.Context, info *graphql.ResolveInfo) (context.Context, graphql.ResolveFieldFinishFunc)
- func (a APIErrorExtension) ValidationDidStart(ctx context.Context) (context.Context, graphql.ValidationFinishFunc)
- type Connection
- type Cursor
- type DataLoader
- type DataLoaderInterface
- type DoParams
- type GraphQLContext
- type GraphiQL
- type Handler
- type Lazy
- type LazyItem
- type LoadFunc
- type PageArgs
- type PageResult
- type RequestOptions
- type ResultCallbackFn
Constants ¶
const ( ContentTypeJSON = "application/json" ContentTypeGraphQL = "application/graphql" )
const DEFAULT_MAX_PAGE_SIZE uint64 = 100
Variables ¶
var Date = graphql.NewScalar(graphql.ScalarConfig{ Name: "Date", Description: "The `Date` scalar type represents a Date." + " The Date is serialized in ISO 8601 format", Serialize: serializeDate, ParseValue: unserializeDate, ParseLiteral: func(valueAST ast.Value) interface{} { switch valueAST := valueAST.(type) { case *ast.StringValue: return unserializeDate(valueAST.Value) } return nil }, })
var ErrBodyMustBeNonNil = errors.New("http request body must be non-nil")
var ErrMethodMustBePost = errors.New("http method must be POST")
Functions ¶
func GetDateTimeInUTCFromInput ¶
GetDateTimeInUTCFromInput gets a *time.Time from input. It is expected that the graphql library accepts RFC3339 timestamp only. As of graphql v0.8.1, https://github.com/graphql-go/graphql/blob/v0.8.1/scalars.go#L557 The deserialization of DateTime delegates to time.Time.UnmarshalText, and the doc of UnmarshalText says it only accept RFC3339. That is, the input timestamp also has an explicit timezone. The job of this function is to ensure the returned time is always in UTC.
func HTTPDo ¶
func HTTPDo(client *http.Client, r *http.Request, params DoParams) (result *graphql.Result, err error)
HTTPDo is the HTTP version of graphql.Do.
func NewConnectionDef ¶
func NewConnectionDef(schema *graphql.Object) *relay.GraphQLConnectionDefinitions
func NewJSONObjectScalar ¶
func WithContext ¶
func WithContext(ctx context.Context, gqlContext GraphQLContext) context.Context
Types ¶
type APIErrorExtension ¶
type APIErrorExtension struct{}
func (APIErrorExtension) ExecutionDidStart ¶
func (a APIErrorExtension) ExecutionDidStart(ctx context.Context) (context.Context, graphql.ExecutionFinishFunc)
func (APIErrorExtension) GetResult ¶
func (a APIErrorExtension) GetResult(ctx context.Context) interface{}
func (APIErrorExtension) HasResult ¶
func (a APIErrorExtension) HasResult() bool
func (APIErrorExtension) Name ¶
func (a APIErrorExtension) Name() string
func (APIErrorExtension) ParseDidStart ¶
func (a APIErrorExtension) ParseDidStart(ctx context.Context) (context.Context, graphql.ParseFinishFunc)
func (APIErrorExtension) ResolveFieldDidStart ¶
func (a APIErrorExtension) ResolveFieldDidStart(ctx context.Context, info *graphql.ResolveInfo) (context.Context, graphql.ResolveFieldFinishFunc)
func (APIErrorExtension) ValidationDidStart ¶
func (a APIErrorExtension) ValidationDidStart(ctx context.Context) (context.Context, graphql.ValidationFinishFunc)
type Connection ¶
type Connection struct {
Edges []*relay.Edge `json:"edges"`
PageInfo relay.PageInfo `json:"pageInfo"`
TotalCount interface{} `json:"totalCount"`
}
func NewConnectionFromArray ¶
func NewConnectionFromArray(data []interface{}, args relay.ConnectionArguments) *Connection
func NewConnectionFromResult ¶
func NewConnectionFromResult(lazyItems []LazyItem, result *PageResult) (*Connection, error)
type DataLoader ¶
type DataLoader struct {
MaxBatch int
// contains filtered or unexported fields
}
func NewDataLoader ¶
func NewDataLoader(loadFn LoadFunc) *DataLoader
func (*DataLoader) Clear ¶
func (l *DataLoader) Clear(key interface{})
func (*DataLoader) ClearAll ¶
func (l *DataLoader) ClearAll()
func (*DataLoader) LoadMany ¶
func (l *DataLoader) LoadMany(ctx context.Context, keys []interface{}) *Lazy
func (*DataLoader) Prime ¶
func (l *DataLoader) Prime(key interface{}, value interface{})
type DataLoaderInterface ¶
type DoParams ¶
type DoParams struct {
OperationName string `json:"operationName,omitempty"`
Query string `json:"query"`
Variables map[string]interface{} `json:"variables"`
}
DoParams is the simplfied version of graphql.Params.
type GraphQLContext ¶
type GraphQLContext interface{}
func GQLContext ¶
func GQLContext(ctx context.Context) GraphQLContext
type Handler ¶
type Handler struct {
Schema *graphql.Schema
ResultCallbackFn ResultCallbackFn
}
func (*Handler) ContextHandler ¶
ContextHandler provides an entrypoint into executing graphQL queries with a user-provided context.
type Lazy ¶
type Lazy struct {
// contains filtered or unexported fields
}
func NewLazyError ¶
func NewLazyValue ¶
func NewLazyValue(value interface{}) *Lazy
type LoadFunc ¶
LoadFunc must satisfy the following conditions.
1. The length of the result must match that of keys. 2. If a given key resolves to nothing, nil must be returned instead. 3. The order of the result must match that of keys.
So it is the responsibility of LoadFunc to satisfy these conditions. The underlying implementation used by LoadFunc may not satisfy the conditions.
type PageArgs ¶
func NewPageArgs ¶
func NewPageArgs(args relay.ConnectionArguments) PageArgs
func NewPageArgsWithMaxPageSize ¶
func NewPageArgsWithMaxPageSize(args relay.ConnectionArguments, maxPageSize uint64) PageArgs
type PageResult ¶
func NewPageResult ¶
func NewPageResult(args PageArgs, itemsLen int, totalCount *Lazy) *PageResult
type RequestOptions ¶
type RequestOptions struct {
Query string `json:"query" url:"query" schema:"query"`
Variables map[string]interface{} `json:"variables" url:"variables" schema:"variables"`
OperationName string `json:"operationName" url:"operationName" schema:"operationName"`
}
func NewRequestOptions ¶
func NewRequestOptions(r *http.Request) (*RequestOptions, error)
RequestOptions Parses a http.Request into GraphQL request options struct