Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to pass an array of inputs to a relay.clientIDMutation? #1232

Open
samarthkathal opened this issue Jul 17, 2020 · 3 comments
Open

Comments

@samarthkathal
Copy link

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
      }
    }
  }
}
@jkimbo
Copy link
Member

jkimbo commented Jul 20, 2020

@samarthkathal it should be possible to define an input type of List(MyInputType) to a mutation. Does that not work?

@Icebreaker454
Copy link

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.

@Icebreaker454
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants