graphene-python - 如何在 Graphite 烯 Python 中将复杂类型作为参数

我正在尝试创建一个接受复杂参数对象的查询,如下所示:

class Pair(graphene.ObjectType):
  x = graphene.Int()
  y = graphene.Int()

class Pairs(graphene.ObjectType):
  pairs = graphene.List(graphene.NonNull(graphene.Field(Pair, required=True)), required=True)

class Query(graphene.ObjectType):
  endpoint = graphene.Field(ResultType, pairs=graphene.Argument(Pairs, required=True))

我在测试中按如下方式调用它:

client = graphene.test.Client(graphene.Schema(query=Query))
executed = client.execute(
  """query($pairs: Pairs!) {
    endpoint(pairs: $pairs) {
      [result type goes here]
    }
  }"""

对这种方法可能有什么问题有什么想法吗?

最佳答案

我可以用下面的代码来做

class SomeFilter(graphene.InputObjectType):
    name = graphene.String()


class Query(graphene.ObjectType):
    all_somes = graphene.List(Some, options=SomeFilter())

    def resolve_all_somes(self, info, options=None):
        if options:
            if name := options.get('name'):

关于graphene-python - 如何在 Graphite 烯 Python 中将复杂类型作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62352292/

相关文章:

ruby-on-rails - 如何在 ruby​​ 中找到调用者类?

python - 如何在 Excel 的 Power Query 中运行 Python 脚本

python - 条件概率 - Python

javascript - 匿名访问如何跟踪?智威汤逊/ cookies / session ?

javascript - 如何在对象中保留一些深层 Prop ?

flutter - 如何在 Flutter 的 initState 中获取当前的 App Local

node.js - Node http.大文件传输失败并显示 'ERR_STREAM_PREMATU

python - `join` 或 `format` 字符串哪个更好?

javascript - react-router-dom 不工作只是渲染 "/"

html - Nodejs如何从ejs文件生成pdf文件