@graphprotocol/graph-cli 0.30.0-alpha.0 → 0.30.1
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/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/arweave.ts +76 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/cosmos.ts +341 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +39 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +286 -142
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +4 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +2 -1
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +4 -2
- package/examples/basic-event-handlers/node_modules/keccak/build/config.gypi +300 -125
- package/examples/basic-event-handlers/node_modules/websocket/build/config.gypi +292 -15
- package/examples/basic-event-handlers/package.json +1 -1
- package/examples/basic-event-handlers/yarn.lock +4 -4
- package/examples/example-subgraph/package.json +1 -1
- package/examples/example-subgraph/yarn.lock +4 -4
- package/package.json +1 -1
- package/resources/test/docker-compose.yml +4 -2
- package/src/codegen/schema.js +8 -45
- package/src/codegen/schema.test.js +102 -6
- package/src/codegen/types/conversions.js +19 -19
- package/src/codegen/types/index.js +0 -25
- package/src/codegen/types/index.test.js +0 -22
- package/src/command-helpers/abi.js +69 -0
- package/src/command-helpers/scaffold.js +67 -0
- package/src/commands/add.js +198 -0
- package/src/commands/init.js +25 -71
- package/src/migrations/spec_version_0_0_2.js +1 -1
- package/src/migrations/{spec_version_0_0_4.js → spec_version_0_0_3.js} +10 -6
- package/src/migrations.js +1 -1
- package/src/protocols/arweave/manifest.graphql +57 -0
- package/src/protocols/arweave/scaffold/manifest.js +19 -0
- package/src/protocols/arweave/scaffold/mapping.js +53 -0
- package/src/protocols/arweave/subgraph.js +20 -0
- package/src/protocols/{tendermint → cosmos}/manifest.graphql +6 -0
- package/src/protocols/cosmos/scaffold/manifest.js +16 -0
- package/src/protocols/cosmos/scaffold/mapping.js +39 -0
- package/src/protocols/{tendermint → cosmos}/subgraph.js +2 -1
- package/src/protocols/ethereum/codegen/abi.js +21 -4
- package/src/protocols/ethereum/scaffold/manifest.js +2 -1
- package/src/protocols/index.js +53 -20
- package/src/protocols/near/manifest.graphql +1 -0
- package/src/protocols/near/scaffold/manifest.js +4 -2
- package/src/scaffold/cosmos.test.js +86 -0
- package/src/scaffold/ethereum.test.js +2 -1
- package/src/scaffold/index.js +5 -3
- package/src/scaffold/near.test.js +2 -1
- package/src/validation/manifest.js +52 -12
- package/src/validation/schema.js +2 -0
- package/tests/cli/validation/conflicting-protocol-names/Abi.json +7 -0
- package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-protocol-names/schema.graphql +3 -0
- package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +41 -0
- package/tests/cli/validation/conflicting-protocol-names.stderr +10 -0
- package/tests/cli/validation.test.js +9 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/tendermint.ts +0 -554
- package/examples/basic-event-handlers/node_modules/keccak/build/Makefile +0 -342
- package/examples/basic-event-handlers/node_modules/keccak/build/Release/.deps/Release/obj.target/keccak/src/addon.o.d.raw +0 -27
- package/examples/basic-event-handlers/node_modules/keccak/build/binding.Makefile +0 -6
- package/examples/basic-event-handlers/node_modules/keccak/build/gyp-mac-tool +0 -615
- package/examples/basic-event-handlers/node_modules/keccak/build/keccak.target.mk +0 -209
- package/examples/basic-event-handlers/node_modules/websocket/build/Makefile +0 -347
- package/examples/basic-event-handlers/node_modules/websocket/build/Release/.deps/Release/obj.target/bufferutil/src/bufferutil.o.d.raw +0 -25
- package/examples/basic-event-handlers/node_modules/websocket/build/binding.Makefile +0 -6
- package/examples/basic-event-handlers/node_modules/websocket/build/bufferutil.target.mk +0 -192
- package/examples/basic-event-handlers/node_modules/websocket/build/gyp-mac-tool +0 -615
- package/examples/basic-event-handlers/node_modules/websocket/build/validation.target.mk +0 -192
- package/src/codegen/types/defaults.js +0 -34
- package/src/migrations/mapping_api_version_0_0_6.js +0 -74
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const immutable = require('immutable')
|
|
2
|
+
const Scaffold = require('./')
|
|
3
|
+
const Protocol = require('../protocols')
|
|
4
|
+
|
|
5
|
+
const protocol = new Protocol('cosmos')
|
|
6
|
+
|
|
7
|
+
const scaffoldOptions = {
|
|
8
|
+
protocol,
|
|
9
|
+
network: 'cosmoshub-4',
|
|
10
|
+
dataSourceName: 'CosmosHub'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const scaffold = new Scaffold(scaffoldOptions)
|
|
14
|
+
|
|
15
|
+
describe('Cosmos subgraph scaffolding', () => {
|
|
16
|
+
test('Manifest', () => {
|
|
17
|
+
expect(
|
|
18
|
+
scaffold.generateManifest(),
|
|
19
|
+
).toEqual(`\
|
|
20
|
+
specVersion: 0.0.1
|
|
21
|
+
schema:
|
|
22
|
+
file: ./schema.graphql
|
|
23
|
+
dataSources:
|
|
24
|
+
- kind: cosmos
|
|
25
|
+
name: CosmosHub
|
|
26
|
+
network: cosmoshub-4
|
|
27
|
+
source:
|
|
28
|
+
startBlock: 0
|
|
29
|
+
mapping:
|
|
30
|
+
apiVersion: 0.0.5
|
|
31
|
+
language: wasm/assemblyscript
|
|
32
|
+
entities:
|
|
33
|
+
- ExampleEntity
|
|
34
|
+
blockHandlers:
|
|
35
|
+
- handler: handleBlock
|
|
36
|
+
file: ./src/mapping.ts
|
|
37
|
+
`)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('Schema (default)', () => {
|
|
41
|
+
expect(scaffold.generateSchema()).toEqual(`\
|
|
42
|
+
type ExampleEntity @entity {
|
|
43
|
+
id: ID!
|
|
44
|
+
block: Bytes!
|
|
45
|
+
count: BigInt!
|
|
46
|
+
}
|
|
47
|
+
`)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('Mapping (default)', () => {
|
|
51
|
+
expect(scaffold.generateMapping()).toEqual(`\
|
|
52
|
+
import { cosmos, BigInt } from "@graphprotocol/graph-ts"
|
|
53
|
+
import { ExampleEntity } from "../generated/schema"
|
|
54
|
+
|
|
55
|
+
export function handleBlock(block: cosmos.Block): void {
|
|
56
|
+
// Entities can be loaded from the store using a string ID; this ID
|
|
57
|
+
// needs to be unique across all entities of the same type
|
|
58
|
+
let entity = ExampleEntity.load(block.header.hash.toHex())
|
|
59
|
+
|
|
60
|
+
// Entities only exist after they have been saved to the store;
|
|
61
|
+
// \`null\` checks allow to create entities on demand
|
|
62
|
+
if (!entity) {
|
|
63
|
+
entity = new ExampleEntity(block.header.hash.toHex())
|
|
64
|
+
|
|
65
|
+
// Entity fields can be set using simple assignments
|
|
66
|
+
entity.count = BigInt.fromI32(0)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// BigInt and BigDecimal math are supported
|
|
70
|
+
entity.count = entity.count + BigInt.fromI32(1)
|
|
71
|
+
|
|
72
|
+
// Entity fields can be set based on receipt information
|
|
73
|
+
entity.height = block.header.height
|
|
74
|
+
|
|
75
|
+
// Entities can be written to the store with \`.save()\`
|
|
76
|
+
entity.save()
|
|
77
|
+
|
|
78
|
+
// Note: If a handler doesn't require existing field values, it is faster
|
|
79
|
+
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
80
|
+
// \`new Entity(...)\`, set the fields that should be updated and save the
|
|
81
|
+
// entity back to the store. Fields that were not set or unset remain
|
|
82
|
+
// unchanged, allowing for partial updates to be applied.
|
|
83
|
+
}
|
|
84
|
+
`)
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -77,6 +77,7 @@ const scaffoldOptions = {
|
|
|
77
77
|
contract: '0xf87e31492faf9a91b02ee0deaad50d51d56d5d4d',
|
|
78
78
|
network: 'kovan',
|
|
79
79
|
contractName: 'Contract',
|
|
80
|
+
dataSourceName: 'Contract'
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
const scaffold = new Scaffold(scaffoldOptions)
|
|
@@ -116,7 +117,7 @@ dataSources:
|
|
|
116
117
|
handler: handleExampleEvent
|
|
117
118
|
- event: ExampleEvent(bytes32)
|
|
118
119
|
handler: handleExampleEvent1
|
|
119
|
-
file: ./src/
|
|
120
|
+
file: ./src/contract.ts
|
|
120
121
|
`)
|
|
121
122
|
})
|
|
122
123
|
|
package/src/scaffold/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const prettier = require('prettier')
|
|
2
2
|
const pkginfo = require('pkginfo')(module)
|
|
3
|
+
const { strings } = require('gluegun')
|
|
3
4
|
|
|
4
5
|
const GRAPH_CLI_VERSION = process.env.GRAPH_CLI_TESTS
|
|
5
6
|
// JSON.stringify should remove this key, we will install the local
|
|
@@ -25,6 +26,7 @@ module.exports = class Scaffold {
|
|
|
25
26
|
this.network = options.network
|
|
26
27
|
this.contractName = options.contractName
|
|
27
28
|
this.subgraphName = options.subgraphName
|
|
29
|
+
this.dataSourceName = options.dataSourceName
|
|
28
30
|
this.node = options.node
|
|
29
31
|
}
|
|
30
32
|
|
|
@@ -50,7 +52,7 @@ module.exports = class Scaffold {
|
|
|
50
52
|
},
|
|
51
53
|
dependencies: {
|
|
52
54
|
'@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
|
|
53
|
-
'@graphprotocol/graph-ts': `0.27.0
|
|
55
|
+
'@graphprotocol/graph-ts': `0.27.0`,
|
|
54
56
|
},
|
|
55
57
|
}),
|
|
56
58
|
{ parser: 'json' },
|
|
@@ -66,7 +68,7 @@ schema:
|
|
|
66
68
|
file: ./schema.graphql
|
|
67
69
|
dataSources:
|
|
68
70
|
- kind: ${this.protocol.name}
|
|
69
|
-
name: ${this.
|
|
71
|
+
name: ${this.dataSourceName}
|
|
70
72
|
network: ${this.network}
|
|
71
73
|
source: ${protocolManifest.source(this)}
|
|
72
74
|
mapping: ${protocolManifest.mapping(this)}
|
|
@@ -142,7 +144,7 @@ dataSources:
|
|
|
142
144
|
'subgraph.yaml': this.generateManifest(),
|
|
143
145
|
'schema.graphql': this.generateSchema(),
|
|
144
146
|
'tsconfig.json': this.generateTsConfig(),
|
|
145
|
-
src: {
|
|
147
|
+
src: { [`${strings.kebabCase(this.contractName)}.ts`]: this.generateMapping() },
|
|
146
148
|
abis: this.generateABIs(),
|
|
147
149
|
}
|
|
148
150
|
}
|
|
@@ -9,6 +9,7 @@ const scaffoldOptions = {
|
|
|
9
9
|
contract: 'abc.def.near',
|
|
10
10
|
network: 'near-mainnet',
|
|
11
11
|
contractName: 'Contract',
|
|
12
|
+
dataSourceName: 'Contract'
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
const scaffold = new Scaffold(scaffoldOptions)
|
|
@@ -34,7 +35,7 @@ dataSources:
|
|
|
34
35
|
- ExampleEntity
|
|
35
36
|
receiptHandlers:
|
|
36
37
|
- handler: handleReceipt
|
|
37
|
-
file: ./src/
|
|
38
|
+
file: ./src/contract.ts
|
|
38
39
|
`)
|
|
39
40
|
})
|
|
40
41
|
|
|
@@ -2,6 +2,8 @@ const immutable = require('immutable')
|
|
|
2
2
|
const yaml = require('js-yaml')
|
|
3
3
|
const path = require('path')
|
|
4
4
|
|
|
5
|
+
const Protocol = require('../protocols')
|
|
6
|
+
|
|
5
7
|
const List = immutable.List
|
|
6
8
|
const Map = immutable.Map
|
|
7
9
|
|
|
@@ -241,23 +243,61 @@ const validateValue = (value, ctx) => {
|
|
|
241
243
|
}
|
|
242
244
|
}
|
|
243
245
|
|
|
244
|
-
|
|
246
|
+
// Transforms list of data sources like this:
|
|
247
|
+
// [
|
|
248
|
+
// { name: 'contract0', kind: 'ethereum/contract', network: 'mainnet' },
|
|
249
|
+
// { name: 'contract1', kind: 'ethereum', network: 'mainnet' },
|
|
250
|
+
// { name: 'contract2', kind: 'ethereum/contract', network: 'xdai' },
|
|
251
|
+
// { name: 'contract3', kind: 'near', network: 'near-mainnet' },
|
|
252
|
+
// ]
|
|
253
|
+
//
|
|
254
|
+
// Into Immutable JS structure like this (protocol kind is normalized):
|
|
255
|
+
// {
|
|
256
|
+
// ethereum: {
|
|
257
|
+
// mainnet: ['contract0', 'contract1'],
|
|
258
|
+
// xdai: ['contract2'],
|
|
259
|
+
// },
|
|
260
|
+
// near: {
|
|
261
|
+
// 'near-mainnet': ['contract3'],
|
|
262
|
+
// },
|
|
263
|
+
// }
|
|
264
|
+
const dataSourceListToMap = dataSources =>
|
|
245
265
|
dataSources
|
|
246
|
-
.filter(dataSource => protocol.isValidKindName(dataSource.kind))
|
|
247
266
|
.reduce(
|
|
248
|
-
(
|
|
249
|
-
|
|
250
|
-
(
|
|
267
|
+
(protocolKinds, dataSource) =>
|
|
268
|
+
protocolKinds.update(Protocol.normalizeName(dataSource.kind), networks =>
|
|
269
|
+
(networks || immutable.OrderedMap()).update(dataSource.network, dataSourceNames =>
|
|
270
|
+
(dataSourceNames || immutable.OrderedSet()).add(dataSource.name)),
|
|
251
271
|
),
|
|
252
272
|
immutable.OrderedMap(),
|
|
253
273
|
)
|
|
254
274
|
|
|
255
|
-
const
|
|
275
|
+
const validateDataSourceProtocolAndNetworks = value => {
|
|
256
276
|
const dataSources = [...value.dataSources, ...(value.templates || [])]
|
|
257
277
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
278
|
+
const protocolNetworkMap = dataSourceListToMap(dataSources)
|
|
279
|
+
|
|
280
|
+
if (protocolNetworkMap.size > 1) {
|
|
281
|
+
return immutable.fromJS([
|
|
282
|
+
{
|
|
283
|
+
path: [],
|
|
284
|
+
message: `Conflicting protocol kinds used in data sources and templates:
|
|
285
|
+
${protocolNetworkMap
|
|
286
|
+
.map(
|
|
287
|
+
(dataSourceNames, protocolKind) =>
|
|
288
|
+
` ${
|
|
289
|
+
protocolKind === undefined
|
|
290
|
+
? 'Data sources and templates having no protocol kind set'
|
|
291
|
+
: `Data sources and templates using '${protocolKind}'`
|
|
292
|
+
}:\n${dataSourceNames.valueSeq().flatten().map(ds => ` - ${ds}`).join('\n')}`,
|
|
293
|
+
)
|
|
294
|
+
.join('\n')}
|
|
295
|
+
Recommendation: Make all data sources and templates use the same protocol kind.`,
|
|
296
|
+
},
|
|
297
|
+
])
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const networks = protocolNetworkMap.first()
|
|
261
301
|
|
|
262
302
|
if (networks.size > 1) {
|
|
263
303
|
return immutable.fromJS([
|
|
@@ -310,9 +350,9 @@ const validateManifest = (value, type, schema, protocol, { resolveFile }) => {
|
|
|
310
350
|
return errors
|
|
311
351
|
}
|
|
312
352
|
|
|
313
|
-
// Validate that all data sources are for the same `network` (
|
|
314
|
-
// _no_ network at all)
|
|
315
|
-
return
|
|
353
|
+
// Validate that all data sources are for the same `network` and `protocol` (kind)
|
|
354
|
+
// (this includes _no_ network/protocol at all)
|
|
355
|
+
return validateDataSourceProtocolAndNetworks(value)
|
|
316
356
|
}
|
|
317
357
|
|
|
318
358
|
module.exports = {
|
package/src/validation/schema.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
specVersion: 0.0.1
|
|
2
|
+
schema:
|
|
3
|
+
file: ./schema.graphql
|
|
4
|
+
dataSources:
|
|
5
|
+
- kind: ethereum/contract
|
|
6
|
+
name: ExampleSubgraph
|
|
7
|
+
network: mainnet
|
|
8
|
+
source:
|
|
9
|
+
address: 22843e74c59580b3eaf6c233fa67d8b7c561a835
|
|
10
|
+
abi: ExampleContract
|
|
11
|
+
mapping:
|
|
12
|
+
kind: ethereum/events
|
|
13
|
+
apiVersion: 0.0.5
|
|
14
|
+
language: wasm/assemblyscript
|
|
15
|
+
file: ./mapping.ts
|
|
16
|
+
entities:
|
|
17
|
+
- ExampleEntity
|
|
18
|
+
abis:
|
|
19
|
+
- name: ExampleContract
|
|
20
|
+
file: ./Abi.json
|
|
21
|
+
eventHandlers:
|
|
22
|
+
- event: ExampleEvent(string)
|
|
23
|
+
handler: handleExampleEvent
|
|
24
|
+
templates:
|
|
25
|
+
- kind: near
|
|
26
|
+
name: ExampleTemplate
|
|
27
|
+
source:
|
|
28
|
+
abi: ExampleContract
|
|
29
|
+
mapping:
|
|
30
|
+
kind: ethereum/events
|
|
31
|
+
apiVersion: 0.0.5
|
|
32
|
+
language: wasm/assemblyscript
|
|
33
|
+
file: ./mapping.ts
|
|
34
|
+
entities:
|
|
35
|
+
- ExampleEntity
|
|
36
|
+
abis:
|
|
37
|
+
- name: ExampleContract
|
|
38
|
+
file: ./Abi.json
|
|
39
|
+
eventHandlers:
|
|
40
|
+
- event: ExampleEvent(string)
|
|
41
|
+
handler: handleExampleEvent
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
- Load subgraph from subgraph.yaml
|
|
2
|
+
✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml:
|
|
3
|
+
|
|
4
|
+
Path: /
|
|
5
|
+
Conflicting protocol kinds used in data sources and templates:
|
|
6
|
+
Data sources and templates using 'ethereum':
|
|
7
|
+
- ExampleSubgraph
|
|
8
|
+
Data sources and templates using 'near':
|
|
9
|
+
- ExampleTemplate
|
|
10
|
+
Recommendation: Make all data sources and templates use the same protocol kind.
|
|
@@ -205,6 +205,15 @@ describe('Validation', () => {
|
|
|
205
205
|
},
|
|
206
206
|
)
|
|
207
207
|
|
|
208
|
+
cliTest(
|
|
209
|
+
'Conflicting protocol names',
|
|
210
|
+
['codegen', '--skip-migrations'],
|
|
211
|
+
'validation/conflicting-protocol-names',
|
|
212
|
+
{
|
|
213
|
+
exitCode: 1,
|
|
214
|
+
},
|
|
215
|
+
)
|
|
216
|
+
|
|
208
217
|
cliTest(
|
|
209
218
|
'Invalid @fulltext directive',
|
|
210
219
|
['codegen', '--skip-migrations'],
|