strawberry-graphql/strawberry-django

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

Aberta

#632 aberto em 25 de set. de 2024

 (1 comentário) (0 reação) (0 responsável)Python (152 forks)auto 404
enhancementhelp wanted

Métricas do repositório

Stars
 (496 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

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

Guia do colaborador