strawberry-graphql/strawberry-django

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

Aperta

#632 aperta il 25 set 2024

 (1 commento) (0 reazioni) (0 assegnatari)Python (152 fork)auto 404
enhancementhelp wanted

Metriche repository

Star
 (496 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor