@graphprotocol/graph-cli 0.37.1 → 0.37.2-alpha-20221219142030-0cf2a37
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 +1 -2
- package/src/codegen/schema.js +49 -58
- package/src/codegen/schema.test.js +32 -27
- package/src/codegen/template.js +1 -2
- package/src/codegen/types/conversions.js +43 -14
- package/src/codegen/types/index.js +20 -23
- package/src/codegen/typescript.js +0 -3
- package/src/command-helpers/abi.js +2 -3
- package/src/command-helpers/data-sources.js +3 -4
- package/src/command-helpers/scaffold.js +18 -14
- package/src/command-helpers/spinner.js +0 -1
- package/src/commands/add.js +42 -25
- package/src/compiler/index.js +12 -13
- package/src/protocols/arweave/subgraph.js +2 -7
- package/src/protocols/cosmos/subgraph.js +2 -9
- package/src/protocols/ethereum/abi.js +6 -7
- package/src/protocols/ethereum/codegen/abi.js +217 -223
- package/src/protocols/ethereum/codegen/abi.test.js +15 -16
- package/src/protocols/ethereum/subgraph.js +55 -67
- package/src/protocols/ethereum/type-generator.js +16 -25
- package/src/protocols/index.js +5 -6
- package/src/protocols/near/subgraph.js +3 -5
- package/src/protocols/substreams/subgraph.js +2 -4
- package/src/scaffold/cosmos.test.js +0 -1
- package/src/scaffold/ethereum.test.js +2 -3
- package/src/scaffold/near.test.js +0 -1
- package/src/schema.js +1 -2
- package/src/subgraph.js +44 -53
- package/src/type-generator.js +6 -7
- package/src/validation/contract.js +6 -11
- package/src/validation/manifest.js +77 -84
- package/src/validation/schema.js +284 -294
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const immutable = require('immutable')
|
|
2
1
|
const ABI = require('./abi')
|
|
3
2
|
const DataSourcesExtractor = require('../../command-helpers/data-sources')
|
|
4
3
|
|
|
@@ -16,7 +15,10 @@ module.exports = class EthereumSubgraph {
|
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
validateAbis() {
|
|
19
|
-
const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
|
|
18
|
+
const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
|
|
19
|
+
this.manifest,
|
|
20
|
+
this.protocol,
|
|
21
|
+
)
|
|
20
22
|
|
|
21
23
|
return dataSourcesAndTemplates.reduce(
|
|
22
24
|
(errors, dataSourceOrTemplate) =>
|
|
@@ -26,18 +28,18 @@ module.exports = class EthereumSubgraph {
|
|
|
26
28
|
dataSourceOrTemplate.get('path'),
|
|
27
29
|
),
|
|
28
30
|
),
|
|
29
|
-
|
|
31
|
+
[],
|
|
30
32
|
)
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
validateDataSourceAbis(dataSource, path) {
|
|
34
36
|
// Validate that the the "source > abi" reference of all data sources
|
|
35
37
|
// points to an existing ABI in the data source ABIs
|
|
36
|
-
let abiName = dataSource.
|
|
37
|
-
let abiNames = dataSource.
|
|
38
|
+
let abiName = dataSource.source?.abi
|
|
39
|
+
let abiNames = dataSource.mapping?.abis.map(abi => abi.get('name'))
|
|
38
40
|
let nameErrors = abiNames.includes(abiName)
|
|
39
|
-
?
|
|
40
|
-
:
|
|
41
|
+
? []
|
|
42
|
+
: [
|
|
41
43
|
{
|
|
42
44
|
path: [...path, 'source', 'abi'],
|
|
43
45
|
message: `\
|
|
@@ -48,61 +50,57 @@ ${abiNames
|
|
|
48
50
|
.map(name => `- ${name}`)
|
|
49
51
|
.join('\n')}`,
|
|
50
52
|
},
|
|
51
|
-
]
|
|
53
|
+
]
|
|
52
54
|
|
|
53
55
|
// Validate that all ABI files are valid
|
|
54
|
-
let fileErrors = dataSource
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}),
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
}, immutable.List())
|
|
56
|
+
let fileErrors = dataSource.mapping?.abis.reduce((errors, abi, abiIndex) => {
|
|
57
|
+
try {
|
|
58
|
+
ABI.load(abi.get('name'), this.resolveFile(abi.get('file')))
|
|
59
|
+
return errors
|
|
60
|
+
} catch (e) {
|
|
61
|
+
return errors.push({
|
|
62
|
+
path: [...path, 'mapping', 'abis', abiIndex, 'file'],
|
|
63
|
+
message: e.message,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}, [])
|
|
69
67
|
|
|
70
68
|
return nameErrors.concat(fileErrors)
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
validateEvents() {
|
|
74
|
-
const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
|
|
72
|
+
const dataSourcesAndTemplates = DataSourcesExtractor.fromManifest(
|
|
73
|
+
this.manifest,
|
|
74
|
+
this.protocol,
|
|
75
|
+
)
|
|
75
76
|
|
|
76
|
-
return dataSourcesAndTemplates
|
|
77
|
-
.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, immutable.List())
|
|
77
|
+
return dataSourcesAndTemplates.reduce((errors, dataSourceOrTemplate) => {
|
|
78
|
+
return errors.concat(
|
|
79
|
+
this.validateDataSourceEvents(
|
|
80
|
+
dataSourceOrTemplate.get('dataSource'),
|
|
81
|
+
dataSourceOrTemplate.get('path'),
|
|
82
|
+
),
|
|
83
|
+
)
|
|
84
|
+
}, [])
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
validateDataSourceEvents(dataSource, path) {
|
|
88
88
|
let abi
|
|
89
89
|
try {
|
|
90
90
|
// Resolve the source ABI name into a real ABI object
|
|
91
|
-
let abiName = dataSource.
|
|
92
|
-
let abiEntry = dataSource
|
|
93
|
-
.getIn(['mapping', 'abis'])
|
|
94
|
-
.find(abi => abi.get('name') === abiName)
|
|
91
|
+
let abiName = dataSource.source?.abi
|
|
92
|
+
let abiEntry = dataSource.mapping?.abis.find(abi => abi.get('name') === abiName)
|
|
95
93
|
abi = ABI.load(abiEntry.get('name'), this.resolveFile(abiEntry.get('file')))
|
|
96
94
|
} catch (_) {
|
|
97
95
|
// Ignore errors silently; we can't really say anything about
|
|
98
96
|
// the events if the ABI can't even be loaded
|
|
99
|
-
return
|
|
97
|
+
return []
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
// Obtain event signatures from the mapping
|
|
103
|
-
let manifestEvents = dataSource
|
|
104
|
-
.
|
|
105
|
-
|
|
101
|
+
let manifestEvents = (dataSource.mapping?.eventHandlers || []).map(handler =>
|
|
102
|
+
handler.get('event'),
|
|
103
|
+
)
|
|
106
104
|
|
|
107
105
|
// Obtain event signatures from the ABI
|
|
108
106
|
let abiEvents = abi.eventSignatures()
|
|
@@ -113,19 +111,17 @@ ${abiNames
|
|
|
113
111
|
(errors, manifestEvent, index) =>
|
|
114
112
|
abiEvents.includes(manifestEvent)
|
|
115
113
|
? errors
|
|
116
|
-
: errors.push(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
message: `\
|
|
114
|
+
: errors.push({
|
|
115
|
+
path: [...path, 'eventHandlers', index],
|
|
116
|
+
message: `\
|
|
120
117
|
Event with signature '${manifestEvent}' not present in ABI '${abi.name}'.
|
|
121
118
|
Available events:
|
|
122
119
|
${abiEvents
|
|
123
120
|
.sort()
|
|
124
121
|
.map(event => `- ${event}`)
|
|
125
122
|
.join('\n')}`,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
immutable.List(),
|
|
123
|
+
}),
|
|
124
|
+
[],
|
|
129
125
|
)
|
|
130
126
|
}
|
|
131
127
|
|
|
@@ -139,10 +135,8 @@ ${abiEvents
|
|
|
139
135
|
let abi
|
|
140
136
|
try {
|
|
141
137
|
// Resolve the source ABI name into a real ABI object
|
|
142
|
-
let abiName = dataSource.
|
|
143
|
-
let abiEntry = dataSource
|
|
144
|
-
.getIn(['mapping', 'abis'])
|
|
145
|
-
.find(abi => abi.get('name') === abiName)
|
|
138
|
+
let abiName = dataSource.source?.abi
|
|
139
|
+
let abiEntry = dataSource.mapping?.abis.find(abi => abi.get('name') === abiName)
|
|
146
140
|
abi = ABI.load(abiEntry.get('name'), this.resolveFile(abiEntry.get('file')))
|
|
147
141
|
} catch (e) {
|
|
148
142
|
// Ignore errors silently; we can't really say anything about
|
|
@@ -151,9 +145,9 @@ ${abiEvents
|
|
|
151
145
|
}
|
|
152
146
|
|
|
153
147
|
// Obtain event signatures from the mapping
|
|
154
|
-
let manifestFunctions = dataSource
|
|
155
|
-
.
|
|
156
|
-
|
|
148
|
+
let manifestFunctions = (dataSource.mapping?.callHandlers || []).map(handler =>
|
|
149
|
+
handler.get('function'),
|
|
150
|
+
)
|
|
157
151
|
|
|
158
152
|
// Obtain event signatures from the ABI
|
|
159
153
|
let abiFunctions = abi.callFunctionSignatures()
|
|
@@ -164,28 +158,22 @@ ${abiEvents
|
|
|
164
158
|
(errors, manifestFunction, index) =>
|
|
165
159
|
abiFunctions.includes(manifestFunction)
|
|
166
160
|
? errors
|
|
167
|
-
: errors.push(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
message: `\
|
|
161
|
+
: errors.push({
|
|
162
|
+
path: [...path, index],
|
|
163
|
+
message: `\
|
|
171
164
|
Call function with signature '${manifestFunction}' not present in ABI '${abi.name}'.
|
|
172
165
|
Available call functions:
|
|
173
166
|
${abiFunctions
|
|
174
167
|
.sort()
|
|
175
168
|
.map(tx => `- ${tx}`)
|
|
176
169
|
.join('\n')}`,
|
|
177
|
-
|
|
178
|
-
),
|
|
170
|
+
}),
|
|
179
171
|
errors,
|
|
180
172
|
)
|
|
181
|
-
},
|
|
173
|
+
}, [])
|
|
182
174
|
}
|
|
183
175
|
|
|
184
176
|
handlerTypes() {
|
|
185
|
-
return
|
|
186
|
-
'blockHandlers',
|
|
187
|
-
'callHandlers',
|
|
188
|
-
'eventHandlers',
|
|
189
|
-
])
|
|
177
|
+
return ['blockHandlers', 'callHandlers', 'eventHandlers']
|
|
190
178
|
}
|
|
191
179
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const fs = require('fs-extra')
|
|
2
2
|
const path = require('path')
|
|
3
|
-
const immutable = require('immutable')
|
|
4
3
|
const prettier = require('prettier')
|
|
5
4
|
const ABI = require('./abi')
|
|
6
5
|
const { step, withSpinner } = require('../../command-helpers/spinner')
|
|
@@ -24,21 +23,19 @@ module.exports = class EthereumTypeGenerator {
|
|
|
24
23
|
.get('dataSources')
|
|
25
24
|
.reduce(
|
|
26
25
|
(abis, dataSource) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
dataSource.mapping?.abis.reduce(
|
|
27
|
+
(abis, abi) =>
|
|
28
|
+
abis.push(
|
|
29
|
+
this._loadABI(
|
|
30
|
+
dataSource,
|
|
31
|
+
abi.get('name'),
|
|
32
|
+
abi.get('file'),
|
|
33
|
+
spinner,
|
|
34
|
+
),
|
|
35
|
+
),
|
|
36
|
+
abis,
|
|
38
37
|
),
|
|
39
|
-
|
|
40
|
-
),
|
|
41
|
-
immutable.List(),
|
|
38
|
+
[],
|
|
42
39
|
)
|
|
43
40
|
} catch (e) {
|
|
44
41
|
throw Error(`Failed to load contract ABIs: ${e.message}`)
|
|
@@ -68,8 +65,8 @@ module.exports = class EthereumTypeGenerator {
|
|
|
68
65
|
`Warnings while loading data source template ABIs`,
|
|
69
66
|
async spinner => {
|
|
70
67
|
let abis = []
|
|
71
|
-
for (let template of subgraph.get('templates',
|
|
72
|
-
for (let abi of template.
|
|
68
|
+
for (let template of subgraph.get('templates', [])) {
|
|
69
|
+
for (let abi of template.mapping?.abis) {
|
|
73
70
|
abis.push(
|
|
74
71
|
this._loadDataSourceTemplateABI(
|
|
75
72
|
template,
|
|
@@ -89,11 +86,7 @@ module.exports = class EthereumTypeGenerator {
|
|
|
89
86
|
try {
|
|
90
87
|
if (this.sourceDir) {
|
|
91
88
|
let absolutePath = path.resolve(this.sourceDir, maybeRelativePath)
|
|
92
|
-
step(
|
|
93
|
-
spinner,
|
|
94
|
-
`Load data source template ABI from`,
|
|
95
|
-
displayPath(absolutePath),
|
|
96
|
-
)
|
|
89
|
+
step(spinner, `Load data source template ABI from`, displayPath(absolutePath))
|
|
97
90
|
return { template, abi: ABI.load(name, absolutePath) }
|
|
98
91
|
} else {
|
|
99
92
|
return { template, abi: ABI.load(name, maybeRelativePath) }
|
|
@@ -170,9 +163,7 @@ module.exports = class EthereumTypeGenerator {
|
|
|
170
163
|
step(
|
|
171
164
|
spinner,
|
|
172
165
|
`Generate types for data source template ABI:`,
|
|
173
|
-
`${abi.template.get('name')} > ${abi.abi.name} (${displayPath(
|
|
174
|
-
abi.abi.file,
|
|
175
|
-
)})`,
|
|
166
|
+
`${abi.template.get('name')} > ${abi.abi.name} (${displayPath(abi.abi.file)})`,
|
|
176
167
|
)
|
|
177
168
|
|
|
178
169
|
let codeGenerator = abi.abi.codeGenerator()
|
package/src/protocols/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const immutable = require('immutable')
|
|
2
1
|
const ArweaveSubgraph = require('./arweave/subgraph')
|
|
3
2
|
const EthereumTypeGenerator = require('./ethereum/type-generator')
|
|
4
3
|
const EthereumTemplateCodeGen = require('./ethereum/codegen/template')
|
|
@@ -54,7 +53,7 @@ class Protocol {
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
static availableProtocols() {
|
|
57
|
-
return
|
|
56
|
+
return Object.freeze({
|
|
58
57
|
// `ethereum/contract` is kept for backwards compatibility.
|
|
59
58
|
// New networks (or protocol perhaps) shouldn't have the `/contract` anymore (unless a new case makes use of it).
|
|
60
59
|
arweave: ['arweave'],
|
|
@@ -66,7 +65,7 @@ class Protocol {
|
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
static availableNetworks() {
|
|
69
|
-
let networks =
|
|
68
|
+
let networks = {
|
|
70
69
|
arweave: ['arweave-mainnet'],
|
|
71
70
|
ethereum: [
|
|
72
71
|
'mainnet',
|
|
@@ -106,14 +105,14 @@ class Protocol {
|
|
|
106
105
|
'juno-1',
|
|
107
106
|
'uni-3', // Juno testnet
|
|
108
107
|
],
|
|
109
|
-
}
|
|
108
|
+
}
|
|
110
109
|
|
|
111
110
|
let allNetworks = []
|
|
112
111
|
networks.forEach(value => {
|
|
113
112
|
allNetworks.push(...value)
|
|
114
113
|
})
|
|
115
114
|
|
|
116
|
-
networks
|
|
115
|
+
networks['substreams'] = allNetworks
|
|
117
116
|
|
|
118
117
|
return networks
|
|
119
118
|
}
|
|
@@ -132,7 +131,7 @@ class Protocol {
|
|
|
132
131
|
// for the given protocol instance (this).
|
|
133
132
|
isValidKindName(kind) {
|
|
134
133
|
return Protocol.availableProtocols()
|
|
135
|
-
.get(this.name,
|
|
134
|
+
.get(this.name, [])
|
|
136
135
|
.includes(kind)
|
|
137
136
|
}
|
|
138
137
|
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const immutable = require('immutable')
|
|
2
|
-
|
|
3
1
|
module.exports = class NearSubgraph {
|
|
4
2
|
constructor(options = {}) {
|
|
5
3
|
this.manifest = options.manifest
|
|
@@ -8,13 +6,13 @@ module.exports = class NearSubgraph {
|
|
|
8
6
|
}
|
|
9
7
|
|
|
10
8
|
validateManifest() {
|
|
11
|
-
return
|
|
9
|
+
return []
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
handlerTypes() {
|
|
15
|
-
return
|
|
13
|
+
return [
|
|
16
14
|
'blockHandlers',
|
|
17
15
|
'receiptHandlers',
|
|
18
|
-
]
|
|
16
|
+
]
|
|
19
17
|
}
|
|
20
18
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const immutable = require('immutable')
|
|
2
|
-
|
|
3
1
|
module.exports = class SubstreamsSubgraph {
|
|
4
2
|
constructor(options = {}) {
|
|
5
3
|
this.manifest = options.manifest
|
|
@@ -8,10 +6,10 @@ module.exports = class SubstreamsSubgraph {
|
|
|
8
6
|
}
|
|
9
7
|
|
|
10
8
|
validateManifest() {
|
|
11
|
-
return
|
|
9
|
+
return []
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
handlerTypes() {
|
|
15
|
-
return
|
|
13
|
+
return []
|
|
16
14
|
}
|
|
17
15
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const ABI = require('../protocols/ethereum/abi')
|
|
2
|
-
const immutable = require('immutable')
|
|
3
2
|
const Scaffold = require('./')
|
|
4
3
|
const Protocol = require('../protocols')
|
|
5
4
|
|
|
@@ -61,12 +60,12 @@ const TEST_CALLABLE_FUNCTIONS = [
|
|
|
61
60
|
const TEST_ABI = new ABI(
|
|
62
61
|
'Contract',
|
|
63
62
|
undefined,
|
|
64
|
-
|
|
63
|
+
[
|
|
65
64
|
TEST_EVENT,
|
|
66
65
|
OVERLOADED_EVENT,
|
|
67
66
|
TEST_CONTRACT,
|
|
68
67
|
...TEST_CALLABLE_FUNCTIONS,
|
|
69
|
-
]
|
|
68
|
+
],
|
|
70
69
|
)
|
|
71
70
|
|
|
72
71
|
const protocol = new Protocol('ethereum')
|
package/src/schema.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
let fs = require('fs-extra')
|
|
2
2
|
let graphql = require('graphql/language')
|
|
3
|
-
let immutable = require('immutable')
|
|
4
3
|
|
|
5
4
|
let SchemaCodeGenerator = require('./codegen/schema')
|
|
6
5
|
|
|
@@ -18,6 +17,6 @@ module.exports = class Schema {
|
|
|
18
17
|
static async load(filename) {
|
|
19
18
|
let document = await fs.readFile(filename, 'utf-8')
|
|
20
19
|
let ast = graphql.parse(document)
|
|
21
|
-
return new Schema(filename, document,
|
|
20
|
+
return new Schema(filename, document, ast)
|
|
22
21
|
}
|
|
23
22
|
}
|
package/src/subgraph.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
let fs = require('fs-extra')
|
|
2
|
-
let immutable = require('immutable')
|
|
3
2
|
let path = require('path')
|
|
4
3
|
let yaml = require('yaml')
|
|
5
4
|
let { strOptions } = require('yaml/types')
|
|
@@ -43,12 +42,12 @@ module.exports = class Subgraph {
|
|
|
43
42
|
static async validate(data, protocol, { resolveFile }) {
|
|
44
43
|
subgraphDebug(`Validating Subgraph with protocol "%s"`, protocol)
|
|
45
44
|
if (protocol.name == null) {
|
|
46
|
-
return
|
|
45
|
+
return [
|
|
47
46
|
{
|
|
48
47
|
path: [],
|
|
49
48
|
message: `Unable to determine for which protocol manifest file is built for. Ensure you have at least one 'dataSources' and/or 'templates' elements defined in your subgraph.`,
|
|
50
49
|
},
|
|
51
|
-
]
|
|
50
|
+
]
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
// Parse the default subgraph schema
|
|
@@ -69,7 +68,7 @@ module.exports = class Subgraph {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
static validateSchema(manifest, { resolveFile }) {
|
|
72
|
-
let filename = resolveFile(manifest.
|
|
71
|
+
let filename = resolveFile(manifest.schema?.file)
|
|
73
72
|
let errors = validation.validateSchema(filename)
|
|
74
73
|
|
|
75
74
|
if (errors.size > 0) {
|
|
@@ -106,29 +105,29 @@ module.exports = class Subgraph {
|
|
|
106
105
|
const repository = manifest.get('repository')
|
|
107
106
|
|
|
108
107
|
return /^https:\/\/github\.com\/graphprotocol\/example-subgraphs?$/.test(repository)
|
|
109
|
-
?
|
|
110
|
-
|
|
108
|
+
? [
|
|
109
|
+
{
|
|
111
110
|
path: ['repository'],
|
|
112
111
|
message: `\
|
|
113
112
|
The repository is still set to ${repository}.
|
|
114
113
|
Please replace it with a link to your subgraph source code.`,
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
:
|
|
114
|
+
},
|
|
115
|
+
]
|
|
116
|
+
: []
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
static validateDescription(manifest, { resolveFile }) {
|
|
121
120
|
// TODO: Maybe implement this in the future for each protocol example description
|
|
122
121
|
return manifest.get('description', '').startsWith('Gravatar for ')
|
|
123
|
-
?
|
|
124
|
-
|
|
122
|
+
? [
|
|
123
|
+
{
|
|
125
124
|
path: ['description'],
|
|
126
125
|
message: `\
|
|
127
126
|
The description is still the one from the example subgraph.
|
|
128
127
|
Please update it to tell users more about your subgraph.`,
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
:
|
|
128
|
+
},
|
|
129
|
+
]
|
|
130
|
+
: []
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
static validateHandlers(manifest, protocol, protocolSubgraph) {
|
|
@@ -151,27 +150,25 @@ Please update it to tell users more about your subgraph.`,
|
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
const areAllHandlersEmpty = handlerTypes
|
|
154
|
-
.map(handlerType => mapping.get(handlerType,
|
|
153
|
+
.map(handlerType => mapping.get(handlerType, []))
|
|
155
154
|
.every(handlers => handlers.isEmpty())
|
|
156
155
|
|
|
157
156
|
const handlerNamesWithoutLast = handlerTypes.pop().join(', ')
|
|
158
157
|
|
|
159
158
|
return areAllHandlersEmpty
|
|
160
|
-
? errors.push(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
message: `\
|
|
159
|
+
? errors.push({
|
|
160
|
+
path: path,
|
|
161
|
+
message: `\
|
|
164
162
|
Mapping has no ${handlerNamesWithoutLast} or ${handlerTypes.get(-1)}.
|
|
165
163
|
At least one such handler must be defined.`,
|
|
166
|
-
|
|
167
|
-
)
|
|
164
|
+
})
|
|
168
165
|
: errors
|
|
169
|
-
},
|
|
166
|
+
}, [])
|
|
170
167
|
}
|
|
171
168
|
|
|
172
169
|
static validateContractValues(manifest, protocol) {
|
|
173
170
|
if (!protocol.hasContract()) {
|
|
174
|
-
return
|
|
171
|
+
return []
|
|
175
172
|
}
|
|
176
173
|
|
|
177
174
|
return validation.validateContractValues(manifest, protocol)
|
|
@@ -184,38 +181,32 @@ At least one such handler must be defined.`,
|
|
|
184
181
|
let path = ['dataSources', dataSourceIndex, 'name']
|
|
185
182
|
let name = dataSource.get('name')
|
|
186
183
|
if (names.includes(name)) {
|
|
187
|
-
errors = errors.push(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
message: `\
|
|
184
|
+
errors = errors.push({
|
|
185
|
+
path,
|
|
186
|
+
message: `\
|
|
191
187
|
More than one data source named '${name}', data source names must be unique.`,
|
|
192
|
-
|
|
193
|
-
)
|
|
188
|
+
})
|
|
194
189
|
}
|
|
195
190
|
names.push(name)
|
|
196
191
|
return errors
|
|
197
|
-
},
|
|
192
|
+
}, [])
|
|
198
193
|
}
|
|
199
194
|
|
|
200
195
|
static validateUniqueTemplateNames(manifest) {
|
|
201
196
|
let names = []
|
|
202
|
-
return manifest
|
|
203
|
-
|
|
204
|
-
.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
immutable.fromJS({
|
|
210
|
-
path,
|
|
211
|
-
message: `\
|
|
197
|
+
return manifest.get('templates', []).reduce((errors, template, templateIndex) => {
|
|
198
|
+
let path = ['templates', templateIndex, 'name']
|
|
199
|
+
let name = template.get('name')
|
|
200
|
+
if (names.includes(name)) {
|
|
201
|
+
errors = errors.push({
|
|
202
|
+
path,
|
|
203
|
+
message: `\
|
|
212
204
|
More than one template named '${name}', template names must be unique.`,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}, immutable.List())
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
names.push(name)
|
|
208
|
+
return errors
|
|
209
|
+
}, [])
|
|
219
210
|
}
|
|
220
211
|
|
|
221
212
|
static dump(manifest) {
|
|
@@ -250,7 +241,7 @@ More than one template named '${name}', template names must be unique.`,
|
|
|
250
241
|
}
|
|
251
242
|
}
|
|
252
243
|
|
|
253
|
-
let manifest =
|
|
244
|
+
let manifest = data
|
|
254
245
|
|
|
255
246
|
// Validate the schema
|
|
256
247
|
Subgraph.validateSchema(manifest, { resolveFile })
|
|
@@ -262,14 +253,14 @@ More than one template named '${name}', template names must be unique.`,
|
|
|
262
253
|
})
|
|
263
254
|
|
|
264
255
|
let errors = skipValidation
|
|
265
|
-
?
|
|
266
|
-
:
|
|
256
|
+
? []
|
|
257
|
+
: [
|
|
267
258
|
...protocolSubgraph.validateManifest(),
|
|
268
259
|
...Subgraph.validateContractValues(manifest, protocol),
|
|
269
260
|
...Subgraph.validateUniqueDataSourceNames(manifest),
|
|
270
261
|
...Subgraph.validateUniqueTemplateNames(manifest),
|
|
271
262
|
...Subgraph.validateHandlers(manifest, protocol, protocolSubgraph),
|
|
272
|
-
|
|
263
|
+
]
|
|
273
264
|
|
|
274
265
|
if (errors.size > 0) {
|
|
275
266
|
throwCombinedError(filename, errors)
|
|
@@ -277,11 +268,11 @@ More than one template named '${name}', template names must be unique.`,
|
|
|
277
268
|
|
|
278
269
|
// Perform warning validations
|
|
279
270
|
let warnings = skipValidation
|
|
280
|
-
?
|
|
281
|
-
:
|
|
271
|
+
? []
|
|
272
|
+
: [
|
|
282
273
|
...Subgraph.validateRepository(manifest, { resolveFile }),
|
|
283
274
|
...Subgraph.validateDescription(manifest, { resolveFile }),
|
|
284
|
-
|
|
275
|
+
]
|
|
285
276
|
|
|
286
277
|
return {
|
|
287
278
|
result: manifest,
|