Skip to content

Commit

Permalink
Merge pull request #15 from nrfta/chore/add-dev-scrubber
Browse files Browse the repository at this point in the history
Add dev var scrubber for graphql logging
  • Loading branch information
gjarmstrong authored Jun 3, 2024
2 parents b9047d1 + 6f4395d commit 158289e
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 158289e

Please sign in to comment.