@graphprotocol/graph-cli 0.33.0 → 0.33.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/package.json +1 -1
- package/src/codegen/template.js +8 -1
- package/src/command-helpers/scaffold.js +15 -9
- package/src/command-helpers/studio.js +1 -1
- package/src/commands/add.js +1 -4
- package/src/commands/test.js +3 -3
- package/src/protocols/index.js +4 -4
- package/src/protocols/ipfs/codegen/file_template.js +40 -0
- package/src/scaffold/index.js +8 -5
- package/src/subgraph.js +10 -4
package/package.json
CHANGED
package/src/codegen/template.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
const immutable = require('immutable')
|
|
2
|
+
const IpfsFileTemplateCodeGen = require('../protocols/ipfs/codegen/file_template')
|
|
2
3
|
|
|
3
4
|
const tsCodegen = require('./typescript')
|
|
4
5
|
|
|
5
6
|
module.exports = class DataSourceTemplateCodeGenerator {
|
|
6
7
|
constructor(template, protocol) {
|
|
7
8
|
this.template = template
|
|
8
|
-
|
|
9
|
+
let kind = template.get('kind')
|
|
10
|
+
|
|
11
|
+
if (kind.split('/')[0] == protocol.name) {
|
|
12
|
+
this.protocolTemplateCodeGen = protocol.getTemplateCodeGen(template)
|
|
13
|
+
} else if (kind == "file/ipfs") {
|
|
14
|
+
this.protocolTemplateCodeGen = new IpfsFileTemplateCodeGen(template)
|
|
15
|
+
}
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
generateModuleImports() {
|
|
@@ -128,17 +128,23 @@ const writeMapping = async (abi, protocol, contractName, entities) => {
|
|
|
128
128
|
})
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
const writeTestsFiles = async (abi, contractName) => {
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const writeTestsFiles = async (abi, protocol, contractName) => {
|
|
132
|
+
const hasEvents = protocol.hasEvents()
|
|
133
|
+
const events = hasEvents
|
|
134
|
+
? abiEvents(abi).toJS()
|
|
135
|
+
: []
|
|
136
|
+
|
|
137
|
+
if(events.length > 0) {
|
|
138
|
+
// If a contract is added to a subgraph that has no tests folder
|
|
139
|
+
await fs.ensureDir('./tests/')
|
|
134
140
|
|
|
135
|
-
|
|
136
|
-
const testsFiles = generateTestsFiles(contractName, events, true)
|
|
141
|
+
const testsFiles = generateTestsFiles(contractName, events, true)
|
|
137
142
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
for (const [fileName, content] of Object.entries(testsFiles)) {
|
|
144
|
+
await fs.writeFile(`./tests/${fileName}`, content, {
|
|
145
|
+
encoding: 'utf-8',
|
|
146
|
+
})
|
|
147
|
+
}
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
150
|
|
package/src/commands/add.js
CHANGED
|
@@ -102,10 +102,7 @@ module.exports = {
|
|
|
102
102
|
await writeABI(ethabi, contractName)
|
|
103
103
|
await writeSchema(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities)
|
|
104
104
|
await writeMapping(ethabi, protocol, contractName, collisionEntities)
|
|
105
|
-
|
|
106
|
-
if (protocol.hasEvents()) {
|
|
107
|
-
await writeTestsFiles(ethabi, contractName)
|
|
108
|
-
}
|
|
105
|
+
await writeTestsFiles(ethabi, protocol, contractName)
|
|
109
106
|
|
|
110
107
|
let dataSources = result.get('dataSources')
|
|
111
108
|
let dataSource = await generateDataSource(protocol,
|
package/src/commands/test.js
CHANGED
|
@@ -168,7 +168,7 @@ async function getPlatform(logsOpt) {
|
|
|
168
168
|
const type = os.type()
|
|
169
169
|
const arch = os.arch()
|
|
170
170
|
const cpuCore = os.cpus()[0]
|
|
171
|
-
const
|
|
171
|
+
const isAppleSilicon = (arch === 'arm64' && /Apple (M1|M2|processor)/.test(cpuCore.model))
|
|
172
172
|
const linuxInfo = type === 'Linux' ? await getLinuxInfo() : {}
|
|
173
173
|
const linuxDistro = linuxInfo.name
|
|
174
174
|
const release = linuxInfo.version || os.release()
|
|
@@ -178,11 +178,11 @@ async function getPlatform(logsOpt) {
|
|
|
178
178
|
print.info(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
if (arch === 'x64' ||
|
|
181
|
+
if (arch === 'x64' || isAppleSilicon) {
|
|
182
182
|
if (type === 'Darwin') {
|
|
183
183
|
if (majorVersion === 18 || majorVersion === 19) {
|
|
184
184
|
return 'binary-macos-10.15' // GitHub dropped support for macOS 10.14 in Actions, but it seems 10.15 binary works on 10.14 too
|
|
185
|
-
} else if (
|
|
185
|
+
} else if (isAppleSilicon) {
|
|
186
186
|
return 'binary-macos-11-m1'
|
|
187
187
|
}
|
|
188
188
|
return 'binary-macos-11'
|
package/src/protocols/index.js
CHANGED
|
@@ -42,9 +42,7 @@ module.exports = class Protocol {
|
|
|
42
42
|
arweave: ['arweave-mainnet'],
|
|
43
43
|
ethereum: [
|
|
44
44
|
'mainnet',
|
|
45
|
-
'kovan',
|
|
46
45
|
'rinkeby',
|
|
47
|
-
'ropsten',
|
|
48
46
|
'goerli',
|
|
49
47
|
'poa-core',
|
|
50
48
|
'poa-sokol',
|
|
@@ -74,9 +72,11 @@ module.exports = class Protocol {
|
|
|
74
72
|
near: ['near-mainnet', 'near-testnet'],
|
|
75
73
|
cosmos: [
|
|
76
74
|
'cosmoshub-4',
|
|
77
|
-
'theta-testnet-001',
|
|
75
|
+
'theta-testnet-001', // CosmosHub testnet
|
|
78
76
|
'osmosis-1',
|
|
79
|
-
'osmo-test-4'
|
|
77
|
+
'osmo-test-4', // Osmosis testnet
|
|
78
|
+
'juno-1',
|
|
79
|
+
'uni-3' // Juno testnet
|
|
80
80
|
],
|
|
81
81
|
})
|
|
82
82
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const tsCodegen = require('../../../codegen/typescript')
|
|
2
|
+
|
|
3
|
+
module.exports = class IpfsFileTemplateCodeGen {
|
|
4
|
+
constructor(template) {
|
|
5
|
+
this.template = template
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
generateModuleImports() {
|
|
9
|
+
return []
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
generateCreateMethod() {
|
|
13
|
+
const name = this.template.get('name')
|
|
14
|
+
|
|
15
|
+
return tsCodegen.staticMethod(
|
|
16
|
+
'create',
|
|
17
|
+
[tsCodegen.param('cid', tsCodegen.namedType('string'))],
|
|
18
|
+
tsCodegen.namedType('void'),
|
|
19
|
+
`
|
|
20
|
+
DataSourceTemplate.create('${name}', [cid])
|
|
21
|
+
`,
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
generateCreateWithContextMethod() {
|
|
26
|
+
const name = this.template.get('name')
|
|
27
|
+
|
|
28
|
+
return tsCodegen.staticMethod(
|
|
29
|
+
'createWithContext',
|
|
30
|
+
[
|
|
31
|
+
tsCodegen.param('cid', tsCodegen.namedType('string')),
|
|
32
|
+
tsCodegen.param('context', tsCodegen.namedType('DataSourceContext')),
|
|
33
|
+
],
|
|
34
|
+
tsCodegen.namedType('void'),
|
|
35
|
+
`
|
|
36
|
+
DataSourceTemplate.createWithContext('${name}', [cid], context)
|
|
37
|
+
`,
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/scaffold/index.js
CHANGED
|
@@ -55,9 +55,7 @@ module.exports = class Scaffold {
|
|
|
55
55
|
'@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
|
|
56
56
|
'@graphprotocol/graph-ts': `0.27.0`,
|
|
57
57
|
},
|
|
58
|
-
devDependencies: {
|
|
59
|
-
'matchstick-as': `0.5.0`,
|
|
60
|
-
},
|
|
58
|
+
devDependencies: this.protocol.hasEvents() ? { 'matchstick-as': `0.5.0`} : undefined,
|
|
61
59
|
}),
|
|
62
60
|
{ parser: 'json' },
|
|
63
61
|
)
|
|
@@ -143,8 +141,13 @@ dataSources:
|
|
|
143
141
|
}
|
|
144
142
|
|
|
145
143
|
generateTests() {
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
const hasEvents = this.protocol.hasEvents()
|
|
145
|
+
const events = hasEvents
|
|
146
|
+
? abiEvents(this.abi).toJS()
|
|
147
|
+
: []
|
|
148
|
+
|
|
149
|
+
return events.length > 0
|
|
150
|
+
? generateTestsFiles(this.contractName, events, this.indexEvents)
|
|
148
151
|
: undefined
|
|
149
152
|
}
|
|
150
153
|
|
package/src/subgraph.js
CHANGED
|
@@ -216,20 +216,26 @@ More than one template named '${name}', template names must be unique.`,
|
|
|
216
216
|
static async load(filename, { protocol, skipValidation } = { skipValidation: false }) {
|
|
217
217
|
// Load and validate the manifest
|
|
218
218
|
let data = null
|
|
219
|
+
let has_file_data_sources = false
|
|
219
220
|
|
|
220
221
|
if (filename.match(/.js$/)) {
|
|
221
222
|
data = require(path.resolve(filename))
|
|
222
223
|
} else {
|
|
223
|
-
|
|
224
|
+
let raw_data = await fs.readFile(filename, 'utf-8')
|
|
225
|
+
has_file_data_sources = raw_data.includes('kind: file')
|
|
226
|
+
data = yaml.parse(raw_data)
|
|
224
227
|
}
|
|
225
228
|
|
|
226
229
|
// Helper to resolve files relative to the subgraph manifest
|
|
227
230
|
let resolveFile = maybeRelativeFile =>
|
|
228
231
|
path.resolve(path.dirname(filename), maybeRelativeFile)
|
|
229
232
|
|
|
230
|
-
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
+
// TODO: Validation for file data sources
|
|
234
|
+
if (!has_file_data_sources) {
|
|
235
|
+
let manifestErrors = await Subgraph.validate(data, protocol, { resolveFile })
|
|
236
|
+
if (manifestErrors.size > 0) {
|
|
237
|
+
throwCombinedError(filename, manifestErrors)
|
|
238
|
+
}
|
|
233
239
|
}
|
|
234
240
|
|
|
235
241
|
let manifest = immutable.fromJS(data)
|