web-ridge / gqlgen-sqlboiler

This is a plugin for gqlgen to generate converts + filter queries and resolvers for sqlboiler
MIT License
74 stars 13 forks source link

How to do validation? #47

Open frederikhors opened 3 years ago

frederikhors commented 3 years ago

Since you are fighting my own battles (gqlgen and go) can I ask you how are you dealing with the hot topic of validations?

E.g. from your example:

input ImageCreateInput {
  postId: ID!
  views: Int
  originalUrl: String
}

how to validate that e.g. views is max = 30 or originalUrl != ""?

RichardLindhout commented 3 years ago

I don't have the use case yet of checking the input but if I require something I require it in my database / schema so origanlUrl: String! and non-nullable database field.

We have soon a new release where it will be a lot easier to override converts/resolvers.

For the max=30 you could create your custom resolver. In the later version we will automically detect other resolver in files other than the generated one's and use the version the developer made.

But I think we need a better validation hook or something, I will make it if I have a use case for it.

For now empty fields checking in database/schema is good enough for me since I make mostly internal apps for companies and do the validation frontend

frederikhors commented 3 years ago

For the max=30 you could create your custom resolver.

Yes, but it's not scalable. What if I need that struct embedded in another?

For now empty fields checking in database/schema is good enough for me

Yep, but for the case with empty string the user can use empty space, e.g.: " " or "-".

I wanna remove validations from frontend for RAD (rapid application development) and generate as much as possible on the server side.

RichardLindhout commented 3 years ago

I agree I think we need something for this maybe schema input validations and a resolver validation or a function like

ValidateCreateUserInput(input *graphql.models.User, resolverName string) []graphql.Error {}

Which you can override or something.

But I don't have time for this yet, maybe in the future or if you make a PR for this

RichardLindhout commented 3 years ago

It will be on my list, but after a better customization story and multiple graphql files and multiple resolvers