GraphQL Services using Node and Apollo

I have prepared 2 repos to implement FakeBank using GraphQL:

1. JavaScript: https://github.com/muratyaman/fakebank-js

2. TypeScript: https://github.com/muratyaman/fakebank-ts

Architecture can be like this:

FakeBank uses:

* GraphQL
https://graphql.org/
– “GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.”

* GraphQL-JS
https://github.com/graphql/graphql-js
– “A reference implementation of GraphQL for JavaScript”

* Apollo Server
https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server
– “Apollo Server is an open-source, spec-compliant GraphQL server that’s compatible with any GraphQL client”

* Apollo Federation
https://github.com/apollographql/apollo-server/tree/master/packages/apollo-federation
– “… expose a single data graph that provides a unified interface for querying all of your backing data sources”

* Apollo REST Data Source
https://github.com/apollographql/apollo-server/tree/master/packages/apollo-datasource-rest
– “This package exports a (RESTDataSource) class which is used for fetching data from a REST API and exposing it via GraphQL within Apollo Server.”

* Apollo Gateway
https://github.com/apollographql/apollo-server/tree/master/packages/apollo-gateway
– sits above other GraphQL services

* GraphQL DataLoader
https://github.com/graphql/dataloader
– “DataLoader is a generic utility to be used as part of your application’s data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching.”
– improves performance of GraphQL service

* Express
https://github.com/expressjs/express/
– “Fast, unopinionated, minimalist web framework for node”
– helps create an HTTP service quickly

* Faker
https://github.com/marak/Faker.js/
– “generate massive amounts of realistic fake data in Node.js and the browser”
– helps create random/mock data

* Lerna
https://github.com/lerna/lerna
– “A tool for managing JavaScript projects with multiple packages.”

## List of core REST services

* rest-auth
– http://localhost:10111
– manages login actions, user records

* rest-accounts
– http://localhost:10222
– manages bank accounts and transactions

* rest-payments
– http://localhost:10333
– manages money transfers

## List of GraphQL services using Core REST services

* gql-fed-auth
– http://localhost:20111
– uses rest-auth

* gql-fed-accounts
– http://localhost:20222
– uses rest-accounts

* gql-fed-payments
– http://localhost:20333
– uses rest-payments

## Standard GraphQL service using Core REST services

* gql-standard
– http://localhost:30111
– uses rest-auth
– uses rest-accounts
– uses rest-payments

## GraphQL Gateway service

* gql-gateway
– http://localhost:40111
– uses gql-fed-auth
– uses gql-fed-accounts
– uses gql-fed-payments

## Sequence diagrams

To see the diagrams, use https://sequencediagram.org/

### A. GraphQL Standard

### B. GraphQL Gateway

## Installation

Install yarn and lerna globally

Install dependencies for all packages in this codebase.

## Build

## Start in production mode

Run these in separate terminals in this order:

## Core REST services

Random/fake data is generated at runtime

## GraphQL Services

These services are used by GraphQL Gateway

## Standard GrapQL service

We can use RESTful services directly

Note: Another way to run a service:

On the next post, I will discuss the details of GraphQL federation: Federation of GraphQL Services using Apollo Gateway

Author: murat