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

When mutation takes a list as an argument - passing in a list of the type does not work #53

Closed
kshehadeh opened this issue Jul 18, 2019 · 6 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@kshehadeh
Copy link

I have an input type that takes a list as an argument. I haven't seen an example of this use case so I just guessed that I could pass in a python list of the right type. But I get the following error:

AttributeError: 'MyInput' object has no attribute 'items'

And, in fact, it is expecting a dict. Here's an edited version of the code I use to run the mutation:

list_arg = [
    gql.MyInput({"key1":"val1"})
    gql.MyInput({"key1":"val2"})
]

op.my_mutation(my_list=list_arg)

I'm assuming that passing a simple list into the argument is not the right way to go about it, but I'm not sure how to construct the list otherwise.

Thoughts?

@barbieri barbieri self-assigned this Jul 18, 2019
@barbieri barbieri added the enhancement New feature or request label Jul 18, 2019
@barbieri
Copy link
Member

I think this suffers from the same problem as #42. I never gave input arguments the deserved love.

I'm under a heavy work load, I'll try to address this once I look at #42.

If you have some time to help, patches are more than welcome!

@barbieri barbieri added the good first issue Good for newcomers label Jul 18, 2019
@kshehadeh
Copy link
Author

Great! I just wanted to make sure I wasn't doing something wrong. I'll see about if I can address.

@barbieri
Copy link
Member

Passing explicit input objects should work, but seems it is not working as expected to create them. However it would be super-handy to allow plain Python objects to be used -- after all the GraphQL input types are as simple and we could convert easily.

So I'd suggest:

  • check the input object constructor. Unlike the output types, you're not receiving a JSON dict from the server... the developer/user is typing them, thus using **kwargs would make sense, allowing gql.MyInput(key1="val1") in your case.
  • get the argument type and with it auto-convert from plain python types -- so {"key1":"val1"} would result in gql.MyInput(**{"key1":"val1"}).
  • do it recursively, so lists and nested objects works.

@barbieri
Copy link
Member

could you confirm b1c740c fixed it?

@barbieri
Copy link
Member

barbieri commented Sep 9, 2019

note: https://github.com/profusion/sgqlc/releases/tag/v8.0 and uploaded to pypi!

it should include this fix, let me know if solves this issue

@kshehadeh
Copy link
Author

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants