strawberry-graphql/strawberry-django

Name of the Payload GraphQL type created does not take parent into account

开放

#632 创建于 2024年9月25日

 (1 条评论) (0 个反应) (0 位负责人)Python (152 个派生)auto 404
enhancementhelp wanted

仓库指标

星标
 (496 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

When nesting a mutation, and having the lib handle django errors (handle_django_errors=True), the Payload type created is named using only the direct field name. If another different mutation has the same name elsewhere, it will use the first created one.

Describe the Bug

# settings.py
STRAWBERRY_DJANGO = {
  "MUTATIONS_DEFAULT_HANDLE_ERRORS": True,
}

# schema.py  

import strawberry
import strawberry_django

from .models import Project, Task

@strawberry_django.type(Project)
class ProjectType:
    id: strawberry.auto
    name: strawberry.auto

@strawberry_django.type(Task)
class TaskType:
    id: strawberry.auto
    name: strawberry.auto
    project: ProjectType

@strawberry_django.input(Project)
class ProjectInputType:
    id: strawberry.auto
    name: strawberry.auto

@strawberry_django.input(Task)
class TaskInputType:
    id: strawberry.auto
    name: strawberry.auto
    project: ProjectType

@strawberry.type
class ProjectMutation:
    create: ProjectType = strawberry_django.mutations.create(ProjectInputType)


@strawberry.type
class TaskMutation:
    create: TaskType = strawberry_django.mutations.create(TaskInputType)

@strawberry.type
class Mutation:

    @strawberry.field
    def project(self) -> ProjectMutation:
        return ProjectMutation()

    @strawberry.field
    def task(self) -> TaskMutation:
        return TaskMutation()


schema = strawberry.Schema(
    query=Query,
    mutation=Mutation,
    extensions=[DjangoOptimizerExtension],
)

Both project.create and task.create mutations return a CreatePayload. Since the project mutation is the first created, the payload contain ProjectType.

System Information

  • Operating system:
  • Strawberry version: 0.242.0
  • Strawberry django version: 0.48.0

贡献者指南