Skip to content

Commit 069f689

Browse files
authored
adding mdc files for graph-tooling and also the mdc.mdc guideline (#2048)
1 parent 4b4ad3e commit 069f689

File tree

2 files changed

+679
-0
lines changed

2 files changed

+679
-0
lines changed

.cursor/rules/@graph-tooling.mdc

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
---
7+
description: Monorepo for The Graph Protocol tooling including CLI and TypeScript bindings for subgraph development
8+
globs: ["**/*.ts", "**/*.js", "**/*.json", "**/*.yaml", "**/*.md", "**/subgraph.yaml", "**/schema.graphql"]
9+
---
10+
11+
# The Graph Tooling
12+
13+
@context {
14+
"type": "monorepo",
15+
"purpose": "subgraph_development_tools",
16+
"organization": "graphprotocol",
17+
"license": "(Apache-2.0 OR MIT)",
18+
"node_version": ">=20.0.0",
19+
"package_manager": "pnpm"
20+
}
21+
22+
@structure {
23+
"workspace": {
24+
"packages": ["packages/*", "examples/*", "website"],
25+
"main_tools": [
26+
"@graphprotocol/graph-cli",
27+
"@graphprotocol/graph-ts"
28+
]
29+
},
30+
"architecture": {
31+
"monorepo": "pnpm workspace",
32+
"build_system": "TypeScript + AssemblyScript",
33+
"testing": "vitest",
34+
"release": "changesets"
35+
}
36+
}
37+
38+
## Core Packages
39+
40+
### @graphprotocol/graph-cli
41+
42+
@package_info {
43+
"name": "@graphprotocol/graph-cli",
44+
"description": "CLI for building and deploying subgraphs to The Graph",
45+
"version": "0.97.1",
46+
"bin": "graph",
47+
"main_commands": [
48+
"add",
49+
"auth",
50+
"build",
51+
"clean",
52+
"codegen",
53+
"create",
54+
"deploy",
55+
"init",
56+
"local",
57+
"publish",
58+
"remove",
59+
"test"
60+
]
61+
}
62+
63+
The primary CLI tool for subgraph developers providing:
64+
- Project initialization and scaffolding
65+
- Contract ABI integration
66+
- Code generation from GraphQL schema
67+
- Local development server
68+
- Deployment to The Graph Network
69+
- Authentication and authorization
70+
- Testing and validation
71+
72+
### @graphprotocol/graph-ts
73+
74+
@package_info {
75+
"name": "@graphprotocol/graph-ts",
76+
"description": "TypeScript/AssemblyScript library for writing subgraph mappings",
77+
"version": "0.38.1",
78+
"language": "AssemblyScript",
79+
"target": "WebAssembly"
80+
}
81+
82+
TypeScript bindings and runtime for subgraph mapping development:
83+
- Type-safe blockchain data access
84+
- Entity store operations
85+
- Event handler utilities
86+
- Built-in helper functions
87+
88+
## Development Environment
89+
90+
@development_setup {
91+
"requirements": {
92+
"node": ">=20.18.1",
93+
"pnpm": "9.x",
94+
"typescript": "^5.7.2"
95+
},
96+
"commands": {
97+
"install": "pnpm install",
98+
"build": "pnpm build",
99+
"test": "pnpm test",
100+
"lint": "pnpm lint"
101+
}
102+
}
103+
104+
### Project Structure
105+
106+
@project_structure {
107+
"packages/cli/": "Graph CLI implementation",
108+
"packages/ts/": "TypeScript/AssemblyScript bindings",
109+
"examples/": "Example subgraphs for various chains",
110+
"website/": "Documentation website",
111+
"patches/": "Package patches for dependencies"
112+
}
113+
114+
## Supported Networks
115+
116+
@supported_networks [
117+
"ethereum",
118+
"polygon",
119+
"near",
120+
"cosmos",
121+
"arweave",
122+
"substreams"
123+
]
124+
125+
## Examples
126+
127+
@examples {
128+
"ethereum": [
129+
"ethereum-gravatar",
130+
"ethereum-basic-event-handlers",
131+
"example-subgraph"
132+
],
133+
"polygon": [
134+
"matic-lens-protocol-posts-subgraph"
135+
],
136+
"near": [
137+
"near-blocks",
138+
"near-receipts"
139+
],
140+
"cosmos": [
141+
"cosmos-validator-rewards",
142+
"cosmos-validator-delegations",
143+
"cosmos-osmosis-token-swaps",
144+
"cosmos-block-filtering"
145+
],
146+
"arweave": [
147+
"arweave-blocks-transactions"
148+
],
149+
"advanced": [
150+
"substreams-powered-subgraph",
151+
"aggregations"
152+
]
153+
}
154+
155+
## CLI Usage Patterns
156+
157+
@cli_patterns {
158+
"initialization": {
159+
"command": "graph init",
160+
"purpose": "Create new subgraph project",
161+
"options": ["--product", "--network", "--contract-name"]
162+
},
163+
"development": {
164+
"command": "graph codegen && graph build",
165+
"purpose": "Generate code and build subgraph",
166+
"watch": "graph build --watch"
167+
},
168+
"deployment": {
169+
"hosted_service": "graph deploy --product hosted-service",
170+
"decentralized_network": "graph deploy --product subgraph-studio"
171+
},
172+
"testing": {
173+
"command": "graph test",
174+
"purpose": "Run subgraph tests"
175+
},
176+
"local_development": {
177+
"command": "graph local",
178+
"purpose": "Start local development environment"
179+
}
180+
}
181+
182+
## TypeScript Integration
183+
184+
@typescript_usage {
185+
"mapping_files": {
186+
"location": "src/mapping.ts",
187+
"imports": ["@graphprotocol/graph-ts"],
188+
"exports": ["event handlers", "block handlers"]
189+
},
190+
"schema_types": {
191+
"generation": "graph codegen",
192+
"location": "generated/schema.ts",
193+
"usage": "Import entity classes"
194+
}
195+
}
196+
197+
```typescript
198+
// Example mapping function
199+
import { Transfer } from '../generated/Contract/Contract'
200+
import { User, Transfer as TransferEntity } from '../generated/schema'
201+
202+
export function handleTransfer(event: Transfer): void {
203+
let user = User.load(event.params.to.toHex())
204+
if (user == null) {
205+
user = new User(event.params.to.toHex())
206+
user.save()
207+
}
208+
209+
let transfer = new TransferEntity(event.transaction.hash.toHex())
210+
transfer.from = event.params.from
211+
transfer.to = event.params.to
212+
transfer.value = event.params.value
213+
transfer.save()
214+
}
215+
```
216+
217+
## Configuration Files
218+
219+
@configuration {
220+
"subgraph.yaml": {
221+
"purpose": "Subgraph manifest",
222+
"sections": ["specVersion", "schema", "dataSources"],
223+
"required": true
224+
},
225+
"schema.graphql": {
226+
"purpose": "GraphQL schema definition",
227+
"contains": ["entities", "types", "relationships"],
228+
"required": true
229+
},
230+
"networks.json": {
231+
"purpose": "Network configuration",
232+
"optional": true,
233+
"usage": "Multi-network deployments"
234+
}
235+
}
236+
237+
## Release Process
238+
239+
@release_process {
240+
"tool": "@changesets/cli",
241+
"workflow": [
242+
"Author creates PR with changeset file",
243+
"PR merged to main",
244+
"Bot creates version bump PR",
245+
"Version PR merged triggers npm publish"
246+
],
247+
"commands": {
248+
"create_changeset": "pnpm changeset",
249+
"release": "pnpm release"
250+
}
251+
}
252+
253+
## Testing
254+
255+
@testing_setup {
256+
"framework": "vitest",
257+
"test_files": "tests/**/*.test.ts",
258+
"commands": {
259+
"all": "pnpm test",
260+
"cli_specific": "pnpm test:cli",
261+
"ts_specific": "pnpm test:ts"
262+
}
263+
}
264+
265+
## Build System
266+
267+
@build_configuration {
268+
"typescript": {
269+
"config": "tsconfig.build.json",
270+
"target": "ESNext",
271+
"module": "ESNext"
272+
},
273+
"assemblyscript": {
274+
"cli_version": "0.19.23",
275+
"ts_version": "0.27.31",
276+
"runtime": "stub",
277+
"optimization": "size"
278+
},
279+
"bundling": {
280+
"cli": "TypeScript compilation + oclif manifest",
281+
"ts": "AssemblyScript to WebAssembly"
282+
}
283+
}
284+
285+
## Common Issues & Solutions
286+
287+
@troubleshooting [
288+
{
289+
"issue": "Node version compatibility",
290+
"solution": "Use Node.js >=20.18.1",
291+
"severity": "error"
292+
},
293+
{
294+
"issue": "AssemblyScript compilation errors",
295+
"solution": "Check graph-ts version compatibility",
296+
"severity": "warning"
297+
},
298+
{
299+
"issue": "Subgraph deployment failures",
300+
"solution": "Verify network config and API keys",
301+
"severity": "error"
302+
}
303+
]
304+
305+
## Contributing
306+
307+
@contribution_guidelines {
308+
"repository": "https://github.com/graphprotocol/graph-tooling",
309+
"requirements": [
310+
"Node.js >=20.x",
311+
"pnpm package manager",
312+
"Changeset file for PRs"
313+
],
314+
"workflow": [
315+
"Fork repository",
316+
"Create feature branch",
317+
"Add changeset with `pnpm changeset`",
318+
"Submit PR with tests"
319+
]
320+
}
321+
322+
@version "0.97.1"
323+
@last_updated "2024-12-19"
324+

0 commit comments

Comments
 (0)