Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions thegraph-proxy/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
THEGRAPH_GATEWAY_DOMAIN="gateway.thegraph.com"
THEGRAPH_API_KEY=
39 changes: 39 additions & 0 deletions thegraph-proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# TheGraph Proxy

> ⚠️ Use this component for development purpose only

Proxy server component relaying the calls to the decentralized thegraph network

## Usage

### prepare the `.env` file

```sh
cp .env.template .env
```

fill in `THEGRAPH_API_KEY` in the generated [.env](.env)

### launch the **thegraph-proxy** service

```sh
docker compose up -d
```

The service is available at <http://localhost:8080>

### use the service to query a subgraph

example

```js
curl --request POST \
--url http://localhost:8080/subgraphs/id/2GCj8gzLCihsiEDq8cYvC5nUgK6VfwZ6hm3Wj8A3kcxz \
--data '{"query":"query {\n\t_meta {\n\t\tdeployment\n\t\thasIndexingErrors\n\t\tblock {\n\t\t\tnumber\n\t\t}\n\t}\n}\n"}'
```

### stop the service

```sh
docker compose down
```
12 changes: 12 additions & 0 deletions thegraph-proxy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
thegraph-proxy:
image: thegraph-proxy
build:
context: ./docker
dockerfile: Dockerfile
restart: unless-stopped
ports:
- '8080:80'
environment:
THEGRAPH_GATEWAY_DOMAIN: ${THEGRAPH_GATEWAY_DOMAIN}
THEGRAPH_API_KEY: ${THEGRAPH_API_KEY}
11 changes: 11 additions & 0 deletions thegraph-proxy/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM nginx:alpine

# Install envsubst (part of gettext)
RUN apk add --no-cache gettext

# Copy config template and entrypoint script
COPY default.conf.template /etc/nginx/templates/default.conf.template
COPY entrypoint.sh /docker-entrypoint.d/entrypoint.sh

# Make sure entrypoint is executable
RUN chmod +x /docker-entrypoint.d/entrypoint.sh
13 changes: 13 additions & 0 deletions thegraph-proxy/docker/default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server {
listen 80;

location / {
proxy_pass https://${THEGRAPH_GATEWAY_DOMAIN}/api/${THEGRAPH_API_KEY}/;

proxy_ssl_server_name on;

proxy_set_header Host ${THEGRAPH_GATEWAY_DOMAIN};
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
7 changes: 7 additions & 0 deletions thegraph-proxy/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Replace env vars in template and save to nginx config dir
envsubst '$THEGRAPH_GATEWAY_DOMAIN $THEGRAPH_API_KEY' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf

# Start nginx (inherited from base image entrypoint)
exec "$@"