热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ImplementFieldMiddlewareStack

Followingonfrom#217thischangeintroducesatheconceptofDirectiveMiddlewaretoge

Following on from #217 this change introduces a the concept of DirectiveMiddleware to generated code.

A

1
DirectiveRoot

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

1
DirectiveRoot

will contain a field for each that the user can assign. Each field has the same signature as a

1
ResolverMiddleware

, 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
    1
    gqlgen

    and

    1
    gqlparser

    .


  • 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
    1
    NewExecutableSchema

    , and the config that can be provided to

    1
    GraphQL

    .


  • This only supports schema-directives on fields definitions.

  • Currently
    1
    DirectiveRoot

    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.





   



推荐阅读
author-avatar
手机用户2502920043
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有