simple graphql with scala.js, zio and apollo-server-express
WIP - please ignore this blog until its done or check back periodically for new content.
REST is a bit on its way out, if its not out already. Graphql has been where the action has been at for a few years now. graphql is relatively easy to use and significantly more express than say, odata. It’s relatively straight forward to create a simple graphql server that uses a RDBMS behind the scenes. If you use the express version of the apollo server library you can get instant reload, solid debugging and other features that makes it easy to use and adopt. While express is not multi-threaded, it may be good enough as a solution.
There are quite a few graphql libaries:
- apollo-graphql-express: From community and a backing company.
- graphql-express: From FB + Relay.
- graphql-yoga: Dev friendly, fast starter graphql database.
- sangria: scala
- calahan: scala + zio (newer)
- …endless list by language…
We will use apollo-graphql-express which easily allows you to use other “express” middleware and features to create a graphql server. graphql can be served over grpc or http or grpc over http or protobuf, etc. It is transport agnostic. We will focus on graphql over http. All of the libraries have varying degrees of “extensions”. For example, the Relay related graphql server has specific support for Relay-required graphql features to support pagination. Since we will also show how to consume a graphql source, we will show graphql with scala.js and react hooks–the best way to use graphql in react.
For this blog, we will use zio for the effects in our resolvers.
apollo setup and resolvers