How to use GraphQL enum and its best practices
This article is also available at https://atheros.ai/blog/how-to-use-graphql-enum-type-and-its-best-practices without the paywall.
Introduction
We will continue with the same repository as in the previous article on GraphQL scalars. You can clone the GitHub repository using this command
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 this part, we will go through the fields that use Enum fields in our previously defined schema. If you are new to GraphQL, it might also be helpful to check out our previous articles on built-in scalars as well as the one on input object type. We use them as prerequisites for this article in terms of understanding GraphQL, and we will also use parts of the code that we built in previous articles. In the following image, we illustrate the hierarchical tree graph of the response for our queries and mutations.
Enum Types
Enums are basically a special type we can use to enumerate all possible values in the field…