Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new ResultCallbackFn with origin http.ResponseWriter and http.Req… #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ const (

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

type ResultCallbackFnV2 func(ctx context.Context, params *graphql.Params, result *graphql.Result, w http.ResponseWriter, r *http.Request)

type Handler struct {
Schema *graphql.Schema
pretty bool
graphiql bool
playground bool
rootObjectFn RootObjectFn
resultCallbackFn ResultCallbackFn
resultCallbackFnV2 ResultCallbackFnV2
formatErrorFn func(err error) gqlerrors.FormattedError
}

Expand Down Expand Up @@ -186,6 +189,10 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
if h.resultCallbackFn != nil {
h.resultCallbackFn(ctx, &params, result, buff)
}

if h.resultCallbackFnV2 != nil {
h.resultCallbackFnV2(ctx, &params, result, w, r)
}
}

// ServeHTTP provides an entrypoint into executing graphQL queries.
Expand All @@ -203,6 +210,7 @@ type Config struct {
Playground bool
RootObjectFn RootObjectFn
ResultCallbackFn ResultCallbackFn
ResultCallbackFnV2 ResultCallbackFnV2
FormatErrorFn func(err error) gqlerrors.FormattedError
}

Expand Down Expand Up @@ -231,6 +239,7 @@ func New(p *Config) *Handler {
playground: p.Playground,
rootObjectFn: p.RootObjectFn,
resultCallbackFn: p.ResultCallbackFn,
resultCallbackFnV2: p.ResultCallbackFnV2,
formatErrorFn: p.FormatErrorFn,
}
}