【问题标题】:How to allow any field filtering in graphene GraphQl如何允许石墨烯GraphQl中的任何字段过滤
【发布时间】:2021-10-29 09:03:55
【问题描述】:

我想知道,是否有办法在石墨烯 GraphQl 解析器中传递更多要查询的参数。

因此,此代码仅适用于 wgr_bez

class GraphqlService(graphene.ObjectType):
    get_single_article = graphene.Field(ArticleGrapheneModel, wgr_bez=graphene.String)


    @staticmethod
    async def resolve_get_single_article(parent, info, **kwargs):
        article = await info.context['request'].state.db.select_article_with_filter(kwargs)
        return article[0][0].to_json()

使用 **kwargs 我可以从请求中获取任何列:值对,但是如何传递任何列:值,我不明白。

我希望能够用更通用的东西或至少是字典来替换它。我在文档中看到了它,但是当我这样做时出现错误:

get_single_article = graphene.Field(ArticleGrapheneModel, {'wgr_bez': graphene.String, 'id': graphene.Int})

ValueError: Unknown argument "wgr_bez".

【问题讨论】:

    标签: graphql graphene-python


    【解决方案1】:

    我找到了答案,需要如下定义参数:

    get_single_article = graphene.Field(ArticleGrapheneModel, args={'wgr_bez': graphene.Argument(graphene.String),
                                                                    'id': graphene.Argument(graphene.Int)})
    

    【讨论】:

      猜你喜欢
      • 2019-12-20
      • 2017-05-11
      • 2017-05-13
      • 2020-07-27
      • 2018-03-11
      • 2021-07-08
      • 2019-08-08
      • 2020-09-19
      • 2020-01-20
      相关资源
      最近更新 更多