strawberry-graphql/strawberry-django

Query & Mutation in namespaces

Ouverte

#627 ouverte le 13 sept. 2024

 (6 commentaires) (2 réactions) (0 personne assignée)Python (152 forks)auto 404
enhancementhelp wantedproposal

Métriques du dépôt

Stars
 (496 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

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

Guide contributeur