|
1 | 1 | # Subgraph |
2 | 2 |
|
| 3 | +This repository contains the code for the DataProtector subgraph, which indexes blockchain events to make them queryable through a GraphQL API. |
| 4 | + |
3 | 5 | ## Build the Subgraph |
4 | 6 |
|
5 | | -And you have finishing editing the schema.graphql & subgraph.yaml files. Type the following command |
| 7 | +After editing the schema.graphql & subgraph.yaml files, build the subgraph with: |
6 | 8 |
|
7 | 9 | ```bash |
8 | 10 | npm run codegen |
9 | 11 | npm run build |
10 | 12 | ``` |
11 | 13 |
|
12 | | -Then you have to write ./src/bays.ts files in order to update the graph when new events appear. In this way, it will always be up to date. |
| 14 | +Then implement event handlers in the ./src files to keep the graph updated when new events occur on the blockchain. |
| 15 | + |
| 16 | +## Deployment Options |
13 | 17 |
|
14 | | -## Local |
| 18 | +### Local Development |
15 | 19 |
|
16 | | -### Deploy on Local Graph node |
| 20 | +To deploy on a local Graph Node: |
17 | 21 |
|
18 | 22 | ```bash |
19 | 23 | npm run create-local |
20 | 24 | npm run deploy-local |
21 | 25 | ``` |
22 | 26 |
|
23 | | -### Test Subgrah API |
| 27 | +The subgraph will be available at: http://localhost:8000/subgraphs/name/DataProtector/graphql |
| 28 | + |
| 29 | +### Hosted Production Environments |
| 30 | + |
| 31 | +We use CI/CD pipelines to deploy our subgraphs to hosted environments. |
| 32 | + |
| 33 | +#### Docker Image Tags |
| 34 | + |
| 35 | +When building and pushing Docker images, the following tag generation strategy is used: |
| 36 | + |
| 37 | +| Trigger | Environment | Tag Format | Example | Push? | |
| 38 | +|---------|-------------|------------|---------|-------| |
| 39 | +| Manual workflow dispatch | Production | `{package.json version}` | `1.2.3` | Yes | |
| 40 | +| Manual workflow dispatch | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | Yes | |
| 41 | +| Push to `main` branch | Production | `{package.json version}` | `1.2.3` | Yes | |
| 42 | +| Push to `develop` branch | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | Yes | |
| 43 | +| Tag push | N/A | `{tag name}` | `v1.2.3-beta` | Yes | |
| 44 | +| Other branch push | Development | `dev-{commit SHA}` | `dev-8e7d3f2` | No | |
24 | 45 |
|
25 | | -Deployed to : <http://localhost:8000/subgraphs/name/DataProtector/graphql> |
| 46 | +### Self-Hosted Subgraph Deployment Process |
26 | 47 |
|
27 | | -Request Example on GraphiQL : |
| 48 | +For zero-downtime updates to the production subgraph: |
28 | 49 |
|
29 | | -Query for GraphiQL API |
| 50 | +1. **Index the New Version (Temporary Deployment)** |
| 51 | + - Trigger deployment with target: `subgraph-deploy-tmp` |
| 52 | + - This creates a separate instance for indexing |
| 53 | + |
| 54 | +2. **Wait for Indexing Completion** |
| 55 | + - Monitor the temporary deployment until it's fully synced |
| 56 | + |
| 57 | +3. **Deploy to Production (Zero Downtime)** |
| 58 | + - Once temporary deployment is ready, trigger: `subgraph-deploy-prod` |
| 59 | + - This swaps the deployments with no service interruption |
| 60 | + |
| 61 | +4. **Verify the Deployment** |
| 62 | + - Access the production subgraph at: https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2/graphql |
| 63 | + |
| 64 | +## Query Examples |
| 65 | + |
| 66 | +### Sample GraphQL Query |
30 | 67 |
|
31 | 68 | ```graphql |
32 | 69 | query MyQuery($requiredSchema: [String!]!, $start: Int!, $range: Int!) { |
@@ -57,48 +94,27 @@ query MyQuery($requiredSchema: [String!]!, $start: Int!, $range: Int!) { |
57 | 94 | } |
58 | 95 | ``` |
59 | 96 |
|
60 | | -```graphql |
61 | | -Query Variables : |
| 97 | +### Query Variables |
62 | 98 |
|
| 99 | +```json |
63 | 100 | { |
64 | 101 | "start": 0, |
65 | 102 | "range": 1000, |
66 | 103 | "requiredSchema": [] |
67 | 104 | } |
68 | 105 | ``` |
69 | 106 |
|
70 | | -## Hosted |
71 | | - |
72 | | -You can trigger a deployment using the promote action on the CI. |
73 | | - |
74 | | -### Self Hosted Subgraph |
75 | | - |
76 | | -To deploy a new version of a subgraph on the iExec self-hosted service, follow these steps: |
77 | | - |
78 | | -1. Index the New Subgraph |
79 | | - |
80 | | -First, index the new version of the subgraph using the temporary subgraph deployment. |
81 | | -Trigger its deployment with the target: |
82 | | - |
83 | | -```sh |
84 | | -subgraph-deploy-tmp |
85 | | -``` |
86 | | - |
87 | | -2. Wait for Indexing Completion |
88 | | - |
89 | | -Once the temporary subgraph has finished indexing, you can proceed to the production deployment. |
90 | | - |
91 | | -3. Deploy to Production (No Downtime) |
92 | | - |
93 | | -Trigger the production deployment with : |
94 | | - |
95 | | -```sh |
96 | | -subgraph-deploy-prod |
97 | | -``` |
| 107 | +## Development Workflow |
98 | 108 |
|
99 | | -This ensures a seamless transition with no downtime. |
| 109 | +1. Update schema.graphql and subgraph.yaml as needed |
| 110 | +2. Run codegen to generate TypeScript types: `npm run codegen` |
| 111 | +3. Implement mapping handlers in src/ files |
| 112 | +4. Build the subgraph: `npm run build` |
| 113 | +5. Test locally before deploying to production environments |
100 | 114 |
|
101 | | -4. Verify the Deployment |
| 115 | +## CI/CD Integration |
102 | 116 |
|
103 | | -Visit the following URL to check the new version of the subgraph: |
104 | | -<https://thegraph.iex.ec/subgraphs/name/bellecour/dataprotector-v2/graphql> |
| 117 | +Our repository uses automated workflows to build, test, and deploy the subgraph: |
| 118 | +- ABI validation checks ensure contract ABIs are up-to-date |
| 119 | +- Docker images are built and pushed with appropriate tags based on the source branch |
| 120 | +- Deployment follows a staged approach to ensure zero downtime |
0 commit comments