This plugin for Hasura DDN (Distributed Data Network) allows you to add RESTified GraphQL endpoints to the DDN supergraph. It transforms GraphQL queries into REST-like endpoints, making it easier to integrate with systems that prefer REST APIs.
Documentation can be found here.
If you want to quickly get started with the plugin in a Hasura DDN project, check out the quickstart guide.
- Transform GraphQL queries into REST-like endpoints
- Configurable endpoint mapping
- Authentication support
- Variable extraction from URL parameters, query strings, and request body
- OpenTelemetry integration for tracing
- The plugin starts a server that listens for incoming requests.
- When a request is received, it checks if it matches any configured RESTified endpoints.
- If a match is found, the plugin:
- Extracts variables from the request (URL parameters, query string, body)
- Executes the corresponding GraphQL query with the extracted variables
- Returns the GraphQL response as a REST-style JSON response
Create a configuration file and run it with docker:
docker run -v ./configuration.json:/config/configuration.json \
-e HASURA_DDN_PLUGIN_CONFIG_PATH=/config \
-e GRAPHQL_SERVER_URL=http://engine:3000/graphql \
-e HASURA_M_AUTH=randomsecret \
ghcr.io/hasura/engine-plugin-restified-endpoint:latest
services:
plugin:
image: ghcr.io/hasura/engine-plugin-restified-endpoint:latest
ports:
- 8787:8787
environment:
HASURA_DDN_PLUGIN_CONFIG_PATH: "/config"
GRAPHQL_SERVER_URL: "http://engine:3280/graphql"
HASURA_M_AUTH: <api-key for hasura-m-auth header>
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://local.hasura.dev:4317}
volumes:
- type: bind
source: ./config/plugin/
target: /config/
read_only: trueAWS Lambda requires us to upload the source code. So you need to clone this repo and edit codes directly.
-
Edit configuration at
src/config.ts. -
Edit the GraphQL endpoint at
src/lambda.ts. -
Build the code and dependencies for Lambda manifests.
-
Linux / MacOS
npm run build:lambda
-
Windows
- Run
npm run build. - Copy
package.lambda.jsontodist/package.lambda.json. - Go to
distfolder and install packagesnpm install.
- Run
-
-
Install AWS CDK
npm install -g aws-cdk. -
Login or export environment variables of AWS account.
-
Edit the desired region config in
bin/serverless-aws.ts. -
Run bootstrap for the first deployment.
cdk synth
cdk bootstrap- Deploy the stack.
cdk deployFor cloud deployment, you can use the following steps in addition to the local development steps:
-
Create an account on Cloudflare.
-
Login to Cloudflare:
wrangler login
-
Deploy to Cloudflare:
npm run deploy
The above command should deploy the RESTified endpoints plugin (as a lambda) using Cloudflare workers. The URL of the deployed plugin will be displayed in the terminal.
To run the plugin locally using Express, you can use the following steps:
-
Install dependencies:
npm install
-
Build the project:
npm run build
-
Export the environment variables:
export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318/v1/traces" export OTEL_EXPORTER_PAT="your-pat-here" export GRAPHQL_SERVER_URL="http://localhost:3280/graphql" export HASURA_DDN_PLUGIN_CONFIG_PATH="../tests/config/plugin"
-
Start the server:
npm run serve
The above command will start a local server that listens for incoming requests. The server runs on port 8787 by default.
Note: You can also use npm run serve-dev to start the server in development mode, which will automatically restart
the server when changes are made to the code.
This plugin can be developed and deployed using Cloudflare wrangler.
Configure the graphql server URL in .dev.vars:
[vars]
GRAPHQL_SERVER_URL = "<GRAPHQL_SERVER_URL>"To run the plugin locally, you can use the following steps:
-
Install wrangler:
npm install -g wrangler
-
Clone this repository:
git clone https://github.com/your-org/engine-plugin-restified-endpoint.git cd engine-plugin-restified-endpoint -
Install dependencies:
npm install
-
Start the local development server:
npm start
The above command will start a local server that listens for incoming requests. The server runs on port 8787 by default. The URL of the local server will be displayed in the terminal.
To run the tests, use the following commands:
-
Start the services required for testing:
docker compose -f tests/docker-compose.yaml up
-
Run the tests:
npm test
- Currently, the plugin supports basic variable extraction. More complex scenarios might require additional implementation.
- OpenAPI Spec documentation generation is not yet implemented.
- Rate limiting is not currently supported within the plugin.
Contributions are welcome! Please feel free to submit a Pull Request.