@graphprotocol/graph-cli 0.37.3-alpha-20230110163550-d64bef6 → 0.37.3-alpha-20230111112917-acbc0ae
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 +1 -1
- package/dist/subgraph.js +4 -1
- package/dist/type-generator.js +13 -10
- package/package.json +1 -1
- package/src/protocols/index.ts +2 -2
- package/src/subgraph.ts +6 -1
- package/src/{type-generator.js → type-generator.ts} +37 -20
package/CHANGELOG.md
CHANGED
package/dist/subgraph.js
CHANGED
|
@@ -83,7 +83,10 @@ class Subgraph {
|
|
|
83
83
|
let msg = errors.reduce((msg, errors, entity) => {
|
|
84
84
|
errors = errors.groupBy((error) => error.get('directive'));
|
|
85
85
|
let inner_msgs = errors.reduce((msg, errors, directive) => {
|
|
86
|
-
return `${msg}${directive
|
|
86
|
+
return `${msg}${directive
|
|
87
|
+
? `
|
|
88
|
+
${directive}:`
|
|
89
|
+
: ''}
|
|
87
90
|
${errors
|
|
88
91
|
.map(error => error
|
|
89
92
|
.get('message')
|
package/dist/type-generator.js
CHANGED
|
@@ -31,8 +31,7 @@ const immutable_1 = __importDefault(require("immutable"));
|
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
32
32
|
const prettier_1 = __importDefault(require("prettier"));
|
|
33
33
|
const graphql = __importStar(require("graphql/language"));
|
|
34
|
-
const
|
|
35
|
-
const toolbox = __importStar(require("gluegun/toolbox"));
|
|
34
|
+
const toolbox = __importStar(require("gluegun"));
|
|
36
35
|
const schema_1 = __importDefault(require("./schema"));
|
|
37
36
|
const subgraph_1 = __importDefault(require("./subgraph"));
|
|
38
37
|
const template_1 = __importDefault(require("./codegen/template"));
|
|
@@ -41,15 +40,20 @@ const spinner_1 = require("./command-helpers/spinner");
|
|
|
41
40
|
const migrations_1 = require("./migrations");
|
|
42
41
|
const typescript_1 = require("./codegen/typescript");
|
|
43
42
|
const fs_1 = require("./command-helpers/fs");
|
|
43
|
+
// @ts-expect-error TODO: type out if necessary
|
|
44
44
|
const Index_bs_js_1 = __importDefault(require("@float-capital/float-subgraph-uncrashable/src/Index.bs.js"));
|
|
45
45
|
class TypeGenerator {
|
|
46
|
+
sourceDir;
|
|
47
|
+
options;
|
|
48
|
+
protocol;
|
|
49
|
+
protocolTypeGenerator;
|
|
46
50
|
constructor(options) {
|
|
47
|
-
this.options = options
|
|
51
|
+
this.options = options;
|
|
48
52
|
this.sourceDir =
|
|
49
53
|
this.options.sourceDir ||
|
|
50
54
|
(this.options.subgraphManifest && path_1.default.dirname(this.options.subgraphManifest));
|
|
51
55
|
this.protocol = this.options.protocol;
|
|
52
|
-
this.protocolTypeGenerator = this.protocol
|
|
56
|
+
this.protocolTypeGenerator = this.protocol?.getTypeGenerator?.({
|
|
53
57
|
sourceDir: this.sourceDir,
|
|
54
58
|
outputDir: this.options.outputDir,
|
|
55
59
|
});
|
|
@@ -104,11 +108,11 @@ class TypeGenerator {
|
|
|
104
108
|
if (quiet) {
|
|
105
109
|
return this.options.subgraph
|
|
106
110
|
? this.options.subgraph
|
|
107
|
-
: subgraph_1.default.load(this.options.subgraphManifest, subgraphLoadOptions).result;
|
|
111
|
+
: (await subgraph_1.default.load(this.options.subgraphManifest, subgraphLoadOptions)).result;
|
|
108
112
|
}
|
|
109
113
|
else {
|
|
110
114
|
const manifestPath = (0, fs_1.displayPath)(this.options.subgraphManifest);
|
|
111
|
-
return await (0, spinner_1.withSpinner)(`Load subgraph from ${manifestPath}`, `Failed to load subgraph from ${manifestPath}`, `Warnings while loading subgraph from ${manifestPath}`, async (
|
|
115
|
+
return await (0, spinner_1.withSpinner)(`Load subgraph from ${manifestPath}`, `Failed to load subgraph from ${manifestPath}`, `Warnings while loading subgraph from ${manifestPath}`, async (_spinner) => {
|
|
112
116
|
return this.options.subgraph
|
|
113
117
|
? this.options.subgraph
|
|
114
118
|
: subgraph_1.default.load(this.options.subgraphManifest, subgraphLoadOptions);
|
|
@@ -118,8 +122,7 @@ class TypeGenerator {
|
|
|
118
122
|
async loadSchema(subgraph) {
|
|
119
123
|
let maybeRelativePath = subgraph.getIn(['schema', 'file']);
|
|
120
124
|
let absolutePath = path_1.default.resolve(this.sourceDir, maybeRelativePath);
|
|
121
|
-
return await (0, spinner_1.withSpinner)(`Load GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, `Failed to load GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, `Warnings while loading GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, async (
|
|
122
|
-
let maybeRelativePath = subgraph.getIn(['schema', 'file']);
|
|
125
|
+
return await (0, spinner_1.withSpinner)(`Load GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, `Failed to load GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, `Warnings while loading GraphQL schema from ${(0, fs_1.displayPath)(absolutePath)}`, async (_spinner) => {
|
|
123
126
|
let absolutePath = path_1.default.resolve(this.sourceDir, maybeRelativePath);
|
|
124
127
|
return schema_1.default.load(absolutePath);
|
|
125
128
|
});
|
|
@@ -176,8 +179,8 @@ class TypeGenerator {
|
|
|
176
179
|
// Add the GraphQL schema to the watched files
|
|
177
180
|
files.push(subgraph.getIn(['schema', 'file']));
|
|
178
181
|
// Add all file paths specified in manifest
|
|
179
|
-
subgraph.get('dataSources').map(dataSource => {
|
|
180
|
-
dataSource.getIn(['mapping', 'abis']).map(abi => {
|
|
182
|
+
subgraph.get('dataSources').map((dataSource) => {
|
|
183
|
+
dataSource.getIn(['mapping', 'abis']).map((abi) => {
|
|
181
184
|
files.push(abi.get('file'));
|
|
182
185
|
});
|
|
183
186
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.37.3-alpha-
|
|
3
|
+
"version": "0.37.3-alpha-20230111112917-acbc0ae",
|
|
4
4
|
"license": "(Apache-2.0 OR MIT)",
|
|
5
5
|
"description": "CLI for building for and deploying to The Graph",
|
|
6
6
|
"main": "dist/cli.js",
|
package/src/protocols/index.ts
CHANGED
|
@@ -205,9 +205,9 @@ export default class Protocol {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams'
|
|
208
|
+
export type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams'
|
|
209
209
|
|
|
210
|
-
interface ProtocolConfig {
|
|
210
|
+
export interface ProtocolConfig {
|
|
211
211
|
displayName: string
|
|
212
212
|
abi?: any
|
|
213
213
|
contract?: any
|
package/src/subgraph.ts
CHANGED
|
@@ -88,7 +88,12 @@ export default class Subgraph {
|
|
|
88
88
|
errors = errors.groupBy((error: any) => error.get('directive'))
|
|
89
89
|
let inner_msgs = errors.reduce(
|
|
90
90
|
(msg: string, errors: any[], directive: string) => {
|
|
91
|
-
return `${msg}${
|
|
91
|
+
return `${msg}${
|
|
92
|
+
directive
|
|
93
|
+
? `
|
|
94
|
+
${directive}:`
|
|
95
|
+
: ''
|
|
96
|
+
}
|
|
92
97
|
${errors
|
|
93
98
|
.map(error =>
|
|
94
99
|
error
|
|
@@ -3,33 +3,51 @@ import immutable from 'immutable'
|
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import prettier from 'prettier'
|
|
5
5
|
import * as graphql from 'graphql/language'
|
|
6
|
-
import
|
|
7
|
-
import * as toolbox from 'gluegun/toolbox'
|
|
6
|
+
import * as toolbox from 'gluegun'
|
|
8
7
|
|
|
9
8
|
import Schema from './schema'
|
|
10
9
|
import Subgraph from './subgraph'
|
|
11
10
|
import DataSourceTemplateCodeGenerator from './codegen/template'
|
|
12
11
|
import Watcher from './watcher'
|
|
13
|
-
import { step, withSpinner } from './command-helpers/spinner'
|
|
12
|
+
import { Spinner, step, withSpinner } from './command-helpers/spinner'
|
|
14
13
|
import { applyMigrations } from './migrations'
|
|
15
14
|
import { GENERATED_FILE_NOTE } from './codegen/typescript'
|
|
16
15
|
import { displayPath } from './command-helpers/fs'
|
|
16
|
+
import Protocol from './protocols'
|
|
17
|
+
|
|
18
|
+
// @ts-expect-error TODO: type out if necessary
|
|
17
19
|
import uncrashable from '@float-capital/float-subgraph-uncrashable/src/Index.bs.js'
|
|
18
20
|
|
|
21
|
+
interface TypeGeneratorOptions {
|
|
22
|
+
sourceDir?: string
|
|
23
|
+
subgraphManifest: string
|
|
24
|
+
subgraph?: string
|
|
25
|
+
protocol: Protocol
|
|
26
|
+
outputDir: string
|
|
27
|
+
skipMigrations?: boolean
|
|
28
|
+
uncrashable: any
|
|
29
|
+
uncrashableConfig: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
19
32
|
export default class TypeGenerator {
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
private sourceDir: string
|
|
34
|
+
private options: TypeGeneratorOptions
|
|
35
|
+
private protocol: Protocol
|
|
36
|
+
private protocolTypeGenerator: any
|
|
37
|
+
|
|
38
|
+
constructor(options: TypeGeneratorOptions) {
|
|
39
|
+
this.options = options
|
|
22
40
|
this.sourceDir =
|
|
23
41
|
this.options.sourceDir ||
|
|
24
42
|
(this.options.subgraphManifest && path.dirname(this.options.subgraphManifest))
|
|
25
43
|
|
|
26
44
|
this.protocol = this.options.protocol
|
|
27
|
-
this.protocolTypeGenerator = this.protocol
|
|
45
|
+
this.protocolTypeGenerator = this.protocol?.getTypeGenerator?.({
|
|
28
46
|
sourceDir: this.sourceDir,
|
|
29
47
|
outputDir: this.options.outputDir,
|
|
30
48
|
})
|
|
31
49
|
|
|
32
|
-
process.on('uncaughtException', function
|
|
50
|
+
process.on('uncaughtException', function(e) {
|
|
33
51
|
toolbox.print.error(`UNCAUGHT EXCEPTION: ${e}`)
|
|
34
52
|
})
|
|
35
53
|
}
|
|
@@ -77,7 +95,7 @@ export default class TypeGenerator {
|
|
|
77
95
|
}
|
|
78
96
|
}
|
|
79
97
|
|
|
80
|
-
async generateUncrashableEntities(graphSchema) {
|
|
98
|
+
async generateUncrashableEntities(graphSchema: any) {
|
|
81
99
|
let ast = graphql.parse(graphSchema.document)
|
|
82
100
|
let entityDefinitions = ast['definitions']
|
|
83
101
|
return await withSpinner(
|
|
@@ -102,7 +120,7 @@ export default class TypeGenerator {
|
|
|
102
120
|
if (quiet) {
|
|
103
121
|
return this.options.subgraph
|
|
104
122
|
? this.options.subgraph
|
|
105
|
-
: Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions).result
|
|
123
|
+
: (await Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions)).result
|
|
106
124
|
} else {
|
|
107
125
|
const manifestPath = displayPath(this.options.subgraphManifest)
|
|
108
126
|
|
|
@@ -110,7 +128,7 @@ export default class TypeGenerator {
|
|
|
110
128
|
`Load subgraph from ${manifestPath}`,
|
|
111
129
|
`Failed to load subgraph from ${manifestPath}`,
|
|
112
130
|
`Warnings while loading subgraph from ${manifestPath}`,
|
|
113
|
-
async
|
|
131
|
+
async _spinner => {
|
|
114
132
|
return this.options.subgraph
|
|
115
133
|
? this.options.subgraph
|
|
116
134
|
: Subgraph.load(this.options.subgraphManifest, subgraphLoadOptions)
|
|
@@ -119,22 +137,21 @@ export default class TypeGenerator {
|
|
|
119
137
|
}
|
|
120
138
|
}
|
|
121
139
|
|
|
122
|
-
async loadSchema(subgraph) {
|
|
123
|
-
let maybeRelativePath = subgraph.getIn(['schema', 'file'])
|
|
140
|
+
async loadSchema(subgraph: immutable.Map<any, any>) {
|
|
141
|
+
let maybeRelativePath = subgraph.getIn(['schema', 'file']) as string
|
|
124
142
|
let absolutePath = path.resolve(this.sourceDir, maybeRelativePath)
|
|
125
143
|
return await withSpinner(
|
|
126
144
|
`Load GraphQL schema from ${displayPath(absolutePath)}`,
|
|
127
145
|
`Failed to load GraphQL schema from ${displayPath(absolutePath)}`,
|
|
128
146
|
`Warnings while loading GraphQL schema from ${displayPath(absolutePath)}`,
|
|
129
|
-
async
|
|
130
|
-
let maybeRelativePath = subgraph.getIn(['schema', 'file'])
|
|
147
|
+
async _spinner => {
|
|
131
148
|
let absolutePath = path.resolve(this.sourceDir, maybeRelativePath)
|
|
132
149
|
return Schema.load(absolutePath)
|
|
133
150
|
},
|
|
134
151
|
)
|
|
135
152
|
}
|
|
136
153
|
|
|
137
|
-
async generateTypesForSchema(schema) {
|
|
154
|
+
async generateTypesForSchema(schema: any) {
|
|
138
155
|
return await withSpinner(
|
|
139
156
|
`Generate types for GraphQL schema`,
|
|
140
157
|
`Failed to generate types for GraphQL schema`,
|
|
@@ -161,7 +178,7 @@ export default class TypeGenerator {
|
|
|
161
178
|
)
|
|
162
179
|
}
|
|
163
180
|
|
|
164
|
-
async generateTypesForDataSourceTemplates(subgraph) {
|
|
181
|
+
async generateTypesForDataSourceTemplates(subgraph: immutable.Map<any, any>) {
|
|
165
182
|
return await withSpinner(
|
|
166
183
|
`Generate types for data source templates`,
|
|
167
184
|
`Failed to generate types for data source templates`,
|
|
@@ -170,7 +187,7 @@ export default class TypeGenerator {
|
|
|
170
187
|
// Combine the generated code for all templates
|
|
171
188
|
let codeSegments = subgraph
|
|
172
189
|
.get('templates', immutable.List())
|
|
173
|
-
.reduce((codeSegments, template) => {
|
|
190
|
+
.reduce((codeSegments: any, template: any) => {
|
|
174
191
|
step(
|
|
175
192
|
spinner,
|
|
176
193
|
'Generate types for data source template',
|
|
@@ -217,8 +234,8 @@ export default class TypeGenerator {
|
|
|
217
234
|
files.push(subgraph.getIn(['schema', 'file']))
|
|
218
235
|
|
|
219
236
|
// Add all file paths specified in manifest
|
|
220
|
-
subgraph.get('dataSources').map(dataSource => {
|
|
221
|
-
dataSource.getIn(['mapping', 'abis']).map(abi => {
|
|
237
|
+
subgraph.get('dataSources').map((dataSource: any) => {
|
|
238
|
+
dataSource.getIn(['mapping', 'abis']).map((abi: any) => {
|
|
222
239
|
files.push(abi.get('file'))
|
|
223
240
|
})
|
|
224
241
|
})
|
|
@@ -232,7 +249,7 @@ export default class TypeGenerator {
|
|
|
232
249
|
|
|
233
250
|
async watchAndGenerateTypes() {
|
|
234
251
|
let generator = this
|
|
235
|
-
let spinner
|
|
252
|
+
let spinner: Spinner
|
|
236
253
|
|
|
237
254
|
// Create watcher and generate types once and then on every change to a watched file
|
|
238
255
|
let watcher = new Watcher({
|