Skip to content

Commit c41c12a

Browse files
author
Victor Velev
committed
Merge branch 'master' of https://github.com/graphprotocol/graph-cli into codegen-test
2 parents 037b718 + 508629f commit c41c12a

File tree

13 files changed

+254
-165
lines changed

13 files changed

+254
-165
lines changed

manifest-schema.graphql

Lines changed: 0 additions & 122 deletions
This file was deleted.

src/commands/test.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { Binary } = require('binary-install-raw')
22
const os = require('os')
33
const chalk = require('chalk')
44
const fetch = require('node-fetch')
5-
const { filesystem, patching, print } = require('gluegun')
5+
const { filesystem, patching, print, system } = require('gluegun')
66
const { fixParameters } = require('../command-helpers/gluegun')
77
const path = require('path')
88
const semver = require('semver')
@@ -103,7 +103,7 @@ async function runBinary(datasource, opts) {
103103
let latestVersion = opts.get("latestVersion")
104104
let recompileOpt = opts.get("recompile")
105105

106-
const platform = getPlatform(logsOpt)
106+
const platform = await getPlatform(logsOpt)
107107

108108
const url = `https://github.com/LimeChain/matchstick/releases/download/${versionOpt || latestVersion}/${platform}`
109109

@@ -121,19 +121,21 @@ async function runBinary(datasource, opts) {
121121
args.length > 0 ? binary.run(...args) : binary.run()
122122
}
123123

124-
function getPlatform(logsOpt) {
124+
async function getPlatform(logsOpt) {
125125
const type = os.type()
126126
const arch = os.arch()
127-
const release = os.release()
128127
const cpuCore = os.cpus()[0]
129-
const majorVersion = semver.major(release)
130-
const isM1 = cpuCore.model.includes("Apple M1")
128+
const isM1 = (arch === 'arm64' && /Apple (M1|processor)/.test(cpuCore.model))
129+
const linuxInfo = type === 'Linux' ? await getLinuxInfo() : new Map()
130+
const linuxDistro = linuxInfo.get('name')
131+
const release = linuxInfo.get('version') || os.release()
132+
const majorVersion = parseInt(linuxInfo.get('version'), 10) || semver.major(release)
131133

132134
if (logsOpt) {
133-
print.info(`OS type: ${type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
135+
print.info(`OS type: ${linuxDistro || type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
134136
}
135137

136-
if (arch === 'x64' || (arch === 'arm64' && isM1)) {
138+
if (arch === 'x64' || isM1) {
137139
if (type === 'Darwin') {
138140
if (majorVersion === 19) {
139141
return 'binary-macos-10.15'
@@ -146,8 +148,9 @@ function getPlatform(logsOpt) {
146148
} else if (type === 'Linux') {
147149
if (majorVersion === 18) {
148150
return 'binary-linux-18'
151+
} else {
152+
return 'binary-linux-20'
149153
}
150-
return 'binary-linux-20'
151154
} else if (type === 'Windows_NT') {
152155
return 'binary-windows'
153156
}
@@ -156,6 +159,23 @@ function getPlatform(logsOpt) {
156159
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
157160
}
158161

162+
async function getLinuxInfo() {
163+
try {
164+
let result = await system.run("cat /etc/*-release | grep -E '(^VERSION|^NAME)='", {trim: true})
165+
let infoArray = result.replace(/['"]+/g, '').split('\n').map(p => p.split('='))
166+
let infoMap = new Map();
167+
168+
infoArray.forEach((val) => {
169+
infoMap.set(val[0].toLowerCase(), val[1])
170+
});
171+
172+
return infoMap
173+
} catch (error) {
174+
print.error(`Error fetching the Linux version:\n ${error}`)
175+
process.exit(1)
176+
}
177+
}
178+
159179
async function runDocker(datasource, opts) {
160180
let coverageOpt = opts.get("coverage")
161181
let forceOpt = opts.get("force")
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
templates: [DataSourceTemplate!]
20+
}
21+
22+
type Schema {
23+
file: File!
24+
}
25+
26+
type DataSource {
27+
kind: String!
28+
name: String!
29+
network: String
30+
source: ContractSource!
31+
mapping: ContractMapping!
32+
}
33+
34+
type ContractSource {
35+
address: String
36+
abi: String!
37+
startBlock: BigInt
38+
}
39+
40+
type ContractMapping {
41+
kind: String
42+
apiVersion: String!
43+
language: String!
44+
file: File!
45+
entities: [String!]!
46+
abis: [ContractAbi!]!
47+
blockHandlers: [BlockHandler!]
48+
callHandlers: [CallHandler!]
49+
eventHandlers: [ContractEventHandler!]
50+
}
51+
52+
type ContractAbi {
53+
name: String!
54+
file: File!
55+
}
56+
57+
type BlockHandler {
58+
handler: String!
59+
filter: BlockFilter
60+
}
61+
62+
type BlockFilter {
63+
kind: String!
64+
}
65+
66+
type CallHandler {
67+
function: String!
68+
handler: String!
69+
}
70+
71+
type ContractEventHandler {
72+
event: String!
73+
topic0: String
74+
handler: String!
75+
}
76+
77+
type Graft {
78+
base: String!
79+
block: BigInt!
80+
}
81+
82+
type DataSourceTemplate {
83+
kind: String!
84+
name: String!
85+
network: String
86+
source: ContractSourceTemplate!
87+
mapping: ContractMapping!
88+
}
89+
90+
type ContractSourceTemplate {
91+
abi: String!
92+
}

src/protocols/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ module.exports = class Protocol {
6060
'aurora',
6161
'aurora-testnet',
6262
],
63-
near: [
64-
'near-mainnet',
65-
'near-testnet'
66-
],
63+
near: ['near-mainnet', 'near-testnet'],
6764
})
6865
}
6966

@@ -108,6 +105,15 @@ module.exports = class Protocol {
108105
}
109106
}
110107

108+
hasTemplates() {
109+
switch (this.name) {
110+
case 'ethereum':
111+
return true
112+
case 'near':
113+
return false
114+
}
115+
}
116+
111117
getTypeGenerator(options) {
112118
switch (this.name) {
113119
case 'ethereum':
@@ -118,13 +124,17 @@ module.exports = class Protocol {
118124
}
119125

120126
getTemplateCodeGen(template) {
127+
if (!this.hasTemplates()) {
128+
throw new Error(
129+
`Template data sources with kind '${this.name}' are not supported yet`,
130+
)
131+
}
132+
121133
switch (this.name) {
122134
case 'ethereum':
123135
return new EthereumTemplateCodeGen(template)
124136
default:
125-
throw new Error(
126-
`Template data sources with kind '${this.name}' are not supported yet`,
127-
)
137+
throw new Error(`Template data sources with kind '${this.name}' is unknown`)
128138
}
129139
}
130140

0 commit comments

Comments
 (0)