-
Notifications
You must be signed in to change notification settings - Fork 341
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
Is it possible to set custom scalars for specific class properties of the same type? #226
Comments
Yes it is! We have an example of doing this same validation by using a So here you could create a custom |
One thing to keep in mind though that if you do create custom scalars all your clients will also need to know how to properly serialize/deserialize those objects. Another approach is to add some validations on the server that will return validation error to the user. |
@smyrick thanks for your reply, I took this possibility in account but this will mess up some logic that is already implemented... I am just curious if this could be done without any additional classes for such custom scalars |
Custom scalars need to be defined in their own classes/types - without it how would you distinguish between a regular You could always do some validations on the server manually and return |
@dkuc84 I am making use of validations already and it works, thanks. I was thinking of an implementation like it's done with @GraphQLID annotation. |
Even if you were to create a custom annotation that would convert your |
Let's say we have this class as an example:
data class Salary( val employer: Employer? = null, val amount: Int? = null, val month: Int? = null, )
When defining .graphql files for this type it is also possible to use Scalars for month and amount. In my case there is a Scalar used for amount that validates that value is a positive one and for month there is a Scalar that allows only values from 1 to 12.
By setting scalars in this way we can see in the schema the exact type used for this fields and also the description for each scalars.
In
CustomSchemaGeneratorHooks
we can define scalars only by type and I can't see any solution by using it for my purpose.Is there any other solution for this?
If there is not any solution at the moment would it be possible to implement such a feature?
The text was updated successfully, but these errors were encountered: