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 TraceIDFromContext(ctx context.Context) string
- 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) ModifyExtensions(ctx context.Context, e *QueryExecution, extensions map[string]interface{}) error
- func (p *BasePlugin) SetupPrivateMux(mux *http.ServeMux)
- func (p *BasePlugin) SetupPublicMux(mux *http.ServeMux)
- type BoundaryQueriesMap
- type BoundaryQuery
- type ClientOpt
- type Config
- 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 QueryExecution
- type QueryPlan
- type QueryPlanStep
- type Request
- type Response
- type Service
Constants ¶
const DebugKey contextKey = "debug"
DebugKey is used to request debug info from the context
Variables ¶
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 ¶ added in v1.1.8
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 TraceIDFromContext ¶
TraceIDFromContext retrieves the trace ID from the context if it exists. Returns an empty string otherwise.
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 ¶ added in v1.1.3
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) ModifyExtensions ¶
func (p *BasePlugin) ModifyExtensions(ctx context.Context, e *QueryExecution, extensions map[string]interface{}) error
ModifyExtensions ...
func (*BasePlugin) SetupPrivateMux ¶
func (p *BasePlugin) SetupPrivateMux(mux *http.ServeMux)
SetupPrivateMux ...
func (*BasePlugin) SetupPublicMux ¶
func (p *BasePlugin) SetupPublicMux(mux *http.ServeMux)
SetupPublicMux ...
type BoundaryQueriesMap ¶ added in v1.1.0
type BoundaryQueriesMap map[string]map[string]BoundaryQuery
BoundaryQueriesMap is a mapping service -> type -> boundary query
func (BoundaryQueriesMap) Query ¶ added in v1.1.0
func (m BoundaryQueriesMap) Query(serviceURL, typeName string) BoundaryQuery
Query returns the boundary query for the given service and type
func (BoundaryQueriesMap) RegisterQuery ¶ added in v1.1.0
func (m BoundaryQueriesMap) RegisterQuery(serviceURL, typeName, query string, array bool)
RegisterQuery registers a boundary query
type BoundaryQuery ¶ added in v1.1.0
BoundaryQuery contains the name and format for a boundary query
type ClientOpt ¶ added in v1.1.0
type ClientOpt func(*GraphQLClient)
ClientOpt is a function used to set a GraphQL client option
func WithMaxResponseSize ¶ added in v1.1.0
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 ¶ added in v1.1.7
WithUserAgent set the user agent used by the client.
type Config ¶
type Config struct {
GatewayPort int `json:"gateway-port"`
MetricsPort int `json:"metrics-port"`
PrivatePort int `json:"private-port"`
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
// 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
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 BoundaryQueriesMap
GraphqlClient *GraphQLClient
Tracer opentracing.Tracer
MaxRequestsPerQuery int64
// contains filtered or unexported fields
}
ExecutableSchema contains all the necessary information to execute queries
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
ExecuteQuery executes an incoming query
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 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 ¶
type GraphQLClient struct {
HTTPClient *http.Client
MaxResponseSize int64
Tracer opentracing.Tracer
UserAgent string
}
GraphQLClient is a GraphQL client.
func NewClient ¶
func NewClient(opts ...ClientOpt) *GraphQLClient
NewClient creates a new GraphQLClient from the given options.
type GraphqlError ¶
type GraphqlError struct {
Message string `json:"message"`
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 ¶ added in v1.1.3
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
ModifyExtensions(ctx context.Context, e *QueryExecution, extensions map[string]interface{}) error
}
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 QueryExecution ¶
type QueryExecution struct {
Schema *ast.Schema
Errors []*gqlerror.Error
RequestCount int64
// contains filtered or unexported fields
}
QueryExecution is a single query execution
type QueryPlan ¶ added in v1.2.0
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 ¶ added in v1.2.0
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 ¶ added in v1.2.0
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.
type Response ¶
type Response struct {
Errors GraphqlErrors `json:"errors"`
Data interface{}
}
Response is a GraphQL response
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
bramble
command
|
|
|
examples
|
|
|
gqlgen-service
command
|
|
|
graph-gophers-service
command
|
|
|
slow-service
module
|
|