3939
4040## Commands
4141
42- | Command | Description |
43- | ---------| -------------|
44- | ` init ` | Scaffold a new subgraph |
45- | ` codegen ` | Generate AssemblyScript types from schema/ABIs |
46- | ` build ` | Compile subgraph to WASM |
47- | ` deploy ` | Deploy to hosted service or decentralized network |
48- | ` test ` | Run matchstick tests |
49- | ` create ` | Create subgraph name on node |
50- | ` publish ` | Publish to The Graph Network |
51- | ` add ` | Add data source to manifest |
52- | ` remove ` | Remove data source from manifest |
53- | ` auth ` | Set deploy key |
54- | ` local ` | Manage local Graph Node (always TS — gnd has no equivalent) |
55- | ` dev ` | Run graph-node in dev mode (delegates to ` gnd dev ` ) |
56- | ` clean ` | Remove build artifacts |
42+ | Command | Description |
43+ | --------- | ----------------------------------------------------------- |
44+ | ` init ` | Scaffold a new subgraph |
45+ | ` codegen ` | Generate AssemblyScript types from schema/ABIs |
46+ | ` build ` | Compile subgraph to WASM |
47+ | ` deploy ` | Deploy to hosted service or decentralized network |
48+ | ` test ` | Run matchstick tests |
49+ | ` create ` | Create subgraph name on node |
50+ | ` publish ` | Publish to The Graph Network |
51+ | ` add ` | Add data source to manifest |
52+ | ` remove ` | Remove data source from manifest |
53+ | ` auth ` | Set deploy key |
54+ | ` local ` | Manage local Graph Node (always TS — gnd has no equivalent) |
55+ | ` dev ` | Run graph-node in dev mode (delegates to ` gnd dev ` ) |
56+ | ` clean ` | Remove build artifacts |
5757
5858## Protocol System
5959
6060Factory pattern for multi-chain support (` src/protocols/index.ts ` ):
6161
6262``` typescript
63- import Protocol from ' ./protocols/index.js' ;
63+ import Protocol from ' ./protocols/index.js'
6464
65- const protocol = Protocol .fromDataSources (dataSources );
66- const manifest = protocol .getManifest ();
65+ const protocol = Protocol .fromDataSources (dataSources )
66+ const manifest = protocol .getManifest ()
6767```
6868
6969Each protocol provides:
70+
7071- ABI handling and type generation
7172- Manifest schema and validation
7273- Scaffolding templates
@@ -75,45 +76,49 @@ Each protocol provides:
7576## Scaffolding
7677
7778Templates in ` src/scaffold/ ` generate:
79+
7880- ` subgraph.yaml ` manifest
7981- ` schema.graphql ` entity definitions
8082- ` src/mapping.ts ` event handlers
8183- Test files
8284
8385``` typescript
84- import Scaffold from ' ./scaffold/index.js' ;
86+ import Scaffold from ' ./scaffold/index.js'
8587
8688const scaffold = new Scaffold ({
8789 protocol ,
8890 network ,
89- contractName ,
91+ contractName
9092 // ...
91- });
92- await scaffold .generate ();
93+ })
94+ await scaffold .generate ()
9395```
9496
9597## Type Generation
9698
9799` src/type-generator.ts ` creates AssemblyScript classes from:
100+
98101- GraphQL schema -> Entity classes
99102- Contract ABIs -> Event/Call types
100103
101104## Development
102105
103106``` bash
104- pnpm build # Compile TypeScript + generate oclif manifest
105- pnpm test # Run vitest tests
106- pnpm type-check # TypeScript type checking
107+ pnpm build # Compile TypeScript + generate oclif manifest
108+ pnpm test # Run vitest tests
109+ pnpm type-check # TypeScript type checking
107110```
108111
109112### Testing
110113
111114Uses Vitest with snapshot tests in ` tests/ ` . Key test files:
115+
112116- ` tests/cli/init.test.ts ` - Scaffolding tests
113117- ` tests/cli/validation.test.ts ` - Manifest validation
114118- ` tests/cli/add.test.ts ` - Data source addition
115119
116120Run specific tests:
121+
117122``` bash
118123pnpm test:init
119124pnpm test:validation
@@ -124,15 +129,15 @@ pnpm test:validation
124129### Command Structure
125130
126131``` typescript
127- import { Command , Flags } from ' @oclif/core' ;
132+ import { Command , Flags } from ' @oclif/core'
128133
129134export default class MyCommand extends Command {
130135 static flags = {
131- network: Flags .string ({ description: ' Network name' }),
132- };
136+ network: Flags .string ({ description: ' Network name' })
137+ }
133138
134139 async run() {
135- const { flags } = await this .parse (MyCommand );
140+ const { flags } = await this .parse (MyCommand )
136141 // ...
137142 }
138143}
@@ -141,10 +146,10 @@ export default class MyCommand extends Command {
141146### Subgraph Manifest Loading
142147
143148``` typescript
144- import Subgraph from ' ./subgraph.js' ;
149+ import Subgraph from ' ./subgraph.js'
145150
146- const subgraph = await Subgraph .load (' subgraph.yaml' );
147- const dataSources = subgraph .get (' dataSources' );
151+ const subgraph = await Subgraph .load (' subgraph.yaml' )
152+ const dataSources = subgraph .get (' dataSources' )
148153```
149154
150155## Related
0 commit comments