Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphene mutation with list as input

I have a graphene mutation like this:


class User(ObjectType):
    username = String()

class ImportUsers(Mutation):
    class Arguments:
        users = List(User)
    Output = List(User)

    @staticmethod
    def mutation(root, info, users):
        ...

But graphene gives me the following error: AssertionError: Mutations.importUsers(users:) argument type must be Input Type but got: [User].

How can I have a mutation in graphene which accepts a list of objects?

like image 796
ojii Avatar asked Jan 25 '23 01:01

ojii


1 Answers

I was trying roughly the same thing as you did.

Figured out that custom input types should inherit from graphene.InputObjectType instead of graphene.ObjectType.

class User(graphene.InputObjectType):  # <-- Changed to InputObjectType
    username = graphene.String()

So, having your User like this should solve the case.

like image 86
Icebreaker454 Avatar answered Jan 27 '23 14:01

Icebreaker454