GraphQL scalars and their input and result coercion

David Mráz
Atheros
Published in
7 min readOct 20, 2017

--

This article is also available at https://atheros.ai/blog/graphql-scalars-and-their-input-and-result-coercion without a paywall.

Introduction

When designing GraphQL schema we have to define the so-called primitive values of each query. In GraphQL the primitive values are represented by scalars and enums. The GraphQL specification has different built-in scalars. In this first part of this series, we will concentrate only on the built-in scalars. To demonstrate real applications of the built-in scalars we will apply them in a modelling query for retrieving tasks from the existing “in-memory” database and also for adding new tasks to a database. All examples are implemented in the repository.

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

You should be now able to access GraphQL Playground.

In GraphQL we deal with 8 different types:

--

--

David Mráz
Atheros

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