From 5b7e016100c941a87969535a53f8dbbf081d9f77 Mon Sep 17 00:00:00 2001 From: Lucian Jones Date: Mon, 2 May 2022 11:05:40 +1200 Subject: [PATCH] Add InterceptRequest plugin interception point --- execution.go | 4 ++++ plugin.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/execution.go b/execution.go index 24c2bb10..d79c4fb2 100644 --- a/execution.go +++ b/execution.go @@ -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) diff --git a/plugin.go b/plugin.go index 0c82fdef..5f3242f8 100644 --- a/plugin.go +++ b/plugin.go @@ -1,6 +1,7 @@ package bramble import ( + "context" "encoding/json" "net/http" @@ -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 @@ -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