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

Query & Mutation in namespaces #627

Open
axieum opened this issue Sep 13, 2024 · 5 comments
Open

Query & Mutation in namespaces #627

axieum opened this issue Sep 13, 2024 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed proposal Proposal

Comments

@axieum
Copy link

axieum commented Sep 13, 2024

Describe the Bug

As per the documentation, https://strawberry.rocks/docs/general/mutations#nested-mutations

@strawberry.type
class Query:
    @strawberry.field(description="Query fruits")
    def fruits(self) -> FruitQuery:
        return FruitQuery()

@strawberry.type
class Mutation:
    @strawberry.field(description="Mutate fruits")
    def fruits(self) -> FruitMutation:
        return FruitMutation()

Raises FruitMutation.__init__() missing 3 required keyword-only arguments: 'create', 'update', and 'delete'

I also tried the following variant to no avail.

@strawberry.type
class Query:
    fruits: FruitQuery= strawberry.field(resolver=FruitQuery, description="Query fruits")

@strawberry.type
class Mutation:
    fruits: FruitMutation = strawberry.field(resolver=FruitMutation, description="Mutate fruits")

Raises Query fields cannot be resolved


The only thing that appears to be correct, is the GraphiQL schema, in all scenarios it is correct - but that would be due to the type hinting I assume.


This works:

from . import models
from .types import Fruit

@strawberry.type
class FruitQuery:
    @strawberry_django.connection(ListConnectionWithTotalCount[Fruit])
    def all(self) -> list[models.Fruit]:
        return models.Fruit.objects.all()

This does not work:

@strawberry.type
class FruitQuery:
    all: ListConnectionWithTotalCount[Fruit] = strawberry_django.connection()

Query fields cannot be resolved. Argument type must be a GraphQL input type.

System Information

  • Operating system:
  • Strawberry version (if applicable): 0.47.2

Additional Context

Here is a reproduction repo: https://github.com/axieum/django-strawberry-example

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
@axieum axieum added the bug Something isn't working label Sep 13, 2024
@bellini666
Copy link
Member

Hi @axieum ,

What is the use case for those namespaces? TBH I have seen someone mentioning something similar, but never saw that anywhere.

Also, is that a strawberry-django issue or a general strawberry issue?

@axieum
Copy link
Author

axieum commented Sep 24, 2024

Hi @bellini666 👋

It appears to just affect strawberry-django fields.

I was not able to reproduce when using pure strawberry fields.

There's a reproduction repository linked at the bottom of the issue which shows the strawberry-django namespacing issue.

Thanks,

@fabien-michel
Copy link
Contributor

I've the same issue. A workaround seems to set create, update, delete... to something:

@strawberry.type
class Mutation:

    @strawberry.field(description="Mutate fruits")
    def fruits(self) -> FruitMutation:
        return FruitMutation(create=None, update=None, delete=None)

@axieum
Copy link
Author

axieum commented Sep 27, 2024

I've the same issue. A workaround seems to set create, update, delete... to something:

@strawberry.type
class Mutation:

    @strawberry.field(description="Mutate fruits")
    def fruits(self) -> FruitMutation:
        return FruitMutation(create=None, update=None, delete=None)

This looks to work for mutations 😄, but I can't get it to work for a query.

@strawberry.field(description="Query fruits")
def fruits(self) -> FruitQuery:
    return FruitQuery(all=None)

It raises a 'NoneType' object has no attribute 'all' suggesting that fruits is null. Did you have any luck with nesting queries?

@axieum
Copy link
Author

axieum commented Sep 27, 2024

Update; this works for nested queries.

@strawberry.field(description="Query fruits")
def fruits(self) -> FruitQuery:
    return FruitQuery(all=Fruit.__strawberry_django_definition__.model.objects)

I am unsure of the implications of providing a queryset here.

And this for nested mutations.

@strawberry.field(description="Mutate fruits")
def fruits(self) -> FruitMutation:
    return FruitMutation(create=None, update=None, delete=None)

Related to #580 (comment)

@bellini666 bellini666 added enhancement New feature or request help wanted Extra attention is needed proposal Proposal and removed bug Something isn't working labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed proposal Proposal
Projects
None yet
Development

No branches or pull requests

3 participants