Skip to content
Advertisement

Graphene Mutation error, fields must be a mapping (dict / OrderedDict)

I’m starting to wrap my head around with GraphQl/Graphene. I’m building a schema connected to a MongoDB. All seems to work so far except mutations. I’ve been following the example here and here without luck. Can someone point me towards what I’m doing wrong? Thanks in advance.

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)

The code above generates this error:

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

Advertisement

Answer

The issue was with the version of graphene I had installed, installing graphene 2.0 solved the issue.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement