strawberry-graphql/strawberry-django
View on GitHubName of the Payload GraphQL type created does not take parent into account
Open
#632 opened on Sep 25, 2024
enhancementhelp wanted
Repository metrics
- Stars
- (496 stars)
- PR merge metrics
- (PR metrics pending)
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