Skip to content

Commit

Permalink
Add InterceptRequest plugin interception point
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucian Jones committed May 1, 2022
1 parent a1e312a commit 5b7e016
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (s *ExecutableSchema) ExecuteQuery(ctx context.Context) *graphql.Response {
operation := operationCtx.Operation
variables := operationCtx.Variables

for _, plugin := range s.plugins {
plugin.InterceptRequest(ctx, operation.Name, operationCtx.RawQuery, variables)
}

AddField(ctx, "operation.name", operation.Name)
AddField(ctx, "operation.type", operation.Operation)

Expand Down
8 changes: 8 additions & 0 deletions plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bramble

import (
"context"
"encoding/json"
"net/http"

Expand All @@ -25,6 +26,8 @@ type Plugin interface {
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{})
}

// BasePlugin is an empty plugin. It can be embedded by any plugin as a way to avoid
Expand All @@ -50,6 +53,11 @@ func (p *BasePlugin) GraphqlQueryPath() (bool, string) {
return false, ""
}

// InterceptRequest is called before bramble starts executing a request.
// It can be used to inspect the unmarshalled GraphQL request bramble receives.
func (p *BasePlugin) InterceptRequest(ctx context.Context, operationName, rawQuery string, variables map[string]interface{}) {
}

// ApplyMiddlewarePublicMux ...
func (p *BasePlugin) ApplyMiddlewarePublicMux(h http.Handler) http.Handler {
return h
Expand Down

0 comments on commit 5b7e016

Please sign in to comment.