@@ -41,6 +41,7 @@ import (
4141 "github.com/getprobo/probo/pkg/usrmgr"
4242 "github.com/go-chi/chi/v5"
4343 "github.com/vektah/gqlparser/v2/gqlerror"
44+ "go.gearno.de/kit/log"
4445)
4546
4647type (
@@ -77,7 +78,14 @@ func UserFromContext(ctx context.Context) *coredata.User {
7778 return user
7879}
7980
80- func NewMux (proboSvc * probo.Service , usrmgrSvc * usrmgr.Service , authCfg AuthConfig , connectorRegistry * connector.ConnectorRegistry , safeRedirect * saferedirect.SafeRedirect ) * chi.Mux {
81+ func NewMux (
82+ logger * log.Logger ,
83+ proboSvc * probo.Service ,
84+ usrmgrSvc * usrmgr.Service ,
85+ authCfg AuthConfig ,
86+ connectorRegistry * connector.ConnectorRegistry ,
87+ safeRedirect * saferedirect.SafeRedirect ,
88+ ) * chi.Mux {
8189 r := chi .NewMux ()
8290
8391 r .Get (
@@ -197,12 +205,12 @@ func NewMux(proboSvc *probo.Service, usrmgrSvc *usrmgr.Service, authCfg AuthConf
197205 }))
198206
199207 r .Get ("/" , playground .Handler ("GraphQL" , "/api/console/v1/query" ))
200- r .Post ("/query" , graphqlHandler (proboSvc , usrmgrSvc , authCfg ))
208+ r .Post ("/query" , graphqlHandler (logger , proboSvc , usrmgrSvc , authCfg ))
201209
202210 return r
203211}
204212
205- func graphqlHandler (proboSvc * probo.Service , usrmgrSvc * usrmgr.Service , authCfg AuthConfig ) http.HandlerFunc {
213+ func graphqlHandler (logger * log. Logger , proboSvc * probo.Service , usrmgrSvc * usrmgr.Service , authCfg AuthConfig ) http.HandlerFunc {
206214 var mb int64 = 1 << 20
207215
208216 es := schema .NewExecutableSchema (
@@ -225,8 +233,8 @@ func graphqlHandler(proboSvc *probo.Service, usrmgrSvc *usrmgr.Service, authCfg
225233 srv .Use (extension.Introspection {})
226234 srv .Use (tracingExtension {})
227235 srv .SetRecoverFunc (func (ctx context.Context , err any ) error {
228- panicValue := ctx . Value ( panicValueContextKey ).( * any )
229- * panicValue = err
236+ logger . Error ( "resolver panic" , log . Any ( "error" , err ) )
237+
230238 return fmt .Errorf ("resolver panic: %v" , err )
231239 })
232240
@@ -253,20 +261,7 @@ func graphqlHandler(proboSvc *probo.Service, usrmgrSvc *usrmgr.Service, authCfg
253261 },
254262 )
255263
256- return WithSession (usrmgrSvc , authCfg , func (w http.ResponseWriter , r * http.Request ) {
257- ctx := r .Context ()
258-
259- // Hack to capture the panic value, because gqlgen execute resolver in a different goroutine.
260- // And I want use the go.gearno.de/kit/httpserver built in panic recovery.
261- var panicValue any
262- ctx = context .WithValue (ctx , panicValueContextKey , & panicValue )
263-
264- srv .ServeHTTP (w , r .WithContext (ctx ))
265-
266- if panicValue != nil {
267- panic (panicValue )
268- }
269- })
264+ return WithSession (usrmgrSvc , authCfg , srv .ServeHTTP )
270265}
271266
272267func WithSession (usrmgrSvc * usrmgr.Service , authCfg AuthConfig , next http.HandlerFunc ) http.HandlerFunc {
0 commit comments