strawberry-graphql/strawberry-django

Query & Mutation in namespaces

開放

#627 建立於 2024年9月13日

 (6 則留言) (2 個反應) (0 位負責人)Python (152 個分叉)auto 404
enhancementhelp wantedproposal

倉庫指標

星標
 (496 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南