A GraphQL scalar is a query leaf node that cannot be queried further via sub field selections. The graphql specification states that five standard scalars must always be present on the type system, these are: String, Int, Float, Boolean and ID.
It is very common that the standard five scalars are not descriptive enough. For example, how do we return a Date or DateTime? As a string? This is where we can create our own custom scalar implementations to define a more specific data type.
Here, I introduce the java graphql extended scalars dependency (graphql-java-extended-scalars) which contains many out-of-the-box scalars for Date, DateTime, PositiveInt, NonNegativeInt and many many more. You can additionally create your own by creating an implementation of GraphQLScalarType and following the patterns from the extended scalars.
I just love the Numeric scalars:
PositiveInt
An Int scalar that MUST be greater than zero.
NegativeInt
An Int scalar that MUST be less than zero.
NonPositiveInt
An Int scalar that MUST be less than or equal to zero.
NonNegativeInt
An Int scalar that MUST be greater than or equal to zero.
PositiveFloat
An Float scalar that MUST be greater than zero.
NegativeFloat
An Float scalar that MUST be less than zero.
NonPositiveFloat
An Float scalar that MUST be less than or equal to zero.
NonNegativeFloat
An Float scalar that MUST be greater than or equal to zero.
See you in the next tutorial where I show graphql Date and DateTime scalars,
Thanks!
Philip
GraphQL open issue for standardizing Date and DateTime scalar: https://github.com/graphql/graphql-sp...
Spring Boot GraphQL: https://github.com/graphql-java-kicks...
Introduction to extended scalars: https://www.graphql-java.com/blog/int...
Java Extended scalars github: https://github.com/graphql-java/graph...