Documentation ¶
Index ¶
- type Configurator
- type ErrExecutor
- type ExecutionContext
- type ExecutionMiddleware
- type Executor
- type ExecutorFunc
- type FieldURLMap
- type Gateway
- func (g *Gateway) Execute(requestContext context.Context, query string, variables map[string]interface{}) (map[string]interface{}, error)
- func (g *Gateway) GraphQLHandler(w http.ResponseWriter, r *http.Request)
- func (g *Gateway) PlaygroundHandler(w http.ResponseWriter, r *http.Request)
- func (g *Gateway) Query(ctx context.Context, input *graphql.QueryInput, receiver interface{}) error
- type Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) FormatSelectionSet(selection ast.SelectionSet) string
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) QueryPlanStep(step *QueryPlanStep)
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) WithFields(fields LoggerFields) *Logger
- type LoggerFields
- type Merger
- type MergerFunc
- type Middleware
- type MiddlewareList
- type MinQueriesPlanner
- type MockErrPlanner
- type MockPlanner
- type ParallelExecutor
- type Planner
- type PlanningContext
- type QueryField
- type QueryPOSTBody
- type QueryPlan
- type QueryPlanStep
- type QueryPlanner
- type RequestMiddleware
- type ResponseMiddleware
- type Set
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configurator ¶
type Configurator func(*Gateway)
Configurator is a function to be passed to New that configures the resulting schema
func WithExecutor ¶
func WithExecutor(e Executor) Configurator
WithExecutor returns a Configurator that sets the executor of the gateway
func WithMerger ¶
func WithMerger(m Merger) Configurator
WithMerger returns a Configurator that sets the merger of the gateway
func WithMiddlewares ¶ added in v0.0.5
func WithMiddlewares(middlewares ...Middleware) Configurator
WithMiddlewares returns a Configurator that adds middlewares to the gateway
func WithPlanner ¶
func WithPlanner(p QueryPlanner) Configurator
WithPlanner returns a Configurator that sets the planner of the gateway
func WithQueryFields ¶ added in v0.0.5
func WithQueryFields(fields ...*QueryField) Configurator
WithQueryFields returns a Configurator that adds the given query fields to the gateway
type ErrExecutor ¶
type ErrExecutor struct {
Error error
}
ErrExecutor always returnes the internal error.
func (*ErrExecutor) Execute ¶
func (e *ErrExecutor) Execute(ctx *ExecutionContext) (map[string]interface{}, error)
Execute returns the internet error
type ExecutionContext ¶ added in v0.0.3
type ExecutionContext struct { Plan *QueryPlan Variables map[string]interface{} RequestContext context.Context RequestMiddlewares []graphql.NetworkMiddleware }
ExecutionContext is a well-type alternative to context.Context and provides the context for a particular execution.
type ExecutionMiddleware ¶ added in v0.0.3
type ExecutionMiddleware interface {
ExecutionMiddleware()
}
ExecutionMiddleware are things that interject in the execution process
type Executor ¶
type Executor interface {
Execute(ctx *ExecutionContext) (map[string]interface{}, error)
}
Executor is responsible for executing a query plan against the remote schemas and returning the result
type ExecutorFunc ¶
type ExecutorFunc func(ctx *ExecutionContext) (map[string]interface{}, error)
ExecutorFunc wraps a function to be used as an executor.
func (ExecutorFunc) Execute ¶
func (e ExecutorFunc) Execute(ctx *ExecutionContext) (map[string]interface{}, error)
Execute invokes and returns the internal function
type FieldURLMap ¶
FieldURLMap holds the intformation for retrieving the valid locations one can find the value for the field
func (FieldURLMap) Concat ¶
func (m FieldURLMap) Concat(other FieldURLMap) FieldURLMap
Concat returns a new field map url whose entries are the union of both maps
func (FieldURLMap) RegisterURL ¶
func (m FieldURLMap) RegisterURL(parent string, field string, locations ...string)
RegisterURL adds a new location to the list of possible places to find the value for parent.field
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway is the top level entry for interacting with a gateway. It is responsible for merging a list of remote schemas into one, generating a query plan to execute based on an incoming request, and following that plan
func New ¶
func New(sources []*graphql.RemoteSchema, configs ...Configurator) (*Gateway, error)
New instantiates a new schema with the required stuffs.
func (*Gateway) Execute ¶
func (g *Gateway) Execute(requestContext context.Context, query string, variables map[string]interface{}) (map[string]interface{}, error)
Execute takes a query string, executes it, and returns the response
func (*Gateway) GraphQLHandler ¶
func (g *Gateway) GraphQLHandler(w http.ResponseWriter, r *http.Request)
GraphQLHandler returns a http.HandlerFunc that should be used as the primary endpoint for the gateway API. The endpoint will respond to queries on both GET and POST requests. POST requests can either be a single object with { query, variables, operationName } or a list of that object.
func (*Gateway) PlaygroundHandler ¶
func (g *Gateway) PlaygroundHandler(w http.ResponseWriter, r *http.Request)
PlaygroundHandler returns a http.HandlerFunc which on GET requests shows the user an interface that they can use to interact with the API. On POSTs the endpoint executes the designated query
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger handles the logging in the gateway library
func (*Logger) Debug ¶
func (l *Logger) Debug(args ...interface{})
Debug should be used for any logging that would be useful for debugging
func (*Logger) FormatSelectionSet ¶
func (l *Logger) FormatSelectionSet(selection ast.SelectionSet) string
FormatSelectionSet returns a pretty printed version of a selection set
func (*Logger) Info ¶
func (l *Logger) Info(args ...interface{})
Info should be used for any logging that doesn't necessarily need attention but is nice to see by default
func (*Logger) QueryPlanStep ¶
func (l *Logger) QueryPlanStep(step *QueryPlanStep)
QueryPlanStep formats and logs a query plan step for human consumption
func (*Logger) Warn ¶
func (l *Logger) Warn(args ...interface{})
Warn should be used for logging that needs attention
func (*Logger) WithFields ¶
func (l *Logger) WithFields(fields LoggerFields) *Logger
WithFields adds the provided fields to the Log
type LoggerFields ¶
type LoggerFields map[string]interface{}
LoggerFields is a wrapper over a map of key,value pairs to associate with the log
type Merger ¶
Merger is an interface for structs that are capable of taking a list of schemas and returning something that resembles a "merge" of those schemas.
type MergerFunc ¶
MergerFunc is a wrapper of a function of the same signature as Merger.Merge
type Middleware ¶
type Middleware interface {
Middleware()
}
Middleware are things that can modify a gateway normal execution
type MinQueriesPlanner ¶
type MinQueriesPlanner struct {
Planner
}
MinQueriesPlanner does the most basic level of query planning
func (*MinQueriesPlanner) Plan ¶
func (p *MinQueriesPlanner) Plan(ctx *PlanningContext) ([]*QueryPlan, error)
Plan computes the nested selections that will need to be performed
type MockErrPlanner ¶
type MockErrPlanner struct {
Err error
}
MockErrPlanner always returns the provided error. Useful in testing.
func (*MockErrPlanner) Plan ¶
func (p *MockErrPlanner) Plan(*PlanningContext) ([]*QueryPlan, error)
type MockPlanner ¶
type MockPlanner struct {
Plans []*QueryPlan
}
MockPlanner always returns the provided list of plans. Useful in testing.
func (*MockPlanner) Plan ¶
func (p *MockPlanner) Plan(*PlanningContext) ([]*QueryPlan, error)
type ParallelExecutor ¶
type ParallelExecutor struct{}
ParallelExecutor executes the given query plan by starting at the root of the plan and walking down the path stitching the results together
func (*ParallelExecutor) Execute ¶
func (executor *ParallelExecutor) Execute(ctx *ExecutionContext) (map[string]interface{}, error)
Execute returns the result of the query plan
type Planner ¶
Planner is meant to be embedded in other QueryPlanners to share configuration
func (*Planner) GetQueryer ¶
func (p *Planner) GetQueryer(ctx *PlanningContext, url string) graphql.Queryer
GetQueryer returns the queryer that should be used to resolve the plan
type PlanningContext ¶ added in v0.0.5
type PlanningContext struct { Query string Schema *ast.Schema Locations FieldURLMap Gateway *Gateway }
PlanningContext is the input struct to the Plan method
type QueryField ¶ added in v0.0.5
type QueryField struct { Name string Type *ast.Type Arguments ast.ArgumentDefinitionList Resolver func(context.Context, map[string]interface{}) (string, error) }
QueryField is a hook to add gateway-level fields to a gateway. Limited to only being able to resolve an id of an already existing type in order to keep business logic out of the gateway.
type QueryPOSTBody ¶
type QueryPOSTBody struct { Query string `json:"query"` Variables map[string]interface{} `json:"variables"` OperationName string `json:"operationName"` }
QueryPOSTBody is the incoming payload when sending POST requests to the gateway
type QueryPlan ¶
type QueryPlan struct { Operation *ast.OperationDefinition RootStep *QueryPlanStep FragmentDefinitions ast.FragmentDefinitionList FieldsToScrub map[string][][]string }
QueryPlan is the full plan to resolve a particular query
type QueryPlanStep ¶
type QueryPlanStep struct { // execution meta data InsertionPoint []string Then []*QueryPlanStep // required info to generate the query Queryer graphql.Queryer ParentType string ParentID string SelectionSet ast.SelectionSet // pre-generated query stuff QueryDocument *ast.QueryDocument QueryString string FragmentDefinitions ast.FragmentDefinitionList Variables Set }
QueryPlanStep represents a step in the plan required to fulfill a query.
type QueryPlanner ¶
type QueryPlanner interface {
Plan(*PlanningContext) ([]*QueryPlan, error)
}
QueryPlanner is responsible for taking a string with a graphql query and returns the steps to fulfill it
type RequestMiddleware ¶
type RequestMiddleware graphql.NetworkMiddleware
RequestMiddleware is a middleware that can modify outbound requests to services
func (RequestMiddleware) Middleware ¶
func (p RequestMiddleware) Middleware()
Middleware marks RequestMiddleware as a valid middleware
type ResponseMiddleware ¶ added in v0.0.3
type ResponseMiddleware func(ctx *ExecutionContext, response map[string]interface{}) error
ResponseMiddleware is a middleware that can modify the response before it is serialized and sent to the user
func (ResponseMiddleware) ExecutionMiddleware ¶ added in v0.0.3
func (p ResponseMiddleware) ExecutionMiddleware()
ExecutionMiddleware marks ResponseMiddleware as a valid execution middleware
func (ResponseMiddleware) Middleware ¶ added in v0.0.3
func (p ResponseMiddleware) Middleware()
Middleware marks ResponseMiddleware as a valid middleware