Skip to content

Commit 3bcd329

Browse files
author
陈鹏飞 chenpengfei
committed
add new ResultCallbackFn with origin http.ResponseWriter and http.Request
1 parent c126735 commit 3bcd329

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

handler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ const (
2222

2323
type ResultCallbackFn func(ctx context.Context, params *graphql.Params, result *graphql.Result, responseBody []byte)
2424

25+
type ResultCallbackFnV2 func(ctx context.Context, params *graphql.Params, result *graphql.Result, w http.ResponseWriter, r *http.Request)
26+
2527
type Handler struct {
2628
Schema *graphql.Schema
2729
pretty bool
2830
graphiql bool
2931
playground bool
3032
rootObjectFn RootObjectFn
3133
resultCallbackFn ResultCallbackFn
34+
resultCallbackFnV2 ResultCallbackFnV2
3235
formatErrorFn func(err error) gqlerrors.FormattedError
3336
}
3437

@@ -186,6 +189,10 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
186189
if h.resultCallbackFn != nil {
187190
h.resultCallbackFn(ctx, &params, result, buff)
188191
}
192+
193+
if h.resultCallbackFnV2 != nil {
194+
h.resultCallbackFnV2(ctx, &params, result, w, r)
195+
}
189196
}
190197

191198
// ServeHTTP provides an entrypoint into executing graphQL queries.
@@ -203,6 +210,7 @@ type Config struct {
203210
Playground bool
204211
RootObjectFn RootObjectFn
205212
ResultCallbackFn ResultCallbackFn
213+
ResultCallbackFnV2 ResultCallbackFnV2
206214
FormatErrorFn func(err error) gqlerrors.FormattedError
207215
}
208216

@@ -231,6 +239,7 @@ func New(p *Config) *Handler {
231239
playground: p.Playground,
232240
rootObjectFn: p.RootObjectFn,
233241
resultCallbackFn: p.ResultCallbackFn,
242+
resultCallbackFnV2: p.ResultCallbackFnV2,
234243
formatErrorFn: p.FormatErrorFn,
235244
}
236245
}

0 commit comments

Comments
 (0)