@graphprotocol/graph-cli 0.36.1 → 0.37.1-alpha-20221207192322-dd39b34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +6 -3
- package/src/command-helpers/abi.js +2 -0
- package/src/command-helpers/compiler.js +1 -1
- package/src/command-helpers/network.test.js +13 -10
- package/src/commands/build.js +7 -3
- package/src/commands/codegen.js +5 -0
- package/src/commands/init.js +12 -3
- package/src/compiler/index.js +128 -73
- package/src/debug.js +15 -0
- package/src/protocols/index.js +140 -128
- package/src/protocols/substreams/manifest.graphql +45 -0
- package/src/protocols/substreams/scaffold/manifest.js +13 -0
- package/src/protocols/substreams/subgraph.js +17 -0
- package/src/scaffold/index.js +7 -2
- package/src/subgraph.js +14 -3
- package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +44 -0
- package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +35 -0
- package/tests/cli/validation/example-values-found/generated/schema.ts +44 -0
- package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +35 -0
- package/.eslintrc +0 -10
- package/.prettierrc.json +0 -6
- package/.travis.yml +0 -37
- package/CONTRIBUTING.md +0 -16
- package/LICENSE-APACHE +0 -190
- package/LICENSE-MIT +0 -21
- package/NEWS.md +0 -80
- package/README.md +0 -146
- package/examples/basic-event-handlers/LICENSE +0 -21
- package/examples/basic-event-handlers/README.md +0 -3
- package/examples/basic-event-handlers/abis/Gravity.json +0 -1
- package/examples/basic-event-handlers/bin/Counter.bin +0 -1
- package/examples/basic-event-handlers/build/Gravity/Gravity.wasm +0 -0
- package/examples/basic-event-handlers/build/Gravity/abis/Gravity.json +0 -199
- package/examples/basic-event-handlers/build/schema.graphql +0 -13
- package/examples/basic-event-handlers/build/subgraph.yaml +0 -27
- package/examples/basic-event-handlers/contracts/Gravity.sol +0 -62
- package/examples/basic-event-handlers/contracts/Migrations.sol +0 -23
- package/examples/basic-event-handlers/generated/Gravity/Gravity.ts +0 -343
- package/examples/basic-event-handlers/generated/schema.ts +0 -133
- package/examples/basic-event-handlers/migrations/1_initial_migration.js +0 -5
- package/examples/basic-event-handlers/migrations/2_deploy_contract.js +0 -5
- package/examples/basic-event-handlers/migrations/3_create_gravatars.js +0 -14
- package/examples/basic-event-handlers/migrations/4_update_gravatars.js +0 -9
- package/examples/basic-event-handlers/package.json +0 -24
- package/examples/basic-event-handlers/schema.graphql +0 -13
- package/examples/basic-event-handlers/src/mapping.ts +0 -21
- package/examples/basic-event-handlers/subgraph.yaml +0 -27
- package/examples/basic-event-handlers/test/handlers.js +0 -110
- package/examples/basic-event-handlers/truffle.js +0 -34
- package/examples/basic-event-handlers/yarn.lock +0 -1027
- package/examples/example-subgraph/abis/ExampleContract.json +0 -2388
- package/examples/example-subgraph/dist/ExampleSubgraph/ExampleSubgraph.wasm +0 -0
- package/examples/example-subgraph/dist/ExampleSubgraph/abis/ExampleContract.json +0 -2394
- package/examples/example-subgraph/dist/abis/ExampleContract.json +0 -2388
- package/examples/example-subgraph/dist/schema.graphql +0 -37
- package/examples/example-subgraph/dist/subgraph.yaml +0 -26
- package/examples/example-subgraph/package.json +0 -15
- package/examples/example-subgraph/schema.graphql +0 -37
- package/examples/example-subgraph/src/mapping.ts +0 -286
- package/examples/example-subgraph/subgraph.yaml +0 -26
- package/examples/example-subgraph/yarn.lock +0 -28
- package/resources/test/docker-compose-standalone-node.yml +0 -20
- package/resources/test/docker-compose.yml +0 -43
package/src/protocols/index.js
CHANGED
|
@@ -6,17 +6,23 @@ const EthereumABI = require('./ethereum/abi')
|
|
|
6
6
|
const EthereumSubgraph = require('./ethereum/subgraph')
|
|
7
7
|
const NearSubgraph = require('./near/subgraph')
|
|
8
8
|
const CosmosSubgraph = require('./cosmos/subgraph')
|
|
9
|
+
const SubstreamsSubgraph = require('./substreams/subgraph')
|
|
9
10
|
const EthereumContract = require('./ethereum/contract')
|
|
10
11
|
const NearContract = require('./near/contract')
|
|
12
|
+
const ArweaveManifestScaffold = require('./arweave/scaffold/manifest')
|
|
11
13
|
const EthereumManifestScaffold = require('./ethereum/scaffold/manifest')
|
|
12
14
|
const NearManifestScaffold = require('./near/scaffold/manifest')
|
|
13
15
|
const CosmosManifestScaffold = require('./cosmos/scaffold/manifest')
|
|
16
|
+
const SubstreamsManifestScaffold = require('./substreams/scaffold/manifest')
|
|
14
17
|
const ArweaveMappingScaffold = require('./arweave/scaffold/mapping')
|
|
15
18
|
const EthereumMappingScaffold = require('./ethereum/scaffold/mapping')
|
|
16
19
|
const NearMappingScaffold = require('./near/scaffold/mapping')
|
|
17
20
|
const CosmosMappingScaffold = require('./cosmos/scaffold/mapping')
|
|
21
|
+
const { ThrowStatement } = require('assemblyscript')
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
let protocolDebug = require('../debug')('graph-cli:protocol')
|
|
24
|
+
|
|
25
|
+
class Protocol {
|
|
20
26
|
static fromDataSources(dataSourcesAndTemplates) {
|
|
21
27
|
const firstDataSourceKind = dataSourcesAndTemplates[0].kind
|
|
22
28
|
return new Protocol(firstDataSourceKind)
|
|
@@ -24,6 +30,27 @@ module.exports = class Protocol {
|
|
|
24
30
|
|
|
25
31
|
constructor(name) {
|
|
26
32
|
this.name = Protocol.normalizeName(name)
|
|
33
|
+
|
|
34
|
+
switch (this.name) {
|
|
35
|
+
case 'arweave':
|
|
36
|
+
this.config = arweaveProtocol
|
|
37
|
+
break
|
|
38
|
+
case 'cosmos':
|
|
39
|
+
this.config = cosmosProtocol
|
|
40
|
+
break
|
|
41
|
+
case 'ethereum':
|
|
42
|
+
this.config = ethereumProtocol
|
|
43
|
+
break
|
|
44
|
+
case 'near':
|
|
45
|
+
this.config = nearProtocol
|
|
46
|
+
break
|
|
47
|
+
case 'substreams':
|
|
48
|
+
this.config = substreamsProtocol
|
|
49
|
+
break
|
|
50
|
+
default:
|
|
51
|
+
// Do not throw when undefined, a better error message is printed after the constructor
|
|
52
|
+
// when validating the Subgraph itself
|
|
53
|
+
}
|
|
27
54
|
}
|
|
28
55
|
|
|
29
56
|
static availableProtocols() {
|
|
@@ -33,12 +60,13 @@ module.exports = class Protocol {
|
|
|
33
60
|
arweave: ['arweave'],
|
|
34
61
|
ethereum: ['ethereum', 'ethereum/contract'],
|
|
35
62
|
near: ['near'],
|
|
36
|
-
cosmos: ['cosmos']
|
|
63
|
+
cosmos: ['cosmos'],
|
|
64
|
+
substreams: ['substreams'],
|
|
37
65
|
})
|
|
38
66
|
}
|
|
39
67
|
|
|
40
68
|
static availableNetworks() {
|
|
41
|
-
|
|
69
|
+
let networks = immutable.fromJS({
|
|
42
70
|
arweave: ['arweave-mainnet'],
|
|
43
71
|
ethereum: [
|
|
44
72
|
'mainnet',
|
|
@@ -74,30 +102,30 @@ module.exports = class Protocol {
|
|
|
74
102
|
'cosmoshub-4',
|
|
75
103
|
'theta-testnet-001', // CosmosHub testnet
|
|
76
104
|
'osmosis-1',
|
|
77
|
-
'osmo-test-4',
|
|
78
|
-
'juno-1',
|
|
79
|
-
'uni-3'
|
|
105
|
+
'osmo-test-4', // Osmosis testnet
|
|
106
|
+
'juno-1',
|
|
107
|
+
'uni-3', // Juno testnet
|
|
80
108
|
],
|
|
81
109
|
})
|
|
110
|
+
|
|
111
|
+
let allNetworks = []
|
|
112
|
+
networks.forEach(value => {
|
|
113
|
+
allNetworks.push(...value)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
networks = networks.set('substreams', immutable.fromJS(allNetworks))
|
|
117
|
+
|
|
118
|
+
return networks
|
|
82
119
|
}
|
|
83
120
|
|
|
84
121
|
static normalizeName(name) {
|
|
85
|
-
return Protocol.availableProtocols().findKey(possibleNames =>
|
|
86
|
-
possibleNames.includes(name)
|
|
87
|
-
)
|
|
122
|
+
return Protocol.availableProtocols().findKey(possibleNames => {
|
|
123
|
+
return possibleNames.includes(name)
|
|
124
|
+
})
|
|
88
125
|
}
|
|
89
126
|
|
|
90
127
|
displayName() {
|
|
91
|
-
|
|
92
|
-
case 'arweave':
|
|
93
|
-
return 'Arweave'
|
|
94
|
-
case 'ethereum':
|
|
95
|
-
return 'Ethereum'
|
|
96
|
-
case 'near':
|
|
97
|
-
return 'NEAR'
|
|
98
|
-
case 'cosmos':
|
|
99
|
-
return 'Cosmos'
|
|
100
|
-
}
|
|
128
|
+
return this.config.displayName
|
|
101
129
|
}
|
|
102
130
|
|
|
103
131
|
// Receives a data source kind, and checks if it's valid
|
|
@@ -109,68 +137,34 @@ module.exports = class Protocol {
|
|
|
109
137
|
}
|
|
110
138
|
|
|
111
139
|
hasABIs() {
|
|
112
|
-
|
|
113
|
-
case 'arweave':
|
|
114
|
-
return false
|
|
115
|
-
case 'ethereum':
|
|
116
|
-
return true
|
|
117
|
-
case 'near':
|
|
118
|
-
return false
|
|
119
|
-
case 'cosmos':
|
|
120
|
-
return false
|
|
121
|
-
}
|
|
140
|
+
return this.config.abi != null
|
|
122
141
|
}
|
|
123
142
|
|
|
124
143
|
hasContract() {
|
|
125
|
-
|
|
126
|
-
case 'arweave':
|
|
127
|
-
return false
|
|
128
|
-
case 'ethereum':
|
|
129
|
-
return true
|
|
130
|
-
case 'near':
|
|
131
|
-
return true
|
|
132
|
-
case 'cosmos':
|
|
133
|
-
return false
|
|
134
|
-
}
|
|
144
|
+
return this.config.contract != null
|
|
135
145
|
}
|
|
136
146
|
|
|
137
147
|
hasEvents() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return true
|
|
143
|
-
case 'near':
|
|
144
|
-
return false
|
|
145
|
-
case 'cosmos':
|
|
146
|
-
return false
|
|
147
|
-
}
|
|
148
|
+
// A problem with hasEvents usage in the codebase is that it's almost every where
|
|
149
|
+
// where used, the ABI data is actually use after the conditional, so it seems
|
|
150
|
+
// both concept are related. So internally, we map to this condition.
|
|
151
|
+
return this.hasABIs()
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
hasTemplates() {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
case 'near':
|
|
157
|
-
return false
|
|
158
|
-
case 'cosmos':
|
|
159
|
-
return false
|
|
160
|
-
}
|
|
155
|
+
return this.config.getTemplateCodeGen != null
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
hasDataSourceMappingFile() {
|
|
159
|
+
return this.config.getMappingScaffold != null
|
|
161
160
|
}
|
|
162
161
|
|
|
163
162
|
getTypeGenerator(options) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return null
|
|
167
|
-
case 'ethereum':
|
|
168
|
-
return new EthereumTypeGenerator(options)
|
|
169
|
-
case 'near':
|
|
170
|
-
return null
|
|
171
|
-
case 'cosmos':
|
|
172
|
-
return null
|
|
163
|
+
if (this.config == null || this.config.getTypeGenerator == null) {
|
|
164
|
+
return null
|
|
173
165
|
}
|
|
166
|
+
|
|
167
|
+
return this.config.getTypeGenerator(options)
|
|
174
168
|
}
|
|
175
169
|
|
|
176
170
|
getTemplateCodeGen(template) {
|
|
@@ -180,80 +174,98 @@ module.exports = class Protocol {
|
|
|
180
174
|
)
|
|
181
175
|
}
|
|
182
176
|
|
|
183
|
-
|
|
184
|
-
case 'ethereum':
|
|
185
|
-
return new EthereumTemplateCodeGen(template)
|
|
186
|
-
default:
|
|
187
|
-
throw new Error(`Template data sources with kind '${this.name}' is unknown`)
|
|
188
|
-
}
|
|
177
|
+
return this.config.getTemplateCodeGen(template)
|
|
189
178
|
}
|
|
190
179
|
|
|
191
180
|
getABI() {
|
|
192
|
-
|
|
193
|
-
case 'arweave':
|
|
194
|
-
return null
|
|
195
|
-
case 'ethereum':
|
|
196
|
-
return EthereumABI
|
|
197
|
-
case 'near':
|
|
198
|
-
return null
|
|
199
|
-
case 'cosmos':
|
|
200
|
-
return null
|
|
201
|
-
}
|
|
181
|
+
return this.config.abi
|
|
202
182
|
}
|
|
203
183
|
|
|
204
184
|
getSubgraph(options = {}) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
switch (this.name) {
|
|
208
|
-
case 'arweave':
|
|
209
|
-
return new ArweaveSubgraph(optionsWithProtocol)
|
|
210
|
-
case 'ethereum':
|
|
211
|
-
return new EthereumSubgraph(optionsWithProtocol)
|
|
212
|
-
case 'near':
|
|
213
|
-
return new NearSubgraph(optionsWithProtocol)
|
|
214
|
-
case 'cosmos':
|
|
215
|
-
return new CosmosSubgraph(optionsWithProtocol)
|
|
216
|
-
default:
|
|
217
|
-
throw new Error(`Data sources with kind '${this.name}' are not supported yet`)
|
|
218
|
-
}
|
|
185
|
+
return this.config.getSubgraph({ ...options, protocol: this })
|
|
219
186
|
}
|
|
220
187
|
|
|
221
188
|
getContract() {
|
|
222
|
-
|
|
223
|
-
case 'arweave':
|
|
224
|
-
return null
|
|
225
|
-
case 'ethereum':
|
|
226
|
-
return EthereumContract
|
|
227
|
-
case 'near':
|
|
228
|
-
return NearContract
|
|
229
|
-
case 'cosmos':
|
|
230
|
-
return null
|
|
231
|
-
}
|
|
189
|
+
return this.config.contract
|
|
232
190
|
}
|
|
233
191
|
|
|
234
192
|
getManifestScaffold() {
|
|
235
|
-
|
|
236
|
-
case 'arweave':
|
|
237
|
-
return ArweaveMappingScaffold
|
|
238
|
-
case 'ethereum':
|
|
239
|
-
return EthereumManifestScaffold
|
|
240
|
-
case 'near':
|
|
241
|
-
return NearManifestScaffold
|
|
242
|
-
case 'cosmos':
|
|
243
|
-
return CosmosManifestScaffold
|
|
244
|
-
}
|
|
193
|
+
return this.config.manifestScaffold
|
|
245
194
|
}
|
|
246
195
|
|
|
247
196
|
getMappingScaffold() {
|
|
248
|
-
|
|
249
|
-
case 'arweave':
|
|
250
|
-
return ArweaveMappingScaffold
|
|
251
|
-
case 'ethereum':
|
|
252
|
-
return EthereumMappingScaffold
|
|
253
|
-
case 'near':
|
|
254
|
-
return NearMappingScaffold
|
|
255
|
-
case 'cosmos':
|
|
256
|
-
return CosmosMappingScaffold
|
|
257
|
-
}
|
|
197
|
+
return this.config.mappingScaffold
|
|
258
198
|
}
|
|
259
199
|
}
|
|
200
|
+
|
|
201
|
+
const arweaveProtocol = {
|
|
202
|
+
displayName: 'Arweave',
|
|
203
|
+
abi: undefined,
|
|
204
|
+
contract: undefined,
|
|
205
|
+
getTemplateCodeGen: undefined,
|
|
206
|
+
getTypeGenerator: undefined,
|
|
207
|
+
getSubgraph(options) {
|
|
208
|
+
return new ArweaveSubgraph(options)
|
|
209
|
+
},
|
|
210
|
+
manifestScaffold: ArweaveManifestScaffold,
|
|
211
|
+
mappingScaffold: ArweaveMappingScaffold,
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const cosmosProtocol = {
|
|
215
|
+
displayName: 'Cosmos',
|
|
216
|
+
abi: undefined,
|
|
217
|
+
contract: undefined,
|
|
218
|
+
getTemplateCodeGen: undefined,
|
|
219
|
+
getTypeGenerator: undefined,
|
|
220
|
+
getSubgraph(options) {
|
|
221
|
+
return new CosmosSubgraph(options)
|
|
222
|
+
},
|
|
223
|
+
manifestScaffold: CosmosManifestScaffold,
|
|
224
|
+
mappingScaffold: CosmosMappingScaffold,
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const ethereumProtocol = {
|
|
228
|
+
displayName: 'Ethereum',
|
|
229
|
+
abi: EthereumABI,
|
|
230
|
+
contract: EthereumContract,
|
|
231
|
+
getTemplateCodeGen(template) {
|
|
232
|
+
return new EthereumTemplateCodeGen(template)
|
|
233
|
+
},
|
|
234
|
+
getTypeGenerator(options) {
|
|
235
|
+
return new EthereumTypeGenerator(options)
|
|
236
|
+
},
|
|
237
|
+
getSubgraph(options) {
|
|
238
|
+
return new EthereumSubgraph(options)
|
|
239
|
+
},
|
|
240
|
+
manifestScaffold: EthereumManifestScaffold,
|
|
241
|
+
mappingScaffold: EthereumMappingScaffold,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const nearProtocol = {
|
|
245
|
+
displayName: 'NEAR',
|
|
246
|
+
abi: undefined,
|
|
247
|
+
contract: NearContract,
|
|
248
|
+
getTypeGenerator: undefined,
|
|
249
|
+
getTemplateCodeGen: undefined,
|
|
250
|
+
getSubgraph(options) {
|
|
251
|
+
return new NearSubgraph(options)
|
|
252
|
+
},
|
|
253
|
+
manifestScaffold: NearManifestScaffold,
|
|
254
|
+
mappingScaffold: NearMappingScaffold,
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const substreamsProtocol = {
|
|
258
|
+
displayName: 'Substreams',
|
|
259
|
+
abi: undefined,
|
|
260
|
+
contract: undefined,
|
|
261
|
+
getTypeGenerator: undefined,
|
|
262
|
+
getTemplateCodeGen: undefined,
|
|
263
|
+
getSubgraph(options) {
|
|
264
|
+
return new SubstreamsSubgraph(options)
|
|
265
|
+
},
|
|
266
|
+
manifestScaffold: SubstreamsManifestScaffold,
|
|
267
|
+
mappingScaffold: undefined,
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
protocolDebug('Available networks %M', Protocol.availableNetworks())
|
|
271
|
+
module.exports = Protocol
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
|
|
11
|
+
type SubgraphManifest {
|
|
12
|
+
specVersion: String!
|
|
13
|
+
features: [String!]
|
|
14
|
+
schema: Schema!
|
|
15
|
+
description: String
|
|
16
|
+
repository: String
|
|
17
|
+
graft: Graft
|
|
18
|
+
dataSources: [DataSource!]!
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type Schema {
|
|
22
|
+
file: File!
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type DataSource {
|
|
26
|
+
kind: String!
|
|
27
|
+
name: String!
|
|
28
|
+
network: String
|
|
29
|
+
source: SubstreamsSource!
|
|
30
|
+
mapping: SubstreamMapping!
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type SubstreamsSource {
|
|
34
|
+
package: SubstreamsPackage!
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type SubstreamsPackage {
|
|
38
|
+
moduleName: String!
|
|
39
|
+
file: String!
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type SubstreamMapping {
|
|
43
|
+
apiVersion: String!
|
|
44
|
+
kind: String!
|
|
45
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const immutable = require('immutable')
|
|
2
|
+
|
|
3
|
+
module.exports = class SubstreamsSubgraph {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this.manifest = options.manifest
|
|
6
|
+
this.resolveFile = options.resolveFile
|
|
7
|
+
this.protocol = options.protocol
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
validateManifest() {
|
|
11
|
+
return immutable.List()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
handlerTypes() {
|
|
15
|
+
return immutable.List([])
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/scaffold/index.js
CHANGED
|
@@ -99,10 +99,15 @@ dataSources:
|
|
|
99
99
|
)
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
generateMappings() {
|
|
103
|
+
return this.protocol.getMappingScaffold()
|
|
104
|
+
? { [`${strings.kebabCase(this.contractName)}.ts`]: this.generateMapping() }
|
|
105
|
+
: undefined
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
generateMapping() {
|
|
103
109
|
const hasEvents = this.protocol.hasEvents()
|
|
104
110
|
const events = hasEvents ? abiEvents(this.abi).toJS() : []
|
|
105
|
-
|
|
106
111
|
const protocolMapping = this.protocol.getMappingScaffold()
|
|
107
112
|
|
|
108
113
|
return prettier.format(
|
|
@@ -141,7 +146,7 @@ dataSources:
|
|
|
141
146
|
'subgraph.yaml': this.generateManifest(),
|
|
142
147
|
'schema.graphql': this.generateSchema(),
|
|
143
148
|
'tsconfig.json': this.generateTsConfig(),
|
|
144
|
-
src:
|
|
149
|
+
src: this.generateMappings(),
|
|
145
150
|
abis: this.generateABIs(),
|
|
146
151
|
tests: this.generateTests(),
|
|
147
152
|
}
|
package/src/subgraph.js
CHANGED
|
@@ -6,6 +6,8 @@ let { strOptions } = require('yaml/types')
|
|
|
6
6
|
let graphql = require('graphql/language')
|
|
7
7
|
let validation = require('./validation')
|
|
8
8
|
|
|
9
|
+
let subgraphDebug = require('./debug')('graph-cli:subgraph')
|
|
10
|
+
|
|
9
11
|
const throwCombinedError = (filename, errors) => {
|
|
10
12
|
throw new Error(
|
|
11
13
|
errors.reduce(
|
|
@@ -39,6 +41,7 @@ const buildCombinedWarning = (filename, warnings) =>
|
|
|
39
41
|
|
|
40
42
|
module.exports = class Subgraph {
|
|
41
43
|
static async validate(data, protocol, { resolveFile }) {
|
|
44
|
+
subgraphDebug(`Validating Subgraph with protocol "%s"`, protocol)
|
|
42
45
|
if (protocol.name == null) {
|
|
43
46
|
return immutable.fromJS([
|
|
44
47
|
{
|
|
@@ -134,11 +137,19 @@ Please update it to tell users more about your subgraph.`,
|
|
|
134
137
|
.filter(dataSource => protocol.isValidKindName(dataSource.get('kind')))
|
|
135
138
|
.reduce((errors, dataSource, dataSourceIndex) => {
|
|
136
139
|
let path = ['dataSources', dataSourceIndex, 'mapping']
|
|
137
|
-
|
|
138
140
|
let mapping = dataSource.get('mapping')
|
|
139
|
-
|
|
140
141
|
const handlerTypes = protocolSubgraph.handlerTypes()
|
|
141
142
|
|
|
143
|
+
subgraphDebug(
|
|
144
|
+
'Validating dataSource "%s" handlers with %d handlers types defined for protocol',
|
|
145
|
+
dataSource.get('name'),
|
|
146
|
+
handlerTypes.size,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
if (handlerTypes.size == 0) {
|
|
150
|
+
return errors
|
|
151
|
+
}
|
|
152
|
+
|
|
142
153
|
const areAllHandlersEmpty = handlerTypes
|
|
143
154
|
.map(handlerType => mapping.get(handlerType, immutable.List()))
|
|
144
155
|
.every(handlers => handlers.isEmpty())
|
|
@@ -159,7 +170,7 @@ At least one such handler must be defined.`,
|
|
|
159
170
|
}
|
|
160
171
|
|
|
161
172
|
static validateContractValues(manifest, protocol) {
|
|
162
|
-
if (!protocol.hasContract()){
|
|
173
|
+
if (!protocol.hasContract()) {
|
|
163
174
|
return immutable.List()
|
|
164
175
|
}
|
|
165
176
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TypedMap,
|
|
5
|
+
Entity,
|
|
6
|
+
Value,
|
|
7
|
+
ValueKind,
|
|
8
|
+
store,
|
|
9
|
+
Bytes,
|
|
10
|
+
BigInt,
|
|
11
|
+
BigDecimal
|
|
12
|
+
} from "@graphprotocol/graph-ts";
|
|
13
|
+
|
|
14
|
+
export class MyEntity extends Entity {
|
|
15
|
+
constructor(id: string) {
|
|
16
|
+
super();
|
|
17
|
+
this.set("id", Value.fromString(id));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
save(): void {
|
|
21
|
+
let id = this.get("id");
|
|
22
|
+
assert(id != null, "Cannot save MyEntity entity without an ID");
|
|
23
|
+
if (id) {
|
|
24
|
+
assert(
|
|
25
|
+
id.kind == ValueKind.STRING,
|
|
26
|
+
`Entities of type MyEntity must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`
|
|
27
|
+
);
|
|
28
|
+
store.set("MyEntity", id.toString(), this);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static load(id: string): MyEntity | null {
|
|
33
|
+
return changetype<MyEntity | null>(store.get("MyEntity", id));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get id(): string {
|
|
37
|
+
let value = this.get("id");
|
|
38
|
+
return value!.toString();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
set id(value: string) {
|
|
42
|
+
this.set("id", Value.fromString(value));
|
|
43
|
+
}
|
|
44
|
+
}
|
package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ethereum,
|
|
5
|
+
JSONValue,
|
|
6
|
+
TypedMap,
|
|
7
|
+
Entity,
|
|
8
|
+
Bytes,
|
|
9
|
+
Address,
|
|
10
|
+
BigInt
|
|
11
|
+
} from "@graphprotocol/graph-ts";
|
|
12
|
+
|
|
13
|
+
export class ExampleEvent extends ethereum.Event {
|
|
14
|
+
get params(): ExampleEvent__Params {
|
|
15
|
+
return new ExampleEvent__Params(this);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class ExampleEvent__Params {
|
|
20
|
+
_event: ExampleEvent;
|
|
21
|
+
|
|
22
|
+
constructor(event: ExampleEvent) {
|
|
23
|
+
this._event = event;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get param0(): string {
|
|
27
|
+
return this._event.parameters[0].value.toString();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class ExampleContract extends ethereum.SmartContract {
|
|
32
|
+
static bind(address: Address): ExampleContract {
|
|
33
|
+
return new ExampleContract("ExampleContract", address);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TypedMap,
|
|
5
|
+
Entity,
|
|
6
|
+
Value,
|
|
7
|
+
ValueKind,
|
|
8
|
+
store,
|
|
9
|
+
Bytes,
|
|
10
|
+
BigInt,
|
|
11
|
+
BigDecimal
|
|
12
|
+
} from "@graphprotocol/graph-ts";
|
|
13
|
+
|
|
14
|
+
export class MyEntity extends Entity {
|
|
15
|
+
constructor(id: string) {
|
|
16
|
+
super();
|
|
17
|
+
this.set("id", Value.fromString(id));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
save(): void {
|
|
21
|
+
let id = this.get("id");
|
|
22
|
+
assert(id != null, "Cannot save MyEntity entity without an ID");
|
|
23
|
+
if (id) {
|
|
24
|
+
assert(
|
|
25
|
+
id.kind == ValueKind.STRING,
|
|
26
|
+
`Entities of type MyEntity must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`
|
|
27
|
+
);
|
|
28
|
+
store.set("MyEntity", id.toString(), this);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static load(id: string): MyEntity | null {
|
|
33
|
+
return changetype<MyEntity | null>(store.get("MyEntity", id));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get id(): string {
|
|
37
|
+
let value = this.get("id");
|
|
38
|
+
return value!.toString();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
set id(value: string) {
|
|
42
|
+
this.set("id", Value.fromString(value));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ethereum,
|
|
5
|
+
JSONValue,
|
|
6
|
+
TypedMap,
|
|
7
|
+
Entity,
|
|
8
|
+
Bytes,
|
|
9
|
+
Address,
|
|
10
|
+
BigInt
|
|
11
|
+
} from "@graphprotocol/graph-ts";
|
|
12
|
+
|
|
13
|
+
export class ExampleEvent extends ethereum.Event {
|
|
14
|
+
get params(): ExampleEvent__Params {
|
|
15
|
+
return new ExampleEvent__Params(this);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class ExampleEvent__Params {
|
|
20
|
+
_event: ExampleEvent;
|
|
21
|
+
|
|
22
|
+
constructor(event: ExampleEvent) {
|
|
23
|
+
this._event = event;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get param0(): string {
|
|
27
|
+
return this._event.parameters[0].value.toString();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class ExampleContract extends ethereum.SmartContract {
|
|
32
|
+
static bind(address: Address): ExampleContract {
|
|
33
|
+
return new ExampleContract("ExampleContract", address);
|
|
34
|
+
}
|
|
35
|
+
}
|
package/.eslintrc
DELETED