Is it possible to pass an array of inputs to a relay.clientIDMutation?
I want to update a django model that has a one to many relation with the model that has the mutation. I know this is possible with queries and also with graphene.Mutation mutations using class Arguments.
i am currently using graphene.relay.ClientIDMutation and I would like to know if its possible to have a dynamic sized class of inputs as an argument for the mutation.
here is a representation of inputs(array) I want to work with,
mutation{
addGamePrequels(input:{
gameThatNeedsPrequels: "game2"
gamearray:[
{
name:"test1",
price:"1",
datereleased:"2020-07-17",
},
{
name:"test2",
price:"1",
datereleased:"2020-07-17",
},
{
name:"test3",
price:"1",
datereleased:"2020-07-17",
},
]
}
){
game{
name
collection{
collectionname
}
}
}
}
@samarthkathal it should be possible to define an input type of List(MyInputType) to a mutation. Does that not work?
Hello, @samarthkathal , @jkimbo
I'm having an issue with the described method of using an input type of List(MyInputType).
Roughly, my code looks like this:
class MyInputType(graphene.ObjectType):
id = graphene.String(required=True)
credentials = graphene.JSONString(required=True)
class MyMutation(graphene.Mutation):
class Arguments:
my_types = graphene.List(MyInputType, required=True)
async def mutate(root, info, my_types):
# Do some stuff
It fails resolving the mutation fields:
File "/Users/icebreaker/Projects/graphene-test/lib/python3.9/site-packages/graphql/type/definition.py", line 745, in fields
raise TypeError(f"{self.name} fields cannot be resolved. {error}")
TypeError: MutationRoot fields cannot be resolved. Argument type must be a GraphQL input type.
Moreover, changing the graphene.List to graphene.Argument, raises the same exception.
I have tried to replace the MyInputType with a built-in graphene type: my_types = graphene.List(graphene.String, required=True), and the error did not appear.
I assume it's an issue with supporting custom ObjectType classes in mutation arguments.
@samarthkathal , @jkimbo , Just figured it out.
Custom input types should inherit from graphene.InputObjectType instead of graphene.ObjectType.
Changed to MyInputType(graphene.InputObjectType and it worked like a charm