How to design GraphQL custom scalars

David Mráz
Atheros
Published in
4 min readNov 14, 2017

--

This article is also available at https://atheros.ai/blog/how-to-design-graphql-custom-scalars without the paywall.

Introduction

In the GraphQL specification, we have different built-in scalar types. We have described them in the dedicated article. But what can we do if we need to use scalars which are not defined in the GraphQL specification? The answer is to use the so-called custom scalar. The implementation of the GraphQL custom scalar can vary based on the language you use for building GraphQL server. In some of these implementations, it may not be even possible to use custom scalars. In our case, we will on building custom scalar with our official graphql-js library.

We will continue with the same repository as with the enums and built-in scalars. You can clone the GitHub repository using this command

You can quickly start with:

git clone git@github.com:atherosai/graphql-gateway-apollo-express.git

install dependencies with

npm i

and start the server in development with

npm run dev

Custom scalar definition

As mentioned the built-in scalars might not be able to fulfil all the required parsing and…

--

--

David Mráz
Atheros

Founder of https://atheros.ai | Artificial Intelligence | Machine Learning | JavaScript, Python, C++ | Business