Reputation: 4781
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?
Upvotes: 6
Views: 5553
Reputation: 1071
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.
Upvotes: 9
Reputation: 51
Yeah so, basically, you need to have this:
class User(graphene.ObjectType):
username = graphene.String()
class ImportUsers(Mutation):
class Arguments:
users = graphene.List(User)
Output = graphene.List(User)
@staticmethod
def mutation(root, info, users):
...
Graphene has a List type. Also, I don't know if it's just me or not, but I think you need to have graphene.(type), not just the type. I am working on something very similar right now to this, so hopefully you find or found your solution, and if you do, let me know how it went! Hopefully I helped xD. I am kinda new to all of this so ye
Upvotes: 4