Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fabien-michel opened this issue Sep 25, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@fabien-michel
Copy link
Contributor

fabien-michel commented Sep 25, 2024

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

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@fabien-michel fabien-michel added the bug Something isn't working label Sep 25, 2024
@fabien-michel fabien-michel changed the title Nome of the Payload GraphQL type created does not take care of parent Name of the Payload GraphQL type created does not take care of parent Sep 25, 2024
@fabien-michel fabien-michel changed the title Name of the Payload GraphQL type created does not take care of parent Name of the Payload GraphQL type created does not take parent into account Sep 25, 2024
@bellini666 bellini666 added enhancement New feature or request help wanted Extra attention is needed and removed bug Something isn't working labels Oct 19, 2024
@bellini666
Copy link
Member

This is related to namespacing, a feature which we Strawberry itself doesn't support that well yet.

To properly support this we would need to understand that the type being returned is actually a mutation.

I think it is worth to start a discussion about this on discord about namespacing queries and mutations to see what the other devs and the community thinks about and to try to come with a general solution for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants