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

贡献者指南