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

feature: provide path to nested field if ValidationError is raised #404

Open
1 of 3 tasks
tokr-bit opened this issue Oct 30, 2023 · 0 comments
Open
1 of 3 tasks

feature: provide path to nested field if ValidationError is raised #404

tokr-bit opened this issue Oct 30, 2023 · 0 comments

Comments

@tokr-bit
Copy link
Contributor

tokr-bit commented Oct 30, 2023

Summary

This is based on the Feature Request in #398.

If a nested object is updated with a value that raises ValidationError, the field name is shown in the OperationInfo is shown that lead tot his error. It might be advantageous to see the actual nested path.

Feature Request Type

  • Core functionality
  • Alteration (enhancement/optimization) of existing feature(s)
  • New behavior

Description

Assume we have a parent with a nested field:

class Parent(models.Model);
   foo_field = models.CharField()

class Child(models.Model):
   url = models.URLField(validators=[validators.validate_url])
   parent_field = models.ForeignKey(to=Parent, related_name="children")

with some types and mutations

@strawberry.type(Child, exclude=["parent_field"])
class Child:
    id: auto
    url: auto

@strawberry.input(Child)
class ChildInput(Child):
   pass

@strawberry.type(Parent)
class Parent:
   id: auto
   foo_field: auto
   children: List[Child]

@strawberry.input(Parent)
class ParentInput(Parent):
   pass

@strawberry.type
class Mutation:
    parent: Parent = mutations.create(types.ParentInput)

Assume the following mutation:

        createParent(data: {
            fooField: "foo"
            children: [
                {
                    url: "unsupportedUrl"
                }
            ]
        }) {
            ... on OperationInfo {
                messages {
                    code
                    kind
                    field
                }
            }
        }
    }

Desired behavior: field should be Parent.children.url.
Actual behavior: field is url

Solution

Currently, we catch ValidationErrors that are raised by django in _get_validation_errors (https://github.com/strawberry-graphql/strawberry-graphql-django/blob/main/strawberry_django/mutations/fields.py#L59). We would need some kind of root parameter that allows us to backtrace this field.

Do you have any suggestions on that?

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant