Create a Federated GraphQL API with REST APIs using Hasura GraphQL Engine (HGE)
This repository highlights 2 ways to use the Hasura GraphQL Engine to wrap REST APIs in a GraphQL API:
- Hasura actions
- Hasura remote schemas + OpenAPI-to-GraphQL
The first example uses :
postgres
for the example data and HGE metadatarest-api
for the REST data APIhge-rest-actions
to add part of the REST API into a GraphQL API via Hasura Actions- The metadata will automatically be applied via the mounted volume of the container service
The second example uses :
postgres
for the example data and HGE metadata- Random Data as the REST API
hge-rest-actions
to add part of the REST API into a GraphQL API via Hasura Actionshge-rest-transform-metadata.json
will need to be imported to initialize the metadata docs - please click "Console"- The
User
action illustrates defining a subset of the returned data to limit the scope of the exposed data - The
userSubscription
action illustrates using a response transform
This example uses:
postgres
for the example data and HGE metadatarest-api
for the REST data API, which implements the OpenAPI specoa2gql
to wrap the REST API with a GraphQL APIhge-rest-schema
to stitch the sub-graph/remote schema into a GraphQL API- The metadata will automatically be applied via the mounted volume of the container service
- REST API
- GraphQL API via OpenAPI-to-GraphQL
- HGE REST via Actions
- HGE REST via Actions with Response Transform
- HGE REST via Remote Schema
- Clone the repository
cd
into the example repository directorydocker compose up -d
to pull & start all the container defined inocker-compose.yaml
a) Please wait approximately 2-3 minutes for all the services to install, build, start and connect to each other. The services may restart several times if the dependent services are not ready.- Load the Hasura Console in your web browser for each example:
- HGE REST via Actions
- HGE REST via Actions with Response Transform
*Please remember to import the metadata
hge-rest-transform-metadata.json
- HGE REST via Remote Schema
docker compose down
to stop & remove the services, this will persist the PostgreSQL data and enable faster re-starts withdocker compose up -d
. Please usedocker compose down -v
if you would like to remove the PostgreSQL data volumedb_data
.
docker-compose.yaml
- start the example container servicespostgres
- PostgreSQL database for HGE metadata & demo datarest-api
- OpenAPI micro service serving Chinook data from postgres serviceoa2gql
- OpenAPI-to-GraphQL proxy that creates a GraphQL schema for an OpenAPI endpointhge-rest-actions
- HGE example that wraps therest-api
service using HGE actionshge-rest-schema
- HGE example that uses theoa2gql
service as a remote schemahge-rest-transform
- HGE example that wraps the Random Data API service using HGE actions and action response transforms to flatten the response data structure
/init-pg
- SQL files to create thepostgres
database and initialize the example data/hge-metadata/rest-actions
- metadata for thehge-rest-action
service/hge-metadata/rest-actions
- metadata for thehge-rest-action
service/hge-metadata/rest-actions
- metadata for thehge-rest-action
servicehge-rest-transform-metadata.json
- metadata for thehge-rest-transform
service/rest-api
- OpenAPI micro service serving Chinook data from postgres service