Comments (6)
Yes it is! We have an example of doing this same validation by using a URL
type from Java which is converted to a GraphQL String
. https://github.com/ExpediaDotCom/graphql-kotlin/wiki/Scalars#custom-scalars
So here you could create a custom data class Month(val value: Int)
and have the validation in the constructor or in the coercing code
from graphql-kotlin.
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.
from graphql-kotlin.
So here you could create a custom
data class Month(val value: Int)
and have the validation in the constructor or in the coercing code
@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
from graphql-kotlin.
Custom scalars need to be defined in their own classes/types - without it how would you distinguish between a regular Int
and "restricted" Int
value for your custom scalar?
You could always do some validations on the server manually and return GraphQLError
if input is invalid. Another alternative is to use GraphQL Directives to customize the behavior.
from graphql-kotlin.
@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.
from graphql-kotlin.
@GraphQLID
converts the field to a GraphQL ID scalar type which is a built-in type. It has a special meaning (see the docs) but it doesn't perform any validation of the fields.
Even if you were to create a custom annotation that would convert your Int
input to a custom scalar it would still be exposed in your GraphQL schema as a custom scalar type.
from graphql-kotlin.
Related Issues (20)
- Deadlock when using subscriptions with two Ktor worker threads HOT 4
- GraphQLIgnore annotation not respected when running GraalVM native image
- Spring Boot 3.1.6 health endpoint latency is very high when other query is running. HOT 10
- Unable to perform upgrade as it is not requested by the client: request should have Upgrade and Connection headers filled properly HOT 1
- [ktor server] Ability to specify custom GraphQL server
- GraphQL client gradle plugin fails to find `compileDebugKotlin` task.
- Make `src/main/resources` configurable for GraphQL clients HOT 1
- Spring WebFlux: How to autowire a service/component in a CustomDirective behavior?
- ControllerAdvice and ModelAttribute
- [generator] support directives using input object args
- GraphQL Ktor plugin swallows context exceptions. HOT 3
- Ktor: Flow/Subscription websocket stops working (Ping Timeout)
- Why do I get this error when I start the application HOT 2
- No code generation occurs, no logs explaining why HOT 9
- feat: allow classes corresponding to SDL to be decoupled from implementation
- Unable to retrieve federated types with apollo federation v1 HOT 1
- Add plugin configuration option to allow generating test client files into testFixtures sources root
- @ShareableDirective causes schema generation error when applied to class used as both input and output
- FederatedSchemaValidator rejects nested union type field set HOT 1
- Union Annotations Do Not Play Well with @GraphQLDescription and @Deprecated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-kotlin.