graphql-python / graphene

GraphQL framework for Python

Home Page:http://graphene-python.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mutation error: must be a mapping (dict / OrderedDict) with field names as keys or a function

simkessy opened this issue · comments

I'm trying to return an object / class in my mutation response but Im getting this error:

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

class SuccessResponse(ObjectType):
    job_id = String
    user = String


class Payload(relay.ClientIDMutation):
    class Input(object):
        emails = List(String, description="List of user emails")

    success = List(SuccessResponse)

    @classmethod
    def mutate_and_get_payload(cls, root, info, **kwargs):
        success = []
        raw_emails = kwargs.get('emails')

        for user in raw_emails:
            job_id = do_job(user.id)
            success.append(SuccessResponse(job_id='job_id', user='user'))

        # Return the payload
        return Payload(success=success)