From 6f4395db2b20e3a56936ab02ba42b92c7f25d9cc Mon Sep 17 00:00:00 2001 From: Gene Armstrong Date: Fri, 31 May 2024 10:17:43 -0700 Subject: [PATCH] chore: add dev var scrubber for graphql logging --- slog.go | 10 ++++++++++ slog_test.go | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/slog.go b/slog.go index 02cb5d3..06bbbeb 100644 --- a/slog.go +++ b/slog.go @@ -54,6 +54,16 @@ func (noopVariablesScrubber) Scrub(vars map[string]any) map[string]any { return nil } +var _ VariablesScrubber = (*DevScrubber)(nil) + +// DevScrubber is a VariablesScrubber that passes all var information from +// GraphQL variables. It is intended for use in development environments. +type DevScrubber struct{} + +func (DevScrubber) Scrub(vars map[string]any) map[string]any { + return vars +} + // NewSLogGraphQLResponseMiddleware is used to log GraphQL requests and responses. func NewSLogGraphQLResponseMiddleware(l *slog.Logger, s VariablesScrubber) graphql.ResponseMiddleware { if l == nil { diff --git a/slog_test.go b/slog_test.go index 4776a95..6b374f8 100644 --- a/slog_test.go +++ b/slog_test.go @@ -70,6 +70,17 @@ var _ = Describe("Logger", func() { }) }) + Describe("DevScrubber#Scrub", func() { + It("should return the same map", func() { + s := DevScrubber{} + + in := map[string]any{"test": struct{ Data string }{Data: "data"}} + res := s.Scrub(in) + + g.Expect(res).To(g.Equal(in)) + }) + }) + Describe("NewGraphQLResponseMiddleware", func() { It("should log GraphQL response and request info", func() { var (