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

Mutation filters not working #317

Open
jaydensmith opened this issue Jul 20, 2023 · 5 comments
Open

Mutation filters not working #317

jaydensmith opened this issue Jul 20, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@jaydensmith
Copy link
Contributor

jaydensmith commented Jul 20, 2023

When specifying a mutation filter as per the docs, the filter does not appear in the generated schema:

@strawberry.type
class Mutation:
    updateFruits: List[Fruit] = mutations.update(FruitPartialInput, filters=FruitFilter)
    deleteFruits: List[Fruit] = mutations.delete(filters=FruitFilter)
  • Operating system:
  • Strawberry version (if applicable): 0.195.2

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@jaydensmith jaydensmith added the bug Something isn't working label Jul 20, 2023
@bellini666
Copy link
Contributor

Hey @jaydensmith ,

I just tested here and it worked correctly.

Do you have a minimal reproduction example for this?

@jaydensmith
Copy link
Contributor Author

jaydensmith commented Jul 23, 2023

@bellini666 it took a lot of digging around. You must enable the following new MUTATIONS_DEFAULT_HANDLE_ERRORS setting:

STRAWBERRY_DJANGO = {
    'MUTATIONS_DEFAULT_HANDLE_ERRORS': True
}

This causes the return type to be a StrawberryUnion type, not a StrawberryList. So the following returns false.

https://github.com/strawberry-graphql/strawberry-graphql-django/blob/4bc135853cfa7965d286a11e2fc1782d69669894/strawberry_django/fields/base.py#L117-L123

@bellini666
Copy link
Contributor

Hey @jaydensmith ,

Oh, I see. In that case, does that actually work? Because AFAIK you can't create a union between a list and a type on graphql.

@jaydensmith
Copy link
Contributor Author

@bellini666 aside from not being able to filter the mutation so it affects all items, it does raise an exception:

Traceback (most recent call last):
  File "/Users/jaydensmith/public_html/test/.virtualenv/lib/python3.10/site-packages/graphql/execution/execute.py", line 527, in await_result
    completed = self.complete_value(
  File "/Users/jaydensmith/public_html/test/.virtualenv/lib/python3.10/site-packages/graphql/execution/execute.py", line 612, in complete_value
    completed = self.complete_value(
  File "/Users/jaydensmith/public_html/test/.virtualenv/lib/python3.10/site-packages/graphql/execution/execute.py", line 644, in complete_value
    return self.complete_abstract_value(
  File "/Users/jaydensmith/public_html/test/.virtualenv/lib/python3.10/site-packages/graphql/execution/execute.py", line 796, in complete_abstract_value
    runtime_type = resolve_type_fn(result, info, return_type)  # type: ignore
  File "/Users/jaydensmith/public_html/test/.virtualenv/lib/python3.10/site-packages/strawberry/union.py", line 188, in _resolve_union_type
    raise WrongReturnTypeForUnion(info.field_name, str(type(root)))
strawberry.exceptions.WrongReturnTypeForUnion: The type "<class 'list'>" cannot be resolved for the field "updateInventoryItems" , are you using a strawberry.field?

@bellini666
Copy link
Contributor

@jaydensmith indeed that will not work because of the reason I said above.

I'll try to improve that error message to be more meaningful. But basically MUTATIONS_DEFAULT_HANDLE_ERRORS is not compatible with CUD mutations using filters because of that reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants