Documentation ¶
Index ¶
- Constants
- Variables
- func AddField(ctx context.Context, name string, value interface{})
- func AddFields(ctx context.Context, fields EventFields)
- func AddOutgoingRequestsHeaderToContext(ctx context.Context, key, value string) context.Context
- func AddPermissionsToContext(ctx context.Context, perms OperationPermissions) context.Context
- func GenerateUserAgent(operation string) string
- func GetOutgoingRequestHeadersFromContext(ctx context.Context) http.Header
- func Main()
- func MergeSchemas(schemas ...*ast.Schema) (*ast.Schema, error)
- func NewMetricsHandler() http.Handler
- func RegisterMetrics()
- func RegisterPlugin(p Plugin)
- func RegisteredPlugins() map[string]Plugin
- func ValidateSchema(schema *ast.Schema) error
- type AllowedFields
- type BasePlugin
- func (p *BasePlugin) ApplyMiddlewarePrivateMux(h http.Handler) http.Handler
- func (p *BasePlugin) ApplyMiddlewarePublicMux(h http.Handler) http.Handler
- func (p *BasePlugin) Configure(*Config, json.RawMessage) error
- func (p *BasePlugin) GraphqlQueryPath() (bool, string)
- func (p *BasePlugin) Init(s *ExecutableSchema)
- func (p *BasePlugin) InterceptRequest(ctx context.Context, operationName, rawQuery string, ...)
- func (p *BasePlugin) InterceptResponse(ctx context.Context, operationName, rawQuery string, ...) *graphql.Response
- func (p *BasePlugin) SetupPrivateMux(mux *http.ServeMux)
- func (p *BasePlugin) SetupPublicMux(mux *http.ServeMux)
- func (p *BasePlugin) WrapGraphQLClientTransport(transport http.RoundTripper) http.RoundTripper
- type BoundaryField
- type BoundaryFieldsMap
- type ClientOpt
- type Config
- func (c *Config) ConfigurePlugins() []Plugin
- func (c *Config) GatewayAddress() string
- func (c *Config) Init() error
- func (c *Config) Load() error
- func (c *Config) MetricAddress() string
- func (c *Config) PrivateAddress() string
- func (c *Config) PrivateHttpAddress(path string) string
- func (c *Config) Watch()
- type DebugInfo
- type EventFields
- type ExecutableSchema
- func (s *ExecutableSchema) Complexity(typeName, fieldName string, childComplexity int, args map[string]interface{}) (int, bool)
- func (s *ExecutableSchema) Exec(ctx context.Context) graphql.ResponseHandler
- func (s *ExecutableSchema) ExecuteQuery(ctx context.Context) *graphql.Response
- func (s *ExecutableSchema) Schema() *ast.Schema
- func (s *ExecutableSchema) UpdateSchema(forceRebuild bool) error
- func (s *ExecutableSchema) UpdateServiceList(services []string) error
- type FieldURLMap
- type Gateway
- type GraphQLClient
- type GraphqlError
- type GraphqlErrors
- type OperationPermissions
- type PlanningContext
- type Plugin
- type PluginConfig
- type QueryPlan
- type QueryPlanStep
- type Request
- type Response
- type Service
- type TimeoutConfig
Constants ¶
const DebugKey contextKey = "debug"
DebugKey is used to request debug info from the context
Variables ¶
var ( IdFieldName = "id" IdsFieldName = "ids" )
var Version = "dev"
Functions ¶
func AddFields ¶
func AddFields(ctx context.Context, fields EventFields)
AddFields adds the given fields to the event contained in the context (if any)
func AddOutgoingRequestsHeaderToContext ¶
AddOutgoingRequestsHeaderToContext adds a header to all outgoings requests for the current query
func AddPermissionsToContext ¶
func AddPermissionsToContext(ctx context.Context, perms OperationPermissions) context.Context
AddPermissionsToContext adds permissions to the request context. If permissions are set the execution will check them against the query.
func GenerateUserAgent ¶
func GetOutgoingRequestHeadersFromContext ¶
GetOutgoingRequestHeadersFromContext get the headers that should be added to outgoing requests
func Main ¶
func Main()
Main runs the gateway. This function is exported so that it can be reused when building Bramble with custom plugins.
func MergeSchemas ¶
MergeSchemas merges the provided schemas together
func NewMetricsHandler ¶
NewMetricsHandler returns a new Prometheus metrics handler.
func RegisterPlugin ¶
func RegisterPlugin(p Plugin)
RegisterPlugin register a plugin so that it can be enabled via the configuration.
func RegisteredPlugins ¶
RegisteredPlugins returned the list of registered plugins.
func ValidateSchema ¶
ValidateSchema validates that the schema respects the Bramble specs
Types ¶
type AllowedFields ¶
type AllowedFields struct { AllowAll bool AllowedSubfields map[string]AllowedFields }
AllowedFields is a recursive set of allowed fields.
func MergeAllowedFields ¶
func MergeAllowedFields(allowedFields ...AllowedFields) AllowedFields
MergeAllowedFields merges the given AllowedFields. The result is the union of all the allowed fields.
func (AllowedFields) IsAllowed ¶
func (a AllowedFields) IsAllowed(fieldName string) (bool, AllowedFields)
IsAllowed returns whether the sub field is allowed along with the permissions for its own subfields
func (AllowedFields) MarshalJSON ¶
func (a AllowedFields) MarshalJSON() ([]byte, error)
MarshalJSON marshals to a JSON representation.
func (*AllowedFields) UnmarshalJSON ¶
func (a *AllowedFields) UnmarshalJSON(input []byte) error
UnmarshalJSON unmarshals from a JSON representation.
type BasePlugin ¶
type BasePlugin struct{}
BasePlugin is an empty plugin. It can be embedded by any plugin as a way to avoid declaring unnecessary methods.
func (*BasePlugin) ApplyMiddlewarePrivateMux ¶
func (p *BasePlugin) ApplyMiddlewarePrivateMux(h http.Handler) http.Handler
ApplyMiddlewarePrivateMux ...
func (*BasePlugin) ApplyMiddlewarePublicMux ¶
func (p *BasePlugin) ApplyMiddlewarePublicMux(h http.Handler) http.Handler
ApplyMiddlewarePublicMux ...
func (*BasePlugin) Configure ¶
func (p *BasePlugin) Configure(*Config, json.RawMessage) error
Configure ...
func (*BasePlugin) GraphqlQueryPath ¶
func (p *BasePlugin) GraphqlQueryPath() (bool, string)
GraphqlQueryPath ...
func (*BasePlugin) InterceptRequest ¶
func (p *BasePlugin) InterceptRequest(ctx context.Context, operationName, rawQuery string, variables map[string]interface{})
InterceptRequest is called before bramble starts executing a request. It can be used to inspect the unmarshalled GraphQL request bramble receives.
func (*BasePlugin) InterceptResponse ¶
func (p *BasePlugin) InterceptResponse(ctx context.Context, operationName, rawQuery string, variables map[string]interface{}, response *graphql.Response) *graphql.Response
InterceptResponse is called after bramble has finished executing a request. It can be used to inspect and/or modify the response bramble will return.
func (*BasePlugin) SetupPrivateMux ¶
func (p *BasePlugin) SetupPrivateMux(mux *http.ServeMux)
SetupPrivateMux ...
func (*BasePlugin) SetupPublicMux ¶
func (p *BasePlugin) SetupPublicMux(mux *http.ServeMux)
SetupPublicMux ...
func (*BasePlugin) WrapGraphQLClientTransport ¶
func (p *BasePlugin) WrapGraphQLClientTransport(transport http.RoundTripper) http.RoundTripper
WrapGraphQLClientTransport wraps the http.RoundTripper used for GraphQL requests.
type BoundaryField ¶
type BoundaryField struct { Field string // Name of the received id argument Argument string // Whether the query is in the array format Array bool }
BoundaryField contains the name and format for a boundary query
type BoundaryFieldsMap ¶
type BoundaryFieldsMap map[string]map[string]BoundaryField
BoundaryFieldsMap is a mapping service -> type -> boundary query
func (BoundaryFieldsMap) Field ¶
func (m BoundaryFieldsMap) Field(serviceURL, typeName string) (BoundaryField, error)
Query returns the boundary field for the given service and type
func (BoundaryFieldsMap) RegisterField ¶
func (m BoundaryFieldsMap) RegisterField(serviceURL, typeName string, field string, argument string, array bool)
RegisterField registers a boundary field
type ClientOpt ¶
type ClientOpt func(*GraphQLClient)
ClientOpt is a function used to set a GraphQL client option
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client to be used when making downstream queries.
func WithMaxResponseSize ¶
WithMaxResponseSize sets the max allowed response size. The client will only read up to maxResponseSize and that size is exceeded an an error will be returned.
func WithUserAgent ¶
WithUserAgent set the user agent used by the client.
type Config ¶
type Config struct { IdFieldName string `json:"id-field-name"` GatewayListenAddress string `json:"gateway-address"` DisableIntrospection bool `json:"disable-introspection"` MetricsListenAddress string `json:"metrics-address"` PrivateListenAddress string `json:"private-address"` GatewayPort int `json:"gateway-port"` MetricsPort int `json:"metrics-port"` PrivatePort int `json:"private-port"` DefaultTimeouts TimeoutConfig `json:"default-timeouts"` GatewayTimeouts TimeoutConfig `json:"gateway-timeouts"` PrivateTimeouts TimeoutConfig `json:"private-timeouts"` Services []string `json:"services"` LogLevel log.Level `json:"loglevel"` PollInterval string `json:"poll-interval"` PollIntervalDuration time.Duration MaxRequestsPerQuery int64 `json:"max-requests-per-query"` MaxServiceResponseSize int64 `json:"max-service-response-size"` Plugins []PluginConfig // Config extensions that can be shared among plugins Extensions map[string]json.RawMessage // HTTP client to customize for downstream services query QueryHTTPClient *http.Client // contains filtered or unexported fields }
Config contains the gateway configuration
func (*Config) ConfigurePlugins ¶
ConfigurePlugins calls the Configure method on each plugin.
func (*Config) GatewayAddress ¶
GatewayAddress returns the host:port string of the gateway
func (*Config) MetricAddress ¶
MetricAddress returns the address for the metric port
func (*Config) PrivateAddress ¶
PrivateAddress returns the address for private port
func (*Config) PrivateHttpAddress ¶
type EventFields ¶
type EventFields map[string]interface{}
EventFields contains fields to be logged for the event
type ExecutableSchema ¶
type ExecutableSchema struct { MergedSchema *ast.Schema Locations FieldURLMap IsBoundary map[string]bool Services map[string]*Service BoundaryQueries BoundaryFieldsMap GraphqlClient *GraphQLClient MaxRequestsPerQuery int64 // contains filtered or unexported fields }
ExecutableSchema contains all the necessary information to execute queries
func NewExecutableSchema ¶
func NewExecutableSchema(plugins []Plugin, maxRequestsPerQuery int64, client *GraphQLClient, services ...*Service) *ExecutableSchema
func (*ExecutableSchema) Complexity ¶
func (s *ExecutableSchema) Complexity(typeName, fieldName string, childComplexity int, args map[string]interface{}) (int, bool)
Complexity returns the query complexity (unimplemented)
func (*ExecutableSchema) Exec ¶
func (s *ExecutableSchema) Exec(ctx context.Context) graphql.ResponseHandler
Exec returns the query execution handler
func (*ExecutableSchema) ExecuteQuery ¶
func (s *ExecutableSchema) ExecuteQuery(ctx context.Context) *graphql.Response
func (*ExecutableSchema) Schema ¶
func (s *ExecutableSchema) Schema() *ast.Schema
Schema returns the merged schema
func (*ExecutableSchema) UpdateSchema ¶
func (s *ExecutableSchema) UpdateSchema(forceRebuild bool) error
UpdateSchema updates the schema from every service and then update the merged schema.
func (*ExecutableSchema) UpdateServiceList ¶
func (s *ExecutableSchema) UpdateServiceList(services []string) error
UpdateServiceList replaces the list of services with the provided one and update the schema.
type FieldURLMap ¶
FieldURLMap maps fields to service URLs
func (FieldURLMap) RegisterURL ¶
func (m FieldURLMap) RegisterURL(parent string, field string, location string)
RegisterURL registers the location for the given field
type Gateway ¶
type Gateway struct { ExecutableSchema *ExecutableSchema // contains filtered or unexported fields }
Gateway contains the public and private routers
func FromConfig ¶
func NewGateway ¶
func NewGateway(executableSchema *ExecutableSchema, plugins []Plugin) *Gateway
NewGateway returns the graphql gateway server mux
func (*Gateway) PrivateRouter ¶
PrivateRouter returns the private http handler
func (*Gateway) UpdateSchemas ¶
UpdateSchemas periodically updates the execute schema
type GraphQLClient ¶
GraphQLClient is a GraphQL client.
func NewClient ¶
func NewClient(opts ...ClientOpt) *GraphQLClient
NewClient creates a new GraphQLClient from the given options.
func NewClientWithPlugins ¶
func NewClientWithPlugins(plugins []Plugin, opts ...ClientOpt) *GraphQLClient
func NewClientWithoutKeepAlive ¶
func NewClientWithoutKeepAlive(opts ...ClientOpt) *GraphQLClient
type GraphqlError ¶
type GraphqlError struct { Message string `json:"message"` Path ast.Path `json:"path,omitempty"` Extensions map[string]interface{} `json:"extensions"` }
GraphqlError is a single GraphQL error
type GraphqlErrors ¶
type GraphqlErrors []GraphqlError
GraphqlErrors represents a list of GraphQL errors, as returned in a GraphQL response.
func (GraphqlErrors) Error ¶
func (e GraphqlErrors) Error() string
Error returns a string representation of the error list
type OperationPermissions ¶
type OperationPermissions struct { AllowedRootQueryFields AllowedFields `json:"query"` AllowedRootMutationFields AllowedFields `json:"mutation"` AllowedRootSubscriptionFields AllowedFields `json:"subscription"` }
OperationPermissions represents the user permissions for all operation types
func GetPermissionsFromContext ¶
func GetPermissionsFromContext(ctx context.Context) (OperationPermissions, bool)
GetPermissionsFromContext returns the permissions stored in the context
func MergePermissions ¶
func MergePermissions(perms ...OperationPermissions) OperationPermissions
MergePermissions merges the given permissions. The result permissions are the union of the given permissions (allow everything that is allowed in any of the given permissions).
func (*OperationPermissions) FilterAuthorizedFields ¶
func (o *OperationPermissions) FilterAuthorizedFields(op *ast.OperationDefinition) gqlerror.List
FilterAuthorizedFields filters the operation's selection set and removes all fields that are not explicitly authorized. Every unauthorized field is returned as an error.
func (*OperationPermissions) FilterSchema ¶
func (o *OperationPermissions) FilterSchema(schema *ast.Schema) *ast.Schema
FilterSchema returns a copy of the given schema stripped of any unauthorized fields and types
func (OperationPermissions) MarshalJSON ¶
func (o OperationPermissions) MarshalJSON() ([]byte, error)
MarshalJSON marshals to a JSON representation.
type PlanningContext ¶
type PlanningContext struct { Operation *ast.OperationDefinition Schema *ast.Schema Locations FieldURLMap IsBoundary map[string]bool Services map[string]*Service }
PlanningContext contains the necessary information used to plan a query.
type Plugin ¶
type Plugin interface { // ID must return the plugin identifier (name). This is the id used to match // the plugin in the configuration. ID() string // Configure is called during initialization and every time the config is modified. // The pluginCfg argument is the raw json contained in the "config" key for that plugin. Configure(cfg *Config, pluginCfg json.RawMessage) error // Init is called once on initialization Init(schema *ExecutableSchema) SetupPublicMux(mux *http.ServeMux) SetupPrivateMux(mux *http.ServeMux) // Should return true and the query path if the plugin is a service that // should be federated by Bramble GraphqlQueryPath() (bool, string) ApplyMiddlewarePublicMux(http.Handler) http.Handler ApplyMiddlewarePrivateMux(http.Handler) http.Handler WrapGraphQLClientTransport(http.RoundTripper) http.RoundTripper InterceptRequest(ctx context.Context, operationName, rawQuery string, variables map[string]interface{}) InterceptResponse(ctx context.Context, operationName, rawQuery string, variables map[string]interface{}, response *graphql.Response) *graphql.Response }
Plugin is a Bramble plugin. Plugins can be used to extend base Bramble functionalities.
type PluginConfig ¶
type PluginConfig struct { Name string Config json.RawMessage }
PluginConfig contains the configuration for the named plugin
type QueryPlan ¶
type QueryPlan struct {
RootSteps []*QueryPlanStep
}
QueryPlan is a query execution plan
func Plan ¶
func Plan(ctx *PlanningContext) (*QueryPlan, error)
Plan returns a query plan from the given planning context
type QueryPlanStep ¶
type QueryPlanStep struct { ServiceURL string ServiceName string ParentType string SelectionSet ast.SelectionSet InsertionPoint []string Then []*QueryPlanStep }
QueryPlanStep is a single execution step
func (*QueryPlanStep) MarshalJSON ¶
func (s *QueryPlanStep) MarshalJSON() ([]byte, error)
MarshalJSON marshals the step the JSON
type Request ¶
type Request struct { Query string `json:"query"` OperationName string `json:"operationName,omitempty"` Variables map[string]interface{} `json:"variables,omitempty"` Headers http.Header `json:"-"` }
Request is a GraphQL request.
func NewRequest ¶
NewRequest creates a new GraphQL requests from the provided body.
func (*Request) WithOperationName ¶
func (*Request) WithVariables ¶
type Response ¶
type Response struct { Errors GraphqlErrors `json:"errors"` Data interface{} }
Response is a GraphQL response