From a41f4daad66cb0c102bfa09d7bff5a057d378197 Mon Sep 17 00:00:00 2001 From: Zen Yui Date: Sat, 2 Sep 2023 12:57:34 -0700 Subject: [PATCH] docs: short-lived loader (#2778) --- docs/content/reference/dataloaders.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/content/reference/dataloaders.md b/docs/content/reference/dataloaders.md index 479b516773a..d28be2a8fea 100644 --- a/docs/content/reference/dataloaders.md +++ b/docs/content/reference/dataloaders.md @@ -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) }) }