Skip to content

Commit 614a4a1

Browse files
feat(thegraph-proxy): add minimal thegraph proxy server for development (#7)
1 parent 1e3190f commit 614a4a1

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed

thegraph-proxy/.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
THEGRAPH_GATEWAY_DOMAIN="gateway.thegraph.com"
2+
THEGRAPH_API_KEY=

thegraph-proxy/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# TheGraph Proxy
2+
3+
> ⚠️ Use this component for development purpose only
4+
5+
Proxy server component relaying the calls to the decentralized thegraph network
6+
7+
## Usage
8+
9+
### prepare the `.env` file
10+
11+
```sh
12+
cp .env.template .env
13+
```
14+
15+
fill in `THEGRAPH_API_KEY` in the generated [.env](.env)
16+
17+
### launch the **thegraph-proxy** service
18+
19+
```sh
20+
docker compose up -d
21+
```
22+
23+
The service is available at <http://localhost:8080>
24+
25+
### use the service to query a subgraph
26+
27+
example
28+
29+
```js
30+
curl --request POST \
31+
--url http://localhost:8080/subgraphs/id/2GCj8gzLCihsiEDq8cYvC5nUgK6VfwZ6hm3Wj8A3kcxz \
32+
--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"}'
33+
```
34+
35+
### stop the service
36+
37+
```sh
38+
docker compose down
39+
```

thegraph-proxy/docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
thegraph-proxy:
3+
image: thegraph-proxy
4+
build:
5+
context: ./docker
6+
dockerfile: Dockerfile
7+
restart: unless-stopped
8+
ports:
9+
- '8080:80'
10+
environment:
11+
THEGRAPH_GATEWAY_DOMAIN: ${THEGRAPH_GATEWAY_DOMAIN}
12+
THEGRAPH_API_KEY: ${THEGRAPH_API_KEY}

thegraph-proxy/docker/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM nginx:alpine
2+
3+
# Install envsubst (part of gettext)
4+
RUN apk add --no-cache gettext
5+
6+
# Copy config template and entrypoint script
7+
COPY default.conf.template /etc/nginx/templates/default.conf.template
8+
COPY entrypoint.sh /docker-entrypoint.d/entrypoint.sh
9+
10+
# Make sure entrypoint is executable
11+
RUN chmod +x /docker-entrypoint.d/entrypoint.sh
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
server {
2+
listen 80;
3+
4+
location / {
5+
proxy_pass https://${THEGRAPH_GATEWAY_DOMAIN}/api/${THEGRAPH_API_KEY}/;
6+
7+
proxy_ssl_server_name on;
8+
9+
proxy_set_header Host ${THEGRAPH_GATEWAY_DOMAIN};
10+
proxy_set_header X-Real-IP $remote_addr;
11+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
12+
}
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Replace env vars in template and save to nginx config dir
4+
envsubst '$THEGRAPH_GATEWAY_DOMAIN $THEGRAPH_API_KEY' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf
5+
6+
# Start nginx (inherited from base image entrypoint)
7+
exec "$@"

0 commit comments

Comments
 (0)