-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Refactor handler package #885
Conversation
a6e0aea
to
aede7d1
Compare
e5cc6ed
to
572fb41
Compare
👍
cool! 👍
user login checker. out (internal) application doesn't response any contents when user is not loggged-in to our company's SSO. func userLoginChecker() interface {
graphql.HandlerExtension
graphql.OperationContextMutator
} {
errPresenter := graphQLErrorPresenter() // `srv.SetErrorPresenter(graphQLErrorPresenter())`
return &operationContextMutatorImpl{
name: "UserLoginChecker",
f: func(ctx context.Context, rc *graphql.OperationContext) *gqlerror.Error {
user := domains.CurrentUser(ctx)
if user == nil {
loginURL, err := aeuser.LoginURL(ctx, "/")
if err != nil {
return gqlerror.Errorf("%s", err.Error())
}
return errPresenter(ctx, domains.ErrLoginRequired.Detailf("loginURL: %s", loginURL))
}
return nil
},
}
}
but suggestions
|
👀 |
041e690
to
93a04e7
Compare
@vvakame I've injected operation context earlier now, so it should be availble during all of the handler hooks, and it now panics when trying to fetch it. This makes it possible for APQ to push stats in (it runs very early, on the raw request params before decoding)/ |
93a04e7
to
14dbf1a
Compare
cool! 👍 |
always return OperationContext for postpone process
Ok, time to ship this then. Lets start moving towards 0.11 (or maybe 1.0, if we get the plugin interfaces sorted too...) |
Refactoring the handler package deprecated some methods and this tutorial still uses those methods. Thus, this commit retires the following methods and use the new alternatives. * https://github.com/99designs/gqlgen/blob/5ad012e3d7be1127706b9c8a3da0378df3a98ec1/handler/handler.go#L17 * https://github.com/99designs/gqlgen/blob/5ad012e3d7be1127706b9c8a3da0378df3a98ec1/handler/handler.go#L242 See 99designs/gqlgen#885 for more details about the refactor.
* docs: Retire deprecated handler methods Refactoring the handler package deprecated some methods and this tutorial still uses those methods. Thus, this commit retires the following methods and use the new alternatives. * https://github.com/99designs/gqlgen/blob/5ad012e3d7be1127706b9c8a3da0378df3a98ec1/handler/handler.go#L17 * https://github.com/99designs/gqlgen/blob/5ad012e3d7be1127706b9c8a3da0378df3a98ec1/handler/handler.go#L242 See 99designs/gqlgen#885 for more details about the refactor. * fix: use handler.NewDefaultServer To use out-of-box transport configurations, use handler.NewDefaultServer instead of handler.New. * docs: Retire deprecated handler methods
Refactor handler package
The handler package has grown organically for a long time, its time to clean up the interfaces and get it ready for 1.0.
New handler extension API
The core of this changes the handler package to be a set of composable extensions. The extensions implement a set of optional interfaces:
Users of an extension should not need to know which extension points are being used by a given extension, they are added to the server simply by calling
Use(extension)
.There are a few convenience methods for defining middleware inline, instead of creating an extension
Middleware:
Transports
In addition to extensions, transports can also be registered against the server. Only one transport can serve a given request.
Transports:
new usage looks like this
More contesistent naming
As part of cleaning up the names the RequestContext has been renamed to OperationContext, as there can be multiple created during the lifecycle of a request. A new ResponseContext has also been created and error handling has been moved here. This allows each response in a subscription to have its own errors. I'm not sure what bugs this might have been causing before...
Removal of tracing
Many of the old interfaces collapse down into just a few extension points:
The tracing interface has also been removed, tracing stats are now measured in core (eg time to parse query) and made available on the operation/response contexts. Much of the old interface was designed so that users of a tracer dont need to know which extension points it was listening to, the new handler extensions have the same goal.
Backward compatibility
I've added a backwards compatibility layer that keeps most of the original interface in place. There are a few places where BC is known to be broken:
func(ctx context.Context, next func(ctx context.Context) []byte) []byte
and is nowfunc(ctx context.Context) *Response
. We could maintain BC by marshalling to json before and after, but the change is pretty easy to make and is likely to cause less issues.