我开始用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.
问题出在进口。 当我使用:
在下一个示例中,我发现了如何从docs正确导入它。这里是:
^{pr2}$问题是我安装的graphene版本,安装graphene2.0解决了这个问题。在
相关问题 更多 >
编程相关推荐