Documentation ¶
Index ¶
- Constants
- 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 GetOutgoingRequestHeadersFromContext(ctx context.Context) http.Header
- func Main()
- func MergeSchemas(schemas ...*ast.Schema) (*ast.Schema, error)
- func NewMetricsHandler() http.Handler
- func Plan(ctx *PlanningContext) (*queryPlan, error)
- 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 Request
- type Response
- type Service
Constants ¶
const DebugKey contextKey = "debug"
Variables ¶
This section is empty.
Functions ¶
func AddFields ¶
func AddFields(ctx context.Context, fields EventFields)
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 GetOutgoingRequestHeadersFromContext ¶
GetOutgoingRequestHeadersFromContext get the headers that should be added to outgoing requests
func NewMetricsHandler ¶
func Plan ¶
func Plan(ctx *PlanningContext) (*queryPlan, error)
func RegisterMetrics ¶
func RegisterMetrics()
func RegisterPlugin ¶
func RegisterPlugin(p Plugin)
func RegisteredPlugins ¶
func TraceIDFromContext ¶
func ValidateSchema ¶
Types ¶
type AllowedFields ¶
type AllowedFields struct { AllowAll bool AllowedSubfields map[string]AllowedFields }
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)
func (*AllowedFields) UnmarshalJSON ¶
func (a *AllowedFields) UnmarshalJSON(input []byte) error
type BasePlugin ¶
type BasePlugin struct{}
func (*BasePlugin) ApplyMiddlewarePrivateMux ¶
func (p *BasePlugin) ApplyMiddlewarePrivateMux(h http.Handler) http.Handler
func (*BasePlugin) ApplyMiddlewarePublicMux ¶
func (p *BasePlugin) ApplyMiddlewarePublicMux(h http.Handler) http.Handler
func (*BasePlugin) Configure ¶
func (p *BasePlugin) Configure(*Config, json.RawMessage) error
func (*BasePlugin) GraphqlQueryPath ¶
func (p *BasePlugin) GraphqlQueryPath() (bool, string)
func (*BasePlugin) Init ¶
func (p *BasePlugin) Init(s *ExecutableSchema)
func (*BasePlugin) ModifyExtensions ¶
func (p *BasePlugin) ModifyExtensions(ctx context.Context, e *QueryExecution, extensions map[string]interface{}) error
func (*BasePlugin) SetupPrivateMux ¶
func (p *BasePlugin) SetupPrivateMux(mux *http.ServeMux)
func (*BasePlugin) SetupPublicMux ¶
func (p *BasePlugin) SetupPublicMux(mux *http.ServeMux)
type BoundaryQueriesMap ¶ added in v1.1.0
type BoundaryQueriesMap map[string]map[string]BoundaryQuery
func (BoundaryQueriesMap) Query ¶ added in v1.1.0
func (m BoundaryQueriesMap) Query(serviceURL, typeName string) BoundaryQuery
func (BoundaryQueriesMap) RegisterQuery ¶ added in v1.1.0
func (m BoundaryQueriesMap) RegisterQuery(serviceURL, typeName, query string, array bool)
type BoundaryQuery ¶ added in v1.1.0
type ClientOpt ¶ added in v1.1.0
type ClientOpt func(*GraphQLClient)
func WithMaxResponseSize ¶ added in v1.1.0
func WithUserAgent ¶ added in v1.1.7
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 ¶
func (*Config) GatewayAddress ¶
GatewayAddress returns the host:port string of the gateway
func (*Config) MetricAddress ¶
func (*Config) PrivateAddress ¶
type EventFields ¶
type EventFields map[string]interface{}
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 }
func (*ExecutableSchema) Complexity ¶
func (*ExecutableSchema) Exec ¶
func (s *ExecutableSchema) Exec(ctx context.Context) graphql.ResponseHandler
func (*ExecutableSchema) ExecuteQuery ¶
func (s *ExecutableSchema) ExecuteQuery(ctx context.Context) *graphql.Response
func (*ExecutableSchema) Schema ¶
func (s *ExecutableSchema) Schema() *ast.Schema
func (*ExecutableSchema) UpdateSchema ¶
func (s *ExecutableSchema) UpdateSchema(forceRebuild bool) error
func (*ExecutableSchema) UpdateServiceList ¶
func (s *ExecutableSchema) UpdateServiceList(services []string) error
type FieldURLMap ¶
func (FieldURLMap) RegisterURL ¶
func (m FieldURLMap) RegisterURL(parent string, field string, location string)
type Gateway ¶
type Gateway struct { ExecutableSchema *ExecutableSchema // contains filtered or unexported fields }
func NewGateway ¶
func NewGateway(executableSchema *ExecutableSchema, plugins []Plugin) *Gateway
NewGateway returns the graphql gateway server mux
func (*Gateway) PrivateRouter ¶
func (*Gateway) UpdateSchemas ¶
type GraphQLClient ¶
type GraphQLClient struct { HTTPClient *http.Client MaxResponseSize int64 Tracer opentracing.Tracer UserAgent string }
func NewClient ¶
func NewClient(opts ...ClientOpt) *GraphQLClient
type GraphqlError ¶
type GraphqlErrors ¶
type GraphqlErrors []GraphqlError
func (GraphqlErrors) Error ¶
func (e GraphqlErrors) Error() string
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)
type PlanningContext ¶
type PlanningContext struct { Operation *ast.OperationDefinition Schema *ast.Schema Locations FieldURLMap IsBoundary map[string]bool Services map[string]*Service }
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 }
type PluginConfig ¶
type PluginConfig struct { Name string Config json.RawMessage }
type QueryExecution ¶
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:"-"` }
func NewRequest ¶
type Response ¶
type Response struct { Errors GraphqlErrors `json:"errors"` Data interface{} }