strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
404 stars 117 forks source link

Feature request: Support for Django form validation #23

Open holtergram opened 3 years ago

holtergram commented 3 years ago

Hey, is there any possibility to add some support for the Django form validation by also returning the field parameters via GraphQL? What I was thinking of is something like this which takes whatever is defined in the model and passes it to the frontend so that I'd be possible to create some auto-validation based on the backend.

User {
  "firstname": {
    "value": "James",
    "validation": {
      "type": "String",
      "max_length": 30
    }
  }
}

Upvote & Fund

Fund with Polar

la4de commented 3 years ago

We do not support Django forms yet. That's very interesting idea. One option would be to provide validation information as a separate object.

We are currently designing the API and stablizing it but Django forms are definitely something we want to think about seriously in the near future.

Thanks for your feedback!

joeydebreuk commented 3 years ago

Correct me if I'm wrong, but this has little to do with Django Forms? I think what you are looking for is adding meta information to a type that includes a validation schema. I think this would be based on models, not on forms?

holtergram commented 3 years ago

Correct me if I'm wrong, but this has little to do with Django Forms? I think what you are looking for is adding meta information to a type that includes a validation schema. I think this would be based on models, not on forms?

Yes, you're right. I should've been more clear. What I mean is to expose the model parameters / meta information to the frontend. On top of this I think a CSRF token validation would come in handy.