@graphprotocol/graph-cli 0.27.0 → 0.28.0
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/tendermint.ts +554 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/collections.ts +52 -2
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/numbers.ts +11 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/value.ts +47 -0
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +150 -1
- package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +2 -0
- 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 +2 -0
- 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/src/codegen/schema.js +104 -25
- package/src/codegen/schema.test.js +3 -7
- package/src/protocols/index.js +24 -0
- package/src/protocols/tendermint/contract.js +12 -0
- package/src/protocols/tendermint/manifest.graphql +64 -0
- package/src/protocols/tendermint/subgraph.js +20 -0
- package/src/scaffold/index.js +1 -1
- package/src/validation/manifest.js +17 -0
- package/src/validation/schema.js +120 -119
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { BigDecimal } from '../common/numbers'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Bytes,
|
|
4
|
+
TypedMapEntry,
|
|
5
|
+
Entity,
|
|
6
|
+
TypedMap,
|
|
7
|
+
Result,
|
|
8
|
+
Wrapped,
|
|
9
|
+
} from '../common/collections'
|
|
3
10
|
import { JSONValue, Value } from '../common/value'
|
|
4
11
|
import { ethereum } from '../chain/ethereum'
|
|
5
12
|
import { near } from '../chain/near'
|
|
13
|
+
import { tendermint } from '../chain/tendermint'
|
|
6
14
|
|
|
7
15
|
export enum TypeId {
|
|
8
16
|
String = 0,
|
|
@@ -92,6 +100,53 @@ export enum TypeId {
|
|
|
92
100
|
NearChunkHeader = 84,
|
|
93
101
|
NearBlock = 85,
|
|
94
102
|
NearReceiptWithOutcome = 86,
|
|
103
|
+
TendermintArrayEventTx = 87,
|
|
104
|
+
TendermintArrayEvent = 88,
|
|
105
|
+
TendermintArrayCommitSig = 89,
|
|
106
|
+
TendermintArrayBytes = 90,
|
|
107
|
+
TendermintArrayEvidence = 91,
|
|
108
|
+
TendermintArrayEventAttribute = 92,
|
|
109
|
+
TendermintBlockIDFlagEnum = 93,
|
|
110
|
+
TendermintSignedMsgTypeEnum = 94,
|
|
111
|
+
TendermintEventList = 95,
|
|
112
|
+
TendermintEventBlock = 96,
|
|
113
|
+
TendermintResponseBeginBlock = 97,
|
|
114
|
+
TendermintResponseEndBlock = 98,
|
|
115
|
+
TendermintValidatorUpdate = 99,
|
|
116
|
+
TendermintArrayValidatorUpdate = 100,
|
|
117
|
+
TendermintConsensusParams = 101,
|
|
118
|
+
TendermintBlockParams = 102,
|
|
119
|
+
TendermintEvidenceParams = 103,
|
|
120
|
+
TendermintValidatorParams = 104,
|
|
121
|
+
TendermintVersionParams = 105,
|
|
122
|
+
TendermintBlock = 106,
|
|
123
|
+
TendermintCommit = 107,
|
|
124
|
+
TendermintCommitSig = 108,
|
|
125
|
+
TendermintHeader = 109,
|
|
126
|
+
TendermintConsensus = 110,
|
|
127
|
+
TendermintBlockID = 111,
|
|
128
|
+
TendermintPartSetHeader = 112,
|
|
129
|
+
TendermintData = 113,
|
|
130
|
+
TendermintEvidence = 114,
|
|
131
|
+
TendermintDuplicateVoteEvidence = 115,
|
|
132
|
+
TendermintEventTx = 116,
|
|
133
|
+
TendermintEventVote = 117,
|
|
134
|
+
TendermintLightClientAttackEvidence = 118,
|
|
135
|
+
TendermintLightBlock = 119,
|
|
136
|
+
TendermintValidatorSet = 120,
|
|
137
|
+
TendermintSignedHeader = 121,
|
|
138
|
+
TendermintEvidenceList = 122,
|
|
139
|
+
TendermintValidator = 123,
|
|
140
|
+
TendermintArrayValidator = 124,
|
|
141
|
+
TendermintPublicKey = 125,
|
|
142
|
+
TendermintTxResult = 126,
|
|
143
|
+
TendermintResponseDeliverTx = 127,
|
|
144
|
+
TendermintEvent = 128,
|
|
145
|
+
TendermintEventAttribute = 129,
|
|
146
|
+
TendermintEventValidatorSetUpdates = 130,
|
|
147
|
+
TendermintDuration = 131,
|
|
148
|
+
TendermintTimestamp = 132,
|
|
149
|
+
TendermintEventData = 133,
|
|
95
150
|
}
|
|
96
151
|
|
|
97
152
|
export function id_of_type(typeId: TypeId): usize {
|
|
@@ -271,6 +326,100 @@ export function id_of_type(typeId: TypeId): usize {
|
|
|
271
326
|
return idof<near.Block>()
|
|
272
327
|
case TypeId.NearReceiptWithOutcome:
|
|
273
328
|
return idof<near.ReceiptWithOutcome>()
|
|
329
|
+
case TypeId.TendermintArrayEventTx:
|
|
330
|
+
return idof<Array<tendermint.EventTx>>()
|
|
331
|
+
case TypeId.TendermintArrayEvent:
|
|
332
|
+
return idof<Array<tendermint.Event>>()
|
|
333
|
+
case TypeId.TendermintArrayCommitSig:
|
|
334
|
+
return idof<Array<tendermint.CommitSig>>()
|
|
335
|
+
case TypeId.TendermintArrayBytes:
|
|
336
|
+
return idof<Array<Bytes>>()
|
|
337
|
+
case TypeId.TendermintArrayEvidence:
|
|
338
|
+
return idof<Array<tendermint.Evidence>>()
|
|
339
|
+
case TypeId.TendermintArrayEventAttribute:
|
|
340
|
+
return idof<Array<tendermint.EventAttribute>>()
|
|
341
|
+
case TypeId.TendermintBlockIDFlagEnum:
|
|
342
|
+
return idof<Array<tendermint.BlockIDFlag>>()
|
|
343
|
+
case TypeId.TendermintSignedMsgTypeEnum:
|
|
344
|
+
return idof<Array<tendermint.SignedMsgType>>()
|
|
345
|
+
case TypeId.TendermintEventList:
|
|
346
|
+
return idof<tendermint.EventList>()
|
|
347
|
+
case TypeId.TendermintEventBlock:
|
|
348
|
+
return idof<tendermint.EventBlock>()
|
|
349
|
+
case TypeId.TendermintResponseBeginBlock:
|
|
350
|
+
return idof<tendermint.ResponseBeginBlock>()
|
|
351
|
+
case TypeId.TendermintResponseEndBlock:
|
|
352
|
+
return idof<tendermint.ResponseEndBlock>()
|
|
353
|
+
case TypeId.TendermintValidatorUpdate:
|
|
354
|
+
return idof<tendermint.ValidatorUpdate>()
|
|
355
|
+
case TypeId.TendermintArrayValidatorUpdate:
|
|
356
|
+
return idof<Array<tendermint.ValidatorUpdate>>()
|
|
357
|
+
case TypeId.TendermintConsensusParams:
|
|
358
|
+
return idof<tendermint.ConsensusParams>()
|
|
359
|
+
case TypeId.TendermintBlockParams:
|
|
360
|
+
return idof<tendermint.BlockParams>()
|
|
361
|
+
case TypeId.TendermintEvidenceParams:
|
|
362
|
+
return idof<tendermint.EvidenceParams>()
|
|
363
|
+
case TypeId.TendermintValidatorParams:
|
|
364
|
+
return idof<tendermint.ValidatorParams>()
|
|
365
|
+
case TypeId.TendermintVersionParams:
|
|
366
|
+
return idof<tendermint.VersionParams>()
|
|
367
|
+
case TypeId.TendermintBlock:
|
|
368
|
+
return idof<tendermint.Block>()
|
|
369
|
+
case TypeId.TendermintCommit:
|
|
370
|
+
return idof<tendermint.Commit>()
|
|
371
|
+
case TypeId.TendermintCommitSig:
|
|
372
|
+
return idof<tendermint.CommitSig>()
|
|
373
|
+
case TypeId.TendermintHeader:
|
|
374
|
+
return idof<tendermint.Header>()
|
|
375
|
+
case TypeId.TendermintConsensus:
|
|
376
|
+
return idof<tendermint.Consensus>()
|
|
377
|
+
case TypeId.TendermintBlockID:
|
|
378
|
+
return idof<tendermint.BlockID>()
|
|
379
|
+
case TypeId.TendermintPartSetHeader:
|
|
380
|
+
return idof<tendermint.PartSetHeader>()
|
|
381
|
+
case TypeId.TendermintData:
|
|
382
|
+
return idof<tendermint.Data>()
|
|
383
|
+
case TypeId.TendermintEvidence:
|
|
384
|
+
return idof<tendermint.Evidence>()
|
|
385
|
+
case TypeId.TendermintDuplicateVoteEvidence:
|
|
386
|
+
return idof<tendermint.DuplicateVoteEvidence>()
|
|
387
|
+
case TypeId.TendermintEventTx:
|
|
388
|
+
return idof<tendermint.EventTx>()
|
|
389
|
+
case TypeId.TendermintEventVote:
|
|
390
|
+
return idof<tendermint.EventVote>()
|
|
391
|
+
case TypeId.TendermintLightClientAttackEvidence:
|
|
392
|
+
return idof<tendermint.LightClientAttackEvidence>()
|
|
393
|
+
case TypeId.TendermintLightBlock:
|
|
394
|
+
return idof<tendermint.LightBlock>()
|
|
395
|
+
case TypeId.TendermintValidatorSet:
|
|
396
|
+
return idof<tendermint.ValidatorSet>()
|
|
397
|
+
case TypeId.TendermintSignedHeader:
|
|
398
|
+
return idof<tendermint.SignedHeader>()
|
|
399
|
+
case TypeId.TendermintEvidenceList:
|
|
400
|
+
return idof<tendermint.EvidenceList>()
|
|
401
|
+
case TypeId.TendermintValidator:
|
|
402
|
+
return idof<tendermint.Validator>()
|
|
403
|
+
case TypeId.TendermintArrayValidator:
|
|
404
|
+
return idof<Array<tendermint.Validator>>()
|
|
405
|
+
case TypeId.TendermintPublicKey:
|
|
406
|
+
return idof<tendermint.PublicKey>()
|
|
407
|
+
case TypeId.TendermintTxResult:
|
|
408
|
+
return idof<tendermint.TxResult>()
|
|
409
|
+
case TypeId.TendermintResponseDeliverTx:
|
|
410
|
+
return idof<tendermint.ResponseDeliverTx>()
|
|
411
|
+
case TypeId.TendermintEvent:
|
|
412
|
+
return idof<tendermint.Event>()
|
|
413
|
+
case TypeId.TendermintEventAttribute:
|
|
414
|
+
return idof<tendermint.EventAttribute>()
|
|
415
|
+
case TypeId.TendermintEventValidatorSetUpdates:
|
|
416
|
+
return idof<tendermint.EventValidatorSetUpdates>()
|
|
417
|
+
case TypeId.TendermintDuration:
|
|
418
|
+
return idof<tendermint.Duration>()
|
|
419
|
+
case TypeId.TendermintTimestamp:
|
|
420
|
+
return idof<tendermint.Timestamp>()
|
|
421
|
+
case TypeId.TendermintEventData:
|
|
422
|
+
return idof<tendermint.EventData>()
|
|
274
423
|
default:
|
|
275
424
|
return 0
|
|
276
425
|
}
|
|
@@ -4,6 +4,8 @@ import './common/eager_offset'
|
|
|
4
4
|
export * from './chain/ethereum'
|
|
5
5
|
// NEAR support
|
|
6
6
|
export * from './chain/near'
|
|
7
|
+
// Tendermint support
|
|
8
|
+
export * from './chain/tendermint'
|
|
7
9
|
// Regular re-exports
|
|
8
10
|
export * from './common/numbers'
|
|
9
11
|
export * from './common/collections'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-ts",
|
|
3
3
|
"description": "TypeScript/AssemblyScript library for writing subgraph mappings for The Graph",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.26.0",
|
|
5
5
|
"module": "index.ts",
|
|
6
6
|
"types": "index.ts",
|
|
7
7
|
"main": "index.ts",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"lint": "prettier -c **/*.{js,ts}",
|
|
16
|
+
"format": "prettier --write -c **/*.{js,ts}",
|
|
16
17
|
"build": "asc --explicitStart --exportRuntime --runtime stub index.ts helper-functions.ts --lib graph-ts -b index.wasm",
|
|
17
18
|
"test": "node test/test.js"
|
|
18
19
|
}
|
|
@@ -31,6 +31,7 @@ async function main() {
|
|
|
31
31
|
fs.copyFileSync('common/value.ts', 'test/temp_lib/common/value.ts')
|
|
32
32
|
fs.copyFileSync('chain/ethereum.ts', 'test/temp_lib/chain/ethereum.ts')
|
|
33
33
|
fs.copyFileSync('chain/near.ts', 'test/temp_lib/chain/near.ts')
|
|
34
|
+
fs.copyFileSync('chain/tendermint.ts', 'test/temp_lib/chain/tendermint.ts')
|
|
34
35
|
fs.copyFileSync('index.ts', 'test/temp_lib/index.ts')
|
|
35
36
|
|
|
36
37
|
try {
|
|
@@ -63,6 +64,7 @@ async function main() {
|
|
|
63
64
|
fs.rmdirSync('test/temp_lib/common')
|
|
64
65
|
fs.unlinkSync('test/temp_lib/chain/ethereum.ts')
|
|
65
66
|
fs.unlinkSync('test/temp_lib/chain/near.ts')
|
|
67
|
+
fs.unlinkSync('test/temp_lib/chain/tendermint.ts')
|
|
66
68
|
fs.rmdirSync('test/temp_lib/chain')
|
|
67
69
|
fs.unlinkSync('test/temp_lib/index.ts')
|
|
68
70
|
fs.rmdirSync('test/temp_lib')
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"deploy-test": "../../bin/graph deploy test/basic-event-handlers --version-label v0.0.1 --ipfs http://localhost:15001 --node http://127.0.0.1:18020"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@graphprotocol/graph-ts": "0.
|
|
12
|
+
"@graphprotocol/graph-ts": "0.26.0",
|
|
13
13
|
"apollo-fetch": "^0.7.0"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
# yarn lockfile v1
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
"@graphprotocol/graph-ts@0.
|
|
6
|
-
version "0.
|
|
7
|
-
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.
|
|
8
|
-
integrity sha512-
|
|
5
|
+
"@graphprotocol/graph-ts@0.26.0":
|
|
6
|
+
version "0.26.0"
|
|
7
|
+
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.26.0.tgz#576f995531eebaca4374901aeaff499219e382e8"
|
|
8
|
+
integrity sha512-GW/emOJl+35MXgmIxTnUK7dJtPCaB9u5aAwoLVqJ8swogC794O92UrXMVrAJsherUriu+yI9bLMGmNPOIi60jw==
|
|
9
9
|
dependencies:
|
|
10
10
|
assemblyscript "0.19.10"
|
|
11
11
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
# yarn lockfile v1
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
"@graphprotocol/graph-ts@0.
|
|
6
|
-
version "0.
|
|
7
|
-
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.
|
|
8
|
-
integrity sha512-
|
|
5
|
+
"@graphprotocol/graph-ts@0.26.0":
|
|
6
|
+
version "0.26.0"
|
|
7
|
+
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.26.0.tgz#576f995531eebaca4374901aeaff499219e382e8"
|
|
8
|
+
integrity sha512-GW/emOJl+35MXgmIxTnUK7dJtPCaB9u5aAwoLVqJ8swogC794O92UrXMVrAJsherUriu+yI9bLMGmNPOIi60jw==
|
|
9
9
|
dependencies:
|
|
10
10
|
assemblyscript "0.19.10"
|
|
11
11
|
|
package/package.json
CHANGED
package/src/codegen/schema.js
CHANGED
|
@@ -5,6 +5,53 @@ const typesCodegen = require('./types')
|
|
|
5
5
|
|
|
6
6
|
const List = immutable.List
|
|
7
7
|
|
|
8
|
+
class IdField {
|
|
9
|
+
static BYTES = Symbol("Bytes")
|
|
10
|
+
static STRING = Symbol("String")
|
|
11
|
+
|
|
12
|
+
constructor(idField) {
|
|
13
|
+
const typeName = idField.getIn(['type', 'type', 'name', 'value'])
|
|
14
|
+
this.kind = typeName === "Bytes" ? IdField.BYTES : IdField.STRING
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
typeName() {
|
|
18
|
+
return this.kind === IdField.BYTES ? "Bytes" : "string"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
gqlTypeName() {
|
|
22
|
+
return this.kind === IdField.BYTES ? "Bytes" : "String"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
tsNamedType() {
|
|
26
|
+
return tsCodegen.namedType(this.typeName())
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
tsValueFrom() {
|
|
30
|
+
return this.kind === IdField.BYTES ? "Value.fromBytes(id)" : "Value.fromString(id)"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
tsValueKind() {
|
|
34
|
+
return this.kind === IdField.BYTES ? "ValueKind.BYTES" : "ValueKind.STRING"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
tsValueToString() {
|
|
38
|
+
return this.kind == IdField.BYTES ? "id.toBytes().toHexString()" : "id.toString()"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
tsToString() {
|
|
42
|
+
return this.kind == IdField.BYTES ? "id.toHexString()" : "id"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static fromFields(fields) {
|
|
46
|
+
const idField = fields.find(field => field.getIn(['name', 'value']) === 'id')
|
|
47
|
+
return new IdField(idField)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static fromTypeDef(def) {
|
|
51
|
+
return IdField.fromFields(def.get("fields"))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
8
55
|
module.exports = class SchemaCodeGenerator {
|
|
9
56
|
constructor(schema) {
|
|
10
57
|
this.schema = schema
|
|
@@ -52,12 +99,14 @@ module.exports = class SchemaCodeGenerator {
|
|
|
52
99
|
_generateEntityType(def) {
|
|
53
100
|
let name = def.getIn(['name', 'value'])
|
|
54
101
|
let klass = tsCodegen.klass(name, { export: true, extends: 'Entity' })
|
|
102
|
+
const fields = def.get('fields')
|
|
103
|
+
const idField = IdField.fromFields(fields)
|
|
55
104
|
|
|
56
105
|
// Generate and add a constructor
|
|
57
|
-
klass.addMethod(this._generateConstructor(name,
|
|
106
|
+
klass.addMethod(this._generateConstructor(name, fields))
|
|
58
107
|
|
|
59
108
|
// Generate and add save() and getById() methods
|
|
60
|
-
this._generateStoreMethods(name).forEach(method => klass.addMethod(method))
|
|
109
|
+
this._generateStoreMethods(name, idField).forEach(method => klass.addMethod(method))
|
|
61
110
|
|
|
62
111
|
// Generate and add entity field getters and setters
|
|
63
112
|
def
|
|
@@ -107,19 +156,20 @@ module.exports = class SchemaCodeGenerator {
|
|
|
107
156
|
}
|
|
108
157
|
|
|
109
158
|
_generateConstructor(entityName, fields) {
|
|
159
|
+
const idField = IdField.fromFields(fields)
|
|
110
160
|
return tsCodegen.method(
|
|
111
161
|
'constructor',
|
|
112
|
-
[tsCodegen.param('id',
|
|
162
|
+
[tsCodegen.param('id', idField.tsNamedType())],
|
|
113
163
|
undefined,
|
|
114
164
|
`
|
|
115
165
|
super()
|
|
116
|
-
this.set('id',
|
|
166
|
+
this.set('id', ${idField.tsValueFrom()})
|
|
117
167
|
${this._generateDefaultFieldValues(fields)}
|
|
118
168
|
`,
|
|
119
169
|
)
|
|
120
170
|
}
|
|
121
171
|
|
|
122
|
-
_generateStoreMethods(entityName) {
|
|
172
|
+
_generateStoreMethods(entityName, idField) {
|
|
123
173
|
return List.of(
|
|
124
174
|
tsCodegen.method(
|
|
125
175
|
'save',
|
|
@@ -127,23 +177,21 @@ module.exports = class SchemaCodeGenerator {
|
|
|
127
177
|
tsCodegen.namedType('void'),
|
|
128
178
|
`
|
|
129
179
|
let id = this.get('id')
|
|
130
|
-
assert(id != null,
|
|
180
|
+
assert(id != null,
|
|
181
|
+
'Cannot save ${entityName} entity without an ID')
|
|
131
182
|
if (id) {
|
|
132
|
-
assert(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
'Considering using .toHex() to convert the "id" to a string.'
|
|
136
|
-
)
|
|
137
|
-
store.set('${entityName}', id.toString(), this)
|
|
183
|
+
assert(id.kind == ${idField.tsValueKind()},
|
|
184
|
+
\`Entities of type ${entityName} must have an ID of type ${idField.gqlTypeName()} but the id '\${id.displayData()}' is of type \${id.displayKind()}\`)
|
|
185
|
+
store.set('${entityName}', ${idField.tsValueToString()}, this)
|
|
138
186
|
}`,
|
|
139
187
|
),
|
|
140
188
|
|
|
141
189
|
tsCodegen.staticMethod(
|
|
142
190
|
'load',
|
|
143
|
-
[tsCodegen.param('id', tsCodegen.namedType(
|
|
191
|
+
[tsCodegen.param('id', tsCodegen.namedType(idField.typeName()))],
|
|
144
192
|
tsCodegen.nullableType(tsCodegen.namedType(entityName)),
|
|
145
193
|
`
|
|
146
|
-
return changetype<${entityName} | null>(store.get('${entityName}',
|
|
194
|
+
return changetype<${entityName} | null>(store.get('${entityName}', ${idField.tsToString()}))
|
|
147
195
|
`,
|
|
148
196
|
),
|
|
149
197
|
)
|
|
@@ -194,13 +242,12 @@ module.exports = class SchemaCodeGenerator {
|
|
|
194
242
|
isArray &&
|
|
195
243
|
paramType.inner instanceof tsCodegen.NullableType
|
|
196
244
|
) {
|
|
197
|
-
let
|
|
198
|
-
let suggestedType = `${arrayTypeWithoutClosingBracked}!]`
|
|
245
|
+
let baseType = this._baseType(gqlType)
|
|
199
246
|
|
|
200
247
|
throw new Error(`
|
|
201
248
|
GraphQL schema can't have List's with Nullable members.
|
|
202
|
-
Error in '${name}' field of type '${
|
|
203
|
-
Suggestion: add an '!' to the member type of the List, change from '${
|
|
249
|
+
Error in '${name}' field of type '[${baseType}]'.
|
|
250
|
+
Suggestion: add an '!' to the member type of the List, change from '[${baseType}]' to '[${baseType}!]'`
|
|
204
251
|
)
|
|
205
252
|
}
|
|
206
253
|
|
|
@@ -212,7 +259,7 @@ Suggestion: add an '!' to the member type of the List, change from '${fieldValue
|
|
|
212
259
|
this.unset('${name}')
|
|
213
260
|
} else {
|
|
214
261
|
this.set('${name}', ${typesCodegen.valueFromAsc(
|
|
215
|
-
|
|
262
|
+
`<${paramTypeString}>value`,
|
|
216
263
|
fieldValueType,
|
|
217
264
|
)})
|
|
218
265
|
}
|
|
@@ -226,12 +273,44 @@ Suggestion: add an '!' to the member type of the List, change from '${fieldValue
|
|
|
226
273
|
)
|
|
227
274
|
}
|
|
228
275
|
|
|
276
|
+
_resolveFieldType(gqlType) {
|
|
277
|
+
let typeName = gqlType.getIn(['name', 'value'])
|
|
278
|
+
|
|
279
|
+
// If this is a reference to another type, the field has the type of
|
|
280
|
+
// the referred type's id field
|
|
281
|
+
const typeDef = this.schema.ast.get("definitions").
|
|
282
|
+
find(def => this._isEntityTypeDefinition(def) && def.getIn(["name", "value"]) === typeName)
|
|
283
|
+
if (typeDef) {
|
|
284
|
+
return IdField.fromTypeDef(typeDef).typeName()
|
|
285
|
+
} else {
|
|
286
|
+
return typeName
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Return the type that values for this field must have. For scalar
|
|
291
|
+
* types, that's the type from the subgraph schema. For references to
|
|
292
|
+
* other entity types, this is the same as the type of the id of the
|
|
293
|
+
* referred type, i.e., `string` or `Bytes`*/
|
|
229
294
|
_valueTypeFromGraphQl(gqlType) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
295
|
+
if (gqlType.get('kind') === 'NonNullType') {
|
|
296
|
+
return this._valueTypeFromGraphQl(gqlType.get('type'), false)
|
|
297
|
+
} else if (gqlType.get('kind') === 'ListType') {
|
|
298
|
+
return '[' + this._valueTypeFromGraphQl(gqlType.get('type')) + ']'
|
|
299
|
+
} else {
|
|
300
|
+
return this._resolveFieldType(gqlType)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Determine the base type of `gqlType` by removing any non-null
|
|
305
|
+
* constraints and using the type of elements of lists */
|
|
306
|
+
_baseType(gqlType) {
|
|
307
|
+
if (gqlType.get('kind') === 'NonNullType') {
|
|
308
|
+
return this._baseType(gqlType.get('type'))
|
|
309
|
+
} else if (gqlType.get('kind') === 'ListType') {
|
|
310
|
+
return this._baseType(gqlType.get('type'))
|
|
311
|
+
} else {
|
|
312
|
+
return gqlType.getIn(['name', 'value'])
|
|
313
|
+
}
|
|
235
314
|
}
|
|
236
315
|
|
|
237
316
|
_typeFromGraphQl(gqlType, nullable = true, nullablePrimitive = false) {
|
|
@@ -243,7 +322,7 @@ Suggestion: add an '!' to the member type of the List, change from '${fieldValue
|
|
|
243
322
|
} else {
|
|
244
323
|
// NamedType
|
|
245
324
|
let type = tsCodegen.namedType(
|
|
246
|
-
typesCodegen.ascTypeForValue(
|
|
325
|
+
typesCodegen.ascTypeForValue(this._resolveFieldType(gqlType)),
|
|
247
326
|
)
|
|
248
327
|
|
|
249
328
|
// Will not wrap primitives into NullableType by default.
|
|
@@ -129,9 +129,7 @@ describe('Schema code generator', () => {
|
|
|
129
129
|
if (id) {
|
|
130
130
|
assert(
|
|
131
131
|
id.kind == ValueKind.STRING,
|
|
132
|
-
|
|
133
|
-
'Considering using .toHex() to convert the "id" to a string.'
|
|
134
|
-
)
|
|
132
|
+
\`Entities of type Account must have an ID of type String but the id '\${id.displayData()}' is of type \${id.displayKind()}\`)
|
|
135
133
|
store.set('Account', id.toString(), this)
|
|
136
134
|
}
|
|
137
135
|
`,
|
|
@@ -279,7 +277,7 @@ describe('Schema code generator', () => {
|
|
|
279
277
|
body: `
|
|
280
278
|
super()
|
|
281
279
|
this.set('id', Value.fromString(id))
|
|
282
|
-
|
|
280
|
+
|
|
283
281
|
this.set('amount', Value.fromBigInt(BigInt.zero()))
|
|
284
282
|
this.set('account', Value.fromString(''))
|
|
285
283
|
`,
|
|
@@ -294,9 +292,7 @@ describe('Schema code generator', () => {
|
|
|
294
292
|
if (id) {
|
|
295
293
|
assert(
|
|
296
294
|
id.kind == ValueKind.STRING,
|
|
297
|
-
|
|
298
|
-
'Considering using .toHex() to convert the "id" to a string.'
|
|
299
|
-
)
|
|
295
|
+
\`Entities of type Wallet must have an ID of type String but the id '\${id.displayData()}' is of type \${id.displayKind()}\`)
|
|
300
296
|
store.set('Wallet', id.toString(), this)
|
|
301
297
|
}
|
|
302
298
|
`,
|
package/src/protocols/index.js
CHANGED
|
@@ -4,8 +4,10 @@ const EthereumTemplateCodeGen = require('./ethereum/codegen/template')
|
|
|
4
4
|
const EthereumABI = require('./ethereum/abi')
|
|
5
5
|
const EthereumSubgraph = require('./ethereum/subgraph')
|
|
6
6
|
const NearSubgraph = require('./near/subgraph')
|
|
7
|
+
const TendermintSubgraph = require('./tendermint/subgraph')
|
|
7
8
|
const EthereumContract = require('./ethereum/contract')
|
|
8
9
|
const NearContract = require('./near/contract')
|
|
10
|
+
const TendermintContract = require('./tendermint/contract')
|
|
9
11
|
const EthereumManifestScaffold = require('./ethereum/scaffold/manifest')
|
|
10
12
|
const NearManifestScaffold = require('./near/scaffold/manifest')
|
|
11
13
|
const EthereumMappingScaffold = require('./ethereum/scaffold/mapping')
|
|
@@ -27,6 +29,7 @@ module.exports = class Protocol {
|
|
|
27
29
|
// New networks (or protocol perhaps) shouldn't have the `/contract` anymore (unless a new case makes use of it).
|
|
28
30
|
ethereum: ['ethereum', 'ethereum/contract'],
|
|
29
31
|
near: ['near'],
|
|
32
|
+
tendermint: ['tendermint']
|
|
30
33
|
})
|
|
31
34
|
}
|
|
32
35
|
|
|
@@ -61,6 +64,7 @@ module.exports = class Protocol {
|
|
|
61
64
|
'aurora-testnet',
|
|
62
65
|
],
|
|
63
66
|
near: ['near-mainnet', 'near-testnet'],
|
|
67
|
+
tendermint: ['cosmoshub-4']
|
|
64
68
|
})
|
|
65
69
|
}
|
|
66
70
|
|
|
@@ -76,6 +80,8 @@ module.exports = class Protocol {
|
|
|
76
80
|
return 'Ethereum'
|
|
77
81
|
case 'near':
|
|
78
82
|
return 'NEAR'
|
|
83
|
+
case 'tendermint':
|
|
84
|
+
return 'Tendermint'
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
|
|
@@ -93,6 +99,8 @@ module.exports = class Protocol {
|
|
|
93
99
|
return true
|
|
94
100
|
case 'near':
|
|
95
101
|
return false
|
|
102
|
+
case 'tendermint':
|
|
103
|
+
return false
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
|
|
@@ -102,6 +110,8 @@ module.exports = class Protocol {
|
|
|
102
110
|
return true
|
|
103
111
|
case 'near':
|
|
104
112
|
return false
|
|
113
|
+
case 'tendermint':
|
|
114
|
+
return false
|
|
105
115
|
}
|
|
106
116
|
}
|
|
107
117
|
|
|
@@ -111,6 +121,8 @@ module.exports = class Protocol {
|
|
|
111
121
|
return true
|
|
112
122
|
case 'near':
|
|
113
123
|
return false
|
|
124
|
+
case 'tendermint':
|
|
125
|
+
return false
|
|
114
126
|
}
|
|
115
127
|
}
|
|
116
128
|
|
|
@@ -120,6 +132,8 @@ module.exports = class Protocol {
|
|
|
120
132
|
return new EthereumTypeGenerator(options)
|
|
121
133
|
case 'near':
|
|
122
134
|
return null
|
|
135
|
+
case 'tendermint':
|
|
136
|
+
return null
|
|
123
137
|
}
|
|
124
138
|
}
|
|
125
139
|
|
|
@@ -144,6 +158,8 @@ module.exports = class Protocol {
|
|
|
144
158
|
return EthereumABI
|
|
145
159
|
case 'near':
|
|
146
160
|
return null
|
|
161
|
+
case 'tendermint':
|
|
162
|
+
return null
|
|
147
163
|
}
|
|
148
164
|
}
|
|
149
165
|
|
|
@@ -155,6 +171,8 @@ module.exports = class Protocol {
|
|
|
155
171
|
return new EthereumSubgraph(optionsWithProtocol)
|
|
156
172
|
case 'near':
|
|
157
173
|
return new NearSubgraph(optionsWithProtocol)
|
|
174
|
+
case 'tendermint':
|
|
175
|
+
return new TendermintSubgraph(optionsWithProtocol)
|
|
158
176
|
default:
|
|
159
177
|
throw new Error(`Data sources with kind '${this.name}' are not supported yet`)
|
|
160
178
|
}
|
|
@@ -166,6 +184,8 @@ module.exports = class Protocol {
|
|
|
166
184
|
return EthereumContract
|
|
167
185
|
case 'near':
|
|
168
186
|
return NearContract
|
|
187
|
+
case 'tendermint':
|
|
188
|
+
return TendermintContract
|
|
169
189
|
}
|
|
170
190
|
}
|
|
171
191
|
|
|
@@ -175,6 +195,8 @@ module.exports = class Protocol {
|
|
|
175
195
|
return EthereumManifestScaffold
|
|
176
196
|
case 'near':
|
|
177
197
|
return NearManifestScaffold
|
|
198
|
+
case 'tendermint':
|
|
199
|
+
return null
|
|
178
200
|
}
|
|
179
201
|
}
|
|
180
202
|
|
|
@@ -184,6 +206,8 @@ module.exports = class Protocol {
|
|
|
184
206
|
return EthereumMappingScaffold
|
|
185
207
|
case 'near':
|
|
186
208
|
return NearMappingScaffold
|
|
209
|
+
case 'tendermint':
|
|
210
|
+
return null
|
|
187
211
|
}
|
|
188
212
|
}
|
|
189
213
|
}
|