Skip to content

Commit 477bf10

Browse files
committed
Add new datasource type for subgraph composition
1 parent 08914a8 commit 477bf10

File tree

4 files changed

+113
-2
lines changed

4 files changed

+113
-2
lines changed

packages/cli/src/protocols/index.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as NearManifestScaffold from './near/scaffold/manifest';
2020
import * as NearMappingScaffold from './near/scaffold/mapping';
2121
import NearSubgraph from './near/subgraph';
2222
import { SubgraphOptions } from './subgraph';
23+
import SubgraphDS from './subgraph/subgraph';
2324
import * as SubstreamsManifestScaffold from './substreams/scaffold/manifest';
2425
import SubstreamsSubgraph from './substreams/subgraph';
2526

@@ -43,6 +44,7 @@ export default class Protocol {
4344
* some other places use datasource object
4445
*/
4546
const name = typeof datasource === 'string' ? datasource : datasource.kind;
47+
protocolDebug('Initializing protocol with datasource %O', datasource);
4648
this.name = Protocol.normalizeName(name)!;
4749
protocolDebug('Initializing protocol %s', this.name);
4850

@@ -59,6 +61,9 @@ export default class Protocol {
5961
case 'near':
6062
this.config = nearProtocol;
6163
break;
64+
case 'subgraph':
65+
this.config = subgraphProtocol;
66+
break;
6267
case 'substreams':
6368
this.config = substreamsProtocol;
6469

@@ -85,6 +90,7 @@ export default class Protocol {
8590
near: ['near'],
8691
cosmos: ['cosmos'],
8792
substreams: ['substreams'],
93+
subgraph: ['subgraph'],
8894
}) as immutable.Collection<ProtocolName, string[]>;
8995
}
9096

@@ -140,14 +146,16 @@ export default class Protocol {
140146
'uni-3', // Juno testnet
141147
],
142148
substreams: ['mainnet'],
149+
subgraph: ['mainnet'],
143150
}) as immutable.Map<
144151
| 'arweave'
145152
| 'ethereum'
146153
| 'near'
147154
| 'cosmos'
148155
| 'substreams'
149156
// this is temporary, until we have a better way to handle substreams triggers
150-
| 'substreams/triggers',
157+
| 'substreams/triggers'
158+
| 'subgraph',
151159
immutable.List<string>
152160
>;
153161
}
@@ -234,7 +242,8 @@ export type ProtocolName =
234242
| 'near'
235243
| 'cosmos'
236244
| 'substreams'
237-
| 'substreams/triggers';
245+
| 'substreams/triggers'
246+
| 'subgraph';
238247

239248
export interface ProtocolConfig {
240249
displayName: string;
@@ -290,6 +299,19 @@ const ethereumProtocol: ProtocolConfig = {
290299
mappingScaffold: EthereumMappingScaffold,
291300
};
292301

302+
const subgraphProtocol: ProtocolConfig = {
303+
displayName: 'Subgraph',
304+
abi: undefined,
305+
contract: undefined,
306+
getTemplateCodeGen: undefined,
307+
getTypeGenerator: undefined,
308+
getSubgraph(options) {
309+
return new SubgraphDS(options);
310+
},
311+
manifestScaffold: undefined,
312+
mappingScaffold: undefined,
313+
};
314+
293315
const nearProtocol: ProtocolConfig = {
294316
displayName: 'NEAR',
295317
abi: undefined,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Each referenced type's in any of the types below must be listed
2+
# here either as `scalar` or `type` for the validation code to work
3+
# properly.
4+
#
5+
# That's why `String` is listed as a scalar even though it's built-in
6+
# GraphQL basic types.
7+
scalar String
8+
scalar File
9+
scalar BigInt
10+
scalar Boolean
11+
scalar JSON
12+
13+
type SubgraphManifest {
14+
specVersion: String!
15+
features: [String!]
16+
schema: Schema!
17+
description: String
18+
repository: String
19+
graft: Graft
20+
dataSources: [DataSource!]!
21+
indexerHints: IndexerHints
22+
}
23+
24+
type Schema {
25+
file: File!
26+
}
27+
28+
type DataSource {
29+
kind: String!
30+
name: String!
31+
network: String
32+
context: JSON
33+
source: ContractSource!
34+
mapping: ContractMapping!
35+
}
36+
37+
type ContractSource {
38+
address: String!
39+
startBlock: BigInt
40+
}
41+
42+
type ContractMapping {
43+
kind: String
44+
apiVersion: String!
45+
language: String!
46+
file: File!
47+
entities: [String!]!
48+
handlers: [EntityHandler!]
49+
}
50+
51+
type EntityHandler {
52+
handler: String!
53+
entity: String!
54+
}
55+
56+
type Graft {
57+
base: String!
58+
block: BigInt!
59+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const source = ({ spkgPath }: { spkgPath?: string }) => `
2+
package:
3+
moduleName: graph_out
4+
file: ${spkgPath || 'substreams-eth-block-meta-v0.1.0.spkg'}`;
5+
6+
export const mapping = () => `
7+
apiVersion: 0.0.5
8+
kind: substreams/graph-entities`;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import immutable from 'immutable';
2+
import { Subgraph, SubgraphOptions } from '../subgraph';
3+
4+
export default class SubgraphDS implements Subgraph {
5+
public manifest: SubgraphOptions['manifest'];
6+
public resolveFile: SubgraphOptions['resolveFile'];
7+
public protocol: SubgraphOptions['protocol'];
8+
9+
constructor(options: SubgraphOptions) {
10+
this.manifest = options.manifest;
11+
this.resolveFile = options.resolveFile;
12+
this.protocol = options.protocol;
13+
}
14+
15+
validateManifest() {
16+
return immutable.List();
17+
}
18+
19+
handlerTypes() {
20+
return immutable.List([]);
21+
}
22+
}

0 commit comments

Comments
 (0)