api

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: Unlicense Imports: 8 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) http.HandlerFunc

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

Types

type GraphQLContextWrapper added in v0.8.2

type GraphQLContextWrapper struct {
	HandlerConfig  *HandlerConfig
	Channel        chan interface{}
	AdditionalData []interface{}
	IsGraphiQL     bool
}

func GraphiQLContextWrapper added in v0.9.16

func GraphiQLContextWrapper() *GraphQLContextWrapper

type GraphQLMutationResolverInterceptorFunc added in v0.8.2

type GraphQLMutationResolverInterceptorFunc func(
	p graphql.ResolveParams, ctx *GraphQLContextWrapper, args interface{}, model interface{}) error

type GraphQLQueryResolverInterceptorFunc added in v0.8.2

type GraphQLQueryResolverInterceptorFunc func(
	p graphql.ResolveParams, ctx *GraphQLContextWrapper, result interface{}) error

type HTTPHandlerFuncWithError

type HTTPHandlerFuncWithError func(w http.ResponseWriter, r *http.Request, config *HandlerConfig, wrapper *GraphQLContextWrapper) 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
	// Runs before returning the response object from the GraphQL
	// query resolver so that you can intercept those objects
	OnQueryResult GraphQLQueryResolverInterceptorFunc
	// Runs before beginning a database transaction for mutations
	// in the GraphQL mutation resolver so that you can intercept
	// mutations before they are persisted
	BeforeMutate GraphQLMutationResolverInterceptorFunc

	// 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

	// A context of your choice - this can contain anything.
	// This is different from the GraphQL context.
	Context interface{}

	// This context is passed down to all GraphQL resolvers inside
	// a predefined struct
	GraphQLContext interface{}

	// In case Plug-n-Play was used, this is a PluggedConfig.
	// Otherwise you can supply anything you want here.
	ExtraConfig interface{}
}

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