Skip to content

Commit bfee2ce

Browse files
committed
Added Envio as an option to the query options
1 parent e9b9ea8 commit bfee2ce

File tree

6 files changed

+627
-71
lines changed

6 files changed

+627
-71
lines changed

ENVIO_MIGRATION.md

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
# Envio GraphQL Endpoint Migration Guide
2+
3+
This guide explains how to use the Envio GraphQL endpoint as an alternative to The Graph.
4+
5+
## Quick Start
6+
7+
### Using Envio (Free, No API Key Required)
8+
9+
Set these environment variables:
10+
11+
```bash
12+
GRAPHQL_ENDPOINT_TYPE=envio
13+
ENVIO_ENDPOINT=https://indexer.hyperindex.xyz/1a2f51c/v1/graphql # Optional, this is the default
14+
```
15+
16+
### Using The Graph (Requires API Key)
17+
18+
Set these environment variables:
19+
20+
```bash
21+
GRAPHQL_ENDPOINT_TYPE=thegraph
22+
CURATE_GRAPHQL_API_KEY=your_api_key_here
23+
```
24+
25+
## Key Differences Between Endpoints
26+
27+
| Feature | The Graph | Envio (Hasura) |
28+
|---------|-----------|----------------|
29+
| **Authentication** | Requires API key | Free, no authentication |
30+
| **Entity Name** | `litems` | `LItem` |
31+
| **Pagination** | `first: 1000` | `limit: 1000` |
32+
| **Sorting** | `orderBy: field`<br>`orderDirection: asc` | `order_by: {field: asc}` |
33+
| **Field Names** | `registry` | `registryAddress` |
34+
| **Metadata** | Nested in `metadata {}` | Flat structure (top-level keys) |
35+
| **Equality Filter** | `field: "value"` | `field: {_eq: "value"}` |
36+
| **Greater Than** | `field_gt: N` | `field: {_gt: N}` |
37+
| **Array Match** | `field_in: [A, B]` | `field: {_in: [A, B]}` |
38+
| **Response Path** | `data.litems` | `data.LItem` |
39+
40+
## Query Examples
41+
42+
### The Graph Query Format
43+
44+
```graphql
45+
{
46+
litems(
47+
first: 1000,
48+
orderBy: latestRequestSubmissionTime,
49+
orderDirection: asc,
50+
where: {
51+
registry: "0x957a53a994860be4750810131d9c876b2f52d6e1",
52+
status_in: [Registered],
53+
disputed: false,
54+
metadata_: { key0_in: ["eip155:1:0x..."] }
55+
}
56+
) {
57+
itemID
58+
latestRequestSubmissionTime
59+
metadata {
60+
key0
61+
key1
62+
key2
63+
key3
64+
props {
65+
value
66+
type
67+
label
68+
}
69+
}
70+
}
71+
}
72+
```
73+
74+
### Envio Query Format
75+
76+
```graphql
77+
{
78+
LItem(
79+
limit: 1000,
80+
order_by: {latestRequestSubmissionTime: asc},
81+
where: {
82+
registryAddress: {_eq: "0x957a53a994860be4750810131d9c876b2f52d6e1"},
83+
status: {_eq: "Registered"},
84+
disputed: {_eq: false},
85+
key0: {_in: ["eip155:1:0x..."]}
86+
}
87+
) {
88+
itemID
89+
latestRequestSubmissionTime
90+
key0
91+
key1
92+
key2
93+
key3
94+
props {
95+
value
96+
type
97+
label
98+
}
99+
}
100+
}
101+
```
102+
103+
## Response Structure
104+
105+
### The Graph Response
106+
107+
```json
108+
{
109+
"data": {
110+
"litems": [{
111+
"itemID": "0x...",
112+
"metadata": {
113+
"key0": "eip155:1:0x...",
114+
"key1": "example.com",
115+
"key2": "...",
116+
"props": [...]
117+
}
118+
}]
119+
}
120+
}
121+
```
122+
123+
### Envio Response
124+
125+
```json
126+
{
127+
"data": {
128+
"LItem": [{
129+
"itemID": "0x...",
130+
"key0": "eip155:1:0x...",
131+
"key1": "example.com",
132+
"key2": "...",
133+
"props": [...]
134+
}]
135+
}
136+
}
137+
```
138+
139+
## How the Service Handles Both Endpoints
140+
141+
The service automatically handles the differences between endpoints:
142+
143+
1. **Query Building**: Different query builders generate the appropriate GraphQL syntax for each endpoint
144+
2. **Response Normalization**: Envio responses are normalized to The Graph format internally
145+
3. **Transparent API**: The REST API remains unchanged regardless of which GraphQL endpoint is used
146+
147+
### Internal Architecture
148+
149+
```
150+
User Request
151+
152+
API Controller
153+
154+
AddressTagService
155+
156+
CurateGraphQLClient
157+
├── buildTheGraphQuery() → The Graph endpoint
158+
└── buildEnvioQuery() → Envio endpoint
159+
160+
normalizeEnvioResponse() (if needed)
161+
162+
DataMapper (same for both)
163+
164+
API Response (same format)
165+
```
166+
167+
## Benefits of Envio
168+
169+
1. **No API Key Required**: Free to use without authentication
170+
2. **No Rate Limits**: (Check with Envio for current limits)
171+
3. **Hasura-Powered**: Modern GraphQL engine with advanced filtering
172+
4. **Direct Access**: No gateway layer
173+
174+
## Benefits of The Graph
175+
176+
1. **Established Infrastructure**: Proven reliability and uptime
177+
2. **Decentralized**: Multiple indexer nodes
178+
3. **Industry Standard**: Widely used in Web3
179+
4. **Advanced Features**: Subgraph composition, conditional queries
180+
181+
## Testing Your Configuration
182+
183+
1. Set your environment variables
184+
2. Start the server:
185+
```bash
186+
npm run dev
187+
```
188+
3. Check the startup logs for:
189+
```
190+
Using thegraph endpoint: https://gateway.thegraph.com/...
191+
# or
192+
Using envio endpoint: https://indexer.hyperindex.xyz/...
193+
```
194+
4. Test the API:
195+
```bash
196+
curl -X POST http://localhost:3000/api/address-tags \
197+
-H "Content-Type: application/json" \
198+
-d '{
199+
"chains": ["1"],
200+
"addresses": ["0x1234567890123456789012345678901234567890"]
201+
}'
202+
```
203+
204+
## Troubleshooting
205+
206+
### Error: "CURATE_GRAPHQL_API_KEY environment variable is required"
207+
208+
**Cause**: Using `GRAPHQL_ENDPOINT_TYPE=thegraph` without an API key
209+
210+
**Solution**: Either:
211+
- Add `CURATE_GRAPHQL_API_KEY=your_key` to `.env`
212+
- Switch to Envio: `GRAPHQL_ENDPOINT_TYPE=envio`
213+
214+
### Error: "Invalid GRAPHQL_ENDPOINT_TYPE"
215+
216+
**Cause**: Invalid value for `GRAPHQL_ENDPOINT_TYPE`
217+
218+
**Solution**: Set to either `thegraph` or `envio` (case-insensitive)
219+
220+
### Different Results Between Endpoints
221+
222+
**Cause**: Data sync differences between indexers
223+
224+
**Solution**: This is expected - different indexers may have slight variations in data depending on sync status
225+
226+
## Migration Checklist
227+
228+
- [ ] Decide which endpoint to use (Envio for free, The Graph for established infrastructure)
229+
- [ ] Set `GRAPHQL_ENDPOINT_TYPE` environment variable
230+
- [ ] If using The Graph: Set `CURATE_GRAPHQL_API_KEY`
231+
- [ ] If using Envio: Optionally set `ENVIO_ENDPOINT` (uses default if not set)
232+
- [ ] Rebuild the application: `npm run build`
233+
- [ ] Test the API endpoints
234+
- [ ] Monitor logs for successful queries
235+
- [ ] Update deployment configurations if needed
236+
237+
## Custom Envio Endpoints
238+
239+
If you're running your own Envio indexer or using a different Envio endpoint:
240+
241+
```bash
242+
GRAPHQL_ENDPOINT_TYPE=envio
243+
ENVIO_ENDPOINT=https://your-custom-envio-endpoint.com/v1/graphql
244+
```
245+
246+
The query builder will automatically use the correct Hasura syntax for any Envio endpoint.
247+

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,44 @@ cp env.example .env
124124

125125
4. Configure environment variables in `.env` file as needed.
126126

127+
### Environment Variables
128+
129+
#### GraphQL Endpoint Configuration
130+
131+
The service supports two GraphQL endpoint types: **The Graph** and **Envio**.
132+
133+
**Common Variables:**
134+
- `GRAPHQL_ENDPOINT_TYPE` - Endpoint type to use: `thegraph` or `envio` (default: `thegraph`)
135+
136+
**The Graph (default):**
137+
- `CURATE_GRAPHQL_API_KEY` - Your The Graph API key (required for `thegraph` endpoint)
138+
- Uses endpoint: `https://gateway.thegraph.com/api/{API_KEY}/subgraphs/id/{SUBGRAPH_ID}`
139+
140+
**Envio (alternative):**
141+
- `ENVIO_ENDPOINT` - Envio GraphQL endpoint (optional, defaults to `https://indexer.hyperindex.xyz/1a2f51c/v1/graphql`)
142+
- No API key required - free to use
143+
144+
**Example `.env` configurations:**
145+
146+
Using The Graph (requires API key):
147+
```env
148+
GRAPHQL_ENDPOINT_TYPE=thegraph
149+
CURATE_GRAPHQL_API_KEY=your_api_key_here
150+
```
151+
152+
Using Envio (no API key needed):
153+
```env
154+
GRAPHQL_ENDPOINT_TYPE=envio
155+
ENVIO_ENDPOINT=https://indexer.hyperindex.xyz/1a2f51c/v1/graphql
156+
```
157+
158+
**Other Variables:**
159+
- `PORT` - Server port (default: 3000)
160+
- `LOG_LEVEL` - Log level: debug, info, warn, error (default: debug)
161+
- `LOG_FILE` - Log file path (default: stdout)
162+
- `NODE_ENV` - Environment: development, production (default: development)
163+
- `ALLOWED_ORIGINS` - Comma-separated list of allowed CORS origins (default: *)
164+
127165
### Development
128166

129167
Start the development server:
@@ -219,11 +257,24 @@ The service integrates with three Kleros Curate registries:
219257

220258
### GraphQL Integration
221259

222-
The service uses GraphQL to query the Kleros Curate subgraph:
260+
The service supports two GraphQL endpoints for querying the Kleros Curate Registry:
223261

262+
**The Graph (default):**
224263
- Endpoint: `https://gateway.thegraph.com/api/${CURATE_GRAPHQL_API_KEY}/subgraphs/id/9hHo5MpjpC1JqfD3BsgFnojGurXRHTrHWcUcZPPCo6m8`
264+
- Requires API key
265+
- Uses `litems` entity with nested `metadata` structure
266+
- Filter syntax: `field_in`, `field_gt`, `orderBy/orderDirection`
267+
268+
**Envio (alternative):**
269+
- Endpoint: `https://indexer.hyperindex.xyz/1a2f51c/v1/graphql`
270+
- Free, no authentication required
271+
- Uses `LItem` entity with flat metadata structure (Hasura-based)
272+
- Filter syntax: `{_in}`, `{_gt}`, `{_eq}`, `order_by: {}`
273+
274+
**Common Features:**
225275
- Queries all three registries simultaneously for efficiency
226276
- Filters by valid statuses: "Registered" and "ClearingRequested"
277+
- Responses are normalized to a common format for consistency
227278

228279
### Data Mapping
229280

env.template

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Server Configuration
2+
PORT=3000
3+
NODE_ENV=development
4+
5+
# Logging
6+
LOG_LEVEL=debug
7+
LOG_FILE=1
8+
9+
# CORS
10+
ALLOWED_ORIGINS=*
11+
12+
# ========================================
13+
# GraphQL Endpoint Configuration
14+
# ========================================
15+
# Choose endpoint type: 'thegraph' or 'envio'
16+
GRAPHQL_ENDPOINT_TYPE=thegraph
17+
18+
# ----------------------------------------
19+
# The Graph Configuration
20+
# ----------------------------------------
21+
# Required if GRAPHQL_ENDPOINT_TYPE=thegraph
22+
CURATE_GRAPHQL_API_KEY=your_api_key_here
23+
24+
# ----------------------------------------
25+
# Envio Configuration
26+
# ----------------------------------------
27+
# Optional - only used if GRAPHQL_ENDPOINT_TYPE=envio
28+
# Defaults to https://indexer.hyperindex.xyz/1a2f51c/v1/graphql if not set
29+
# ENVIO_ENDPOINT=https://indexer.hyperindex.xyz/1a2f51c/v1/graphql
30+

0 commit comments

Comments
 (0)