|
| 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 | + |
0 commit comments