GraphQL Scalars 1.0 is out! More Types, Data Integrity and Strict Validations on GraphQL
The GraphQL Specification has the
ID Scalar types by default. Those scalar types help you identify the data and validate it before transferring it between client and server. But you might need more specific scalars for your GraphQL application, to help you better describe and validate your app’s data.
Validation using Scalars
For example, you have a
String field but you need to validate upcoming or ongoing string data using regular expressions. So you should have this validation on each end; one in the client, the other one in the server and maybe there is another on a source. Instead of duplicating the same logic in different parts of the project, you can use
EmailAddress scalar type that does the validation inside GraphQL for you.
Serialization and Parsing
The other benefit of using GraphQL scalar types is parsing and serializing while transferring data. For example, you have
DateTime data but it is transferred as
Date instance while also serializing it to string before passing it to the client. Instead of having that logic in your implementation, you can just use
Date instances directly like it is one of primitive types such as string, number and boolean.
Since then we completely rewrote the library using TypeScript, upgraded all dependencies, closed all the issues and PRs and increased the number of scalars in the package with new scalars like:
JSON and more. You can see all scalars in the README.
Apollo Server provides mocks built-in scalars such as
Boolean . What if you need same thing for our scalars? So, we provide you mocking functions for each scalar in this package. You can add those easily in your server for mocking the schema.
Thanks to OK-Grow for creating this package, adriano-di-giovanni for being generous and giving us the
graphql-scalars name on npm, to Saeris for letting us to take other scalar implementations from his fork, stems for their
graphql-bigint package, abhiaiyer91 for his
graphql-currency-scalars package and taion for his