Skip to content

Commit

Permalink
docs: short-lived loader (#2778)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenyui committed Sep 2, 2023
1 parent cc4e0ba commit a41f4da
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/content/reference/dataloaders.md
Expand Up @@ -147,10 +147,11 @@ func NewLoaders(conn *sql.DB) *Loaders {
}

// Middleware injects data loaders into the context
func Middleware(loaders *Loaders, next http.Handler) http.Handler {
func Middleware(conn *sql.DB, next http.Handler) http.Handler {
// return a middleware that injects the loader to the request context
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r = r.WithContext(context.WithValue(r.Context(), loadersKey, loaders))
loader := NewLoaders(conn)
r = r.WithContext(context.WithValue(r.Context(), loadersKey, loader))
next.ServeHTTP(w, r)
})
}
Expand Down

0 comments on commit a41f4da

Please sign in to comment.