gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:06:50 27 4
gpt4 key购买 nike

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

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com