作者:手机用户2502920043 | 来源:互联网 | 2023-07-10 20:23
Following on from #217 this change introduces a the concept of DirectiveMiddleware to generated code.
A
struct is now created and can be passed in when creating an executable schema. If a directive is encountered during codegen from the source schema, this
will contain a field for each that the user can assign. Each field has the same signature as a
, and is run on fields with this directive at the end of the resolver middleware chain.
Within the directive middleware, users can access the current request and resolver contexts, and can either call the next middleware in the chain, or return a value early.
Limitations
- Currently there is no direct support for directive arguments. This is coming soon but may depend on some refactoring around coerced values both in
and
.
- If returning a new value, middlewares need to take care to return a value of the expected type, as this will be cast back after the middleware stack has resolved.
- There is probably a refactor to happen around config now required to pass into
, and the config that can be provided to
.
- This only supports schema-directives on fields definitions.
- Currently
is implemented as a struct, but this could easily also be an interface instead. Current thinking is that a struct allows a user to get up and running without having to implement their directives immediately; they are noops until set.
该提问来源于开源项目:99designs/gqlgen
I have implemented with context suggestion and commented on #262
Thanks for the help anyways. You guys are doing the awesome job.