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.
# 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.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too