Documentation ¶
Overview ¶
Package handler implements an HTTP handler to process GraphQL queries (and mutations/subscriptions) given an instance of a query struct (and optionally mutation and subscription structs) and a corresponding GraphQL schema. The schema is typically generated (by the schema package) from the same struct(s).
Index ¶
- Constants
- Variables
- func FixNumberVariables(m map[string]interface{})
- func InitialTimeout(timeout time.Duration) func(h *Handler)
- func New(schemaStrings []string, enums map[string][]string, qms [3][]interface{}, ...) http.Handler
- func NewIntrospectionData(astSchema *ast.Schema) interface{}
- func PingFrequency(freq time.Duration) func(h *Handler)
- func PongTimeout(timeout time.Duration) func(h *Handler)
- type Handler
Constants ¶
const ( AllowIntrospection = true AllowConcurrentQueries = true ALlowNilResolverFunction = true // return NULL for an unimplemented (nil) resolver function TypeNameQuery = "__typename" // Name of "introspection" query that can be performed at any level )
Variables ¶
var IntroEnums = map[string][]string{
"__TypeKind": {"SCALAR", "OBJECT", "INTERFACE", "UNION", "ENUM", "INPUT_OBJECT", "LIST", "NON_NULL"},
"__DirectiveLocation": {
"QUERY", "MUTATION", "SUBSCRIPTION", "FIELD", "FRAGMENT_DEFINITION", "FRAGMENT_SPREAD", "INLINE_FRAGMENT",
"SCHEMA",
"SCALAR", "OBJECT", "FIELD_DEFINITION", "ARGUMENT_DEFINITION", "INTERFACE", "UNION", "ENUM", "ENUM_VALUE",
"INPUT_OBJECT", "INPUT_FIELD_DEFINITION",
},
}
IntroEnums stores the name and values (text) of the __TypeKind and __DirectiveLocation enums
var IntroEnumsReverse = map[string]map[string]int{
"__TypeKind": {
"SCALAR": 0,
"OBJECT": 1,
"INTERFACE": 2,
"UNION": 3,
"ENUM": 4,
"INPUT_OBJECT": 5,
"LIST": 6,
"NON_NULL": 7,
},
"__DirectiveLocation": {
"QUERY": 0,
"MUTATION": 1,
"SUBSCRIPTION": 2,
"FIELD": 3,
"FRAGMENT_DEFINITION": 4,
"FRAGMENT_SPREAD": 5,
"INLINE_FRAGMENT": 6,
"SCHEMA": 7,
"SCALAR": 8,
"OBJECT": 9,
"FIELD_DEFINITION": 10,
"ARGUMENT_DEFINITION": 11,
"INTERFACE": 12,
"UNION": 13,
"ENUM": 14,
"ENUM_VALUE": 15,
"INPUT_OBJECT": 16,
"INPUT_FIELD_DEFINITION": 17,
},
}
IntroEnumsReverse stores the same enums as IntroEnum, as maps for reverse lookup of int values Each enum is a map keyed by the enum value (string) giving the underlying (int) value
Functions ¶
func FixNumberVariables ¶
func FixNumberVariables(m map[string]interface{})
FixNumberVariables goes through the structure created by the JSON decoder, converting any json.Number values to either an int64 or a float64. This assumes that all the JSON numbers were decoded into a json.Number type, rather than int/float, by use of the json.Decode.UseNumber() method.
func InitialTimeout ¶
InitialTimeout set the length time to wait from when the websocket is opened until the "connection_init" message is received. If the message is not received from the client within the time limit then an error message is returned to the client and the WS is closed.
func New ¶
func New(schemaStrings []string, enums map[string][]string, qms [3][]interface{}, options ...func(*Handler), ) http.Handler
New creates a new handler with the given schema(s) and query/mutation/subscription struct(s) Parameters:
schemaStrings - a slice of strings containing the GraphQL schemas (typically only 1) enums - a map of enum names to a slice of strings containing the enum values for all the schemas qms - a slice of query/mutation/subscription structs where: qms[0] - query struct(s) qms[1] - mutation struct(s) qms[2] - subscription struct(s) options - zero or more options returned by calls to: handler.InitialTimeout handler.PingFrequency handler.PongTimeout
func NewIntrospectionData ¶
func PingFrequency ¶
PingFrequency says how often to send a "ping" message (if the client connects with new protocol) or a "ka" (keep alive) message (old protocol)
func PongTimeout ¶
PongTimeout set the length time to wait for a "pong" message from the client after a "ping" message is sent. If the message is not received from the client within the time limit then an error message is returned to the client and the WS is closed.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler stores the invariants (schema and structs) used in the GraphQL requests
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServerHTTP receives a GraphQL query as an HTTP request, executes the query (or mutation) and generates an HTTP response or error message