石墨烯突变错误,字段必须是映射(dict/OrderedDict)

2024-06-07 18:14:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始用GraphQl/Graphene包住我的头。我正在构建一个连接到MongoDB的模式。到目前为止,除了基因突变,所有这些似乎都有效。我一直在跟踪示例here和{a2},但运气不好。有人能告诉我我做错了什么吗?提前谢谢。在

import graphene

class GeoInput(graphene.InputObjectType):
    lat = graphene.Float(required=True)
    lng = graphene.Float(required=True)

    @property
    def latlng(self):
        return "({},{})".format(self.lat, self.lng)


class Address(graphene.ObjectType):
    latlng = graphene.String()


class CreateAddress(graphene.Mutation):

    class Arguments:
        geo = GeoInput(required=True)

    Output = Address

    def mutate(self, info, geo):
        return Address(latlng=geo.latlng)


class Mutation(graphene.ObjectType):
    create_address = CreateAddress.Field()


class Query(graphene.ObjectType):
    address = graphene.Field(Address, geo=GeoInput(required=True))
    def resolve_address(self, info, geo):
        return Address(latlng=geo.latlng)

schema = graphene.Schema(query=Query, mutation=Mutation)

上面的代码会生成以下错误:

AssertionError: CreateAddress fields must be a mapping (dict / OrderedDict) with field names as keys or a function which returns such a mapping.


Tags: selftruereturnaddressdefrequiredclassgraphene
2条回答

问题出在进口。 当我使用:

from graphene import ObjectType

在下一个示例中,我发现了如何从docs正确导入它。这里是:

^{pr2}$

问题是我安装的graphene版本,安装graphene2.0解决了这个问题。在

相关问题 更多 >

    热门问题