Skip to content

Commit

Permalink
chore: add dev var scrubber for graphql logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gjarmstrong committed May 31, 2024
1 parent b9047d1 commit 6f4395d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions slog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 6f4395d

Please sign in to comment.