-
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
Return context.Context from FieldMiddleware #327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets try and keep API breaks off master until we are ready to shop the next major release, maybe bring back the next
branch?
@mathewbyrne have any thoughts?
n := next | ||
next = func(ctx context.Context) (interface{}, error) { | ||
return ec.directives.{{$directive.Name|ucFirst}}({{$directive.CallArgs}}) | ||
res := func() interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed to return values 1 to 2. but generated code will return return graphql.Null
.
this immidiately execute function is wrapping it.
@@ -38,7 +38,7 @@ | |||
Field: field, | |||
} | |||
ctx = graphql.WithResolverContext(ctx, rctx) | |||
resTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(ctx context.Context) (interface{}, error) { | |||
ctx, resTmp := ec.FieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(ctx context.Context) (interface{}, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its probably preferable to update ctx rather than shadowing it and disabling a bunch of linter checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sees that there is not much value for the this hard work... 🤔
func DefaultResolverMiddleware(ctx context.Context, next Resolver) (res interface{}, err error) { | ||
return next(ctx) | ||
func DefaultResolverMiddleware(ctx context.Context, next Resolver) (context.Context, interface{}, error) { | ||
res, err := next(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this interface mismatch imply resolvers cant change their childs context either? Should we be thinking a little broader than just directives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an interesting point.
Does resolvers and directives need to modify context?
For Resolver, I can not make an idea that use case.
For directive, It doesn't have tree structure, because it doesn't need to modify context. I think directive middleware may be good.
👀 |
May be, somehow, we can add second type for middleware? One with context and the second without? |
I'm trying to use OpenCensus for query tracing.
Problem is gqlgen can't propagate tracing span to next resolver.
We can organize resolver tracing to tree structure after this PR merged.
I think same issue has in OpenTracing at here
example stack with this PR
I have: