api

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2020 License: Unlicense Imports: 7 Imported by: 0

Documentation

Overview

Generates a GraphQL API handler for your convenience

Index

Constants

View Source
const MainContextKey = "mainContext"

MainContextKey is used to provide a structured context object to all GraphQL resolvers

Variables

This section is empty.

Functions

func GenerateGraphQLAPIHandler

func GenerateGraphQLAPIHandler(schema *graphql.Schema, config *HandlerConfig, contextObj interface{}) http.HandlerFunc

GenerateGraphQLAPIHandler generates a HTTP handler func that prepares and processes requests to the GraphQL API in an automated fashion

Types

type HTTPHandlerFuncWithError

type HTTPHandlerFuncWithError func(w http.ResponseWriter, r *http.Request) error

HTTPHandlerFuncWithError is the type used for middlewares

type HandlerConfig

type HandlerConfig struct {
	// Runs before any processing is done for requests
	OnRequest HTTPHandlerFuncWithError
	// Runs before processing the GraphQL query but after
	// doing some initial processing
	PreProcess HTTPHandlerFuncWithError
	// Runs right after the GraphQL query has been processed
	// and before the result is checked for errors
	PostProcess HTTPHandlerFuncWithError
	// Runs after checking for errors in the GraphQL query result
	// and before writing the result to the client. Only runs if
	// no errors were encountered.
	PreWriteResult HTTPHandlerFuncWithError
	// Runs after writing the result to the client. This is the last
	// of all handlers that is run.
	PostWriteResult HTTPHandlerFuncWithError

	// Specifying `true` will disallow using the URL query parameter
	// as a means of transporting the GraphQL query
	DisableURLQuery bool
	// Specifying `true` will disallow using the POST body
	// as a means of transporting the GraphQL query
	DisableBodyQuery bool
}

HandlerConfig allows you to attach middlewares and configure the behavior as you like

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL