strawberry-graphql/strawberry-django

Query & Mutation in namespaces

Offen

#627 geöffnet am 13.09.2024

 (6 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)Python (152 Forks)auto 404
enhancementhelp wantedproposal

Repository-Metriken

Stars
 (496 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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

Contributor Guide