@graphprotocol/graph-cli 0.79.0-alpha-20241010142217-5c831cf → 0.79.0-alpha-20241030130848-e62b29d
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/commands/codegen.d.ts +1 -0
- package/dist/commands/codegen.js +13 -1
- package/dist/compiler/index.js +1 -1
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +13 -0
- package/dist/type-generator.d.ts +5 -1
- package/dist/type-generator.js +51 -2
- package/oclif.manifest.json +9 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,7 @@ export default class CodegenCommand extends Command {
|
|
|
10
10
|
'skip-migrations': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
11
|
watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
12
|
uncrashable: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
ipfs: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
14
|
'uncrashable-config': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
15
|
};
|
|
15
16
|
run(): Promise<void>;
|
package/dist/commands/codegen.js
CHANGED
|
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const path_1 = __importDefault(require("path"));
|
|
30
30
|
const core_1 = require("@oclif/core");
|
|
31
31
|
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
32
|
+
const ipfs_1 = require("../command-helpers/ipfs");
|
|
32
33
|
const version_1 = require("../command-helpers/version");
|
|
33
34
|
const debug_1 = __importDefault(require("../debug"));
|
|
34
35
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
@@ -36,9 +37,10 @@ const type_generator_1 = __importDefault(require("../type-generator"));
|
|
|
36
37
|
const codegenDebug = (0, debug_1.default)('graph-cli:codegen');
|
|
37
38
|
class CodegenCommand extends core_1.Command {
|
|
38
39
|
async run() {
|
|
39
|
-
const { args: { 'subgraph-manifest': manifest }, flags: { 'output-dir': outputDir, 'skip-migrations': skipMigrations, watch, uncrashable, 'uncrashable-config': uncrashableConfig, }, } = await this.parse(CodegenCommand);
|
|
40
|
+
const { args: { 'subgraph-manifest': manifest }, flags: { 'output-dir': outputDir, 'skip-migrations': skipMigrations, watch, ipfs, uncrashable, 'uncrashable-config': uncrashableConfig, }, } = await this.parse(CodegenCommand);
|
|
40
41
|
codegenDebug('Initialized codegen manifest: %o', manifest);
|
|
41
42
|
let protocol;
|
|
43
|
+
let subgraphSources;
|
|
42
44
|
try {
|
|
43
45
|
// Checks to make sure codegen doesn't run against
|
|
44
46
|
// older subgraphs (both apiVersion and graph-ts version).
|
|
@@ -50,6 +52,9 @@ class CodegenCommand extends core_1.Command {
|
|
|
50
52
|
await (0, version_1.assertGraphTsVersion)(path_1.default.dirname(manifest), '0.25.0');
|
|
51
53
|
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
|
|
52
54
|
protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
55
|
+
subgraphSources = dataSourcesAndTemplates
|
|
56
|
+
.filter((ds) => ds.kind == 'subgraph')
|
|
57
|
+
.map((ds) => ds.source.address);
|
|
53
58
|
}
|
|
54
59
|
catch (e) {
|
|
55
60
|
this.error(e, { exit: 1 });
|
|
@@ -60,7 +65,9 @@ class CodegenCommand extends core_1.Command {
|
|
|
60
65
|
skipMigrations,
|
|
61
66
|
protocol,
|
|
62
67
|
uncrashable,
|
|
68
|
+
subgraphSources,
|
|
63
69
|
uncrashableConfig: uncrashableConfig || 'uncrashable-config.yaml',
|
|
70
|
+
ipfsUrl: ipfs,
|
|
64
71
|
});
|
|
65
72
|
// Watch working directory for file updates or additions, trigger
|
|
66
73
|
// type generation (if watch argument specified)
|
|
@@ -98,6 +105,11 @@ CodegenCommand.flags = {
|
|
|
98
105
|
summary: 'Generate Float Subgraph Uncrashable helper file.',
|
|
99
106
|
char: 'u',
|
|
100
107
|
}),
|
|
108
|
+
ipfs: core_1.Flags.string({
|
|
109
|
+
summary: 'Upload build results to an IPFS node.',
|
|
110
|
+
char: 'i',
|
|
111
|
+
default: ipfs_1.DEFAULT_IPFS_URL,
|
|
112
|
+
}),
|
|
101
113
|
'uncrashable-config': core_1.Flags.file({
|
|
102
114
|
summary: 'Directory for uncrashable config.',
|
|
103
115
|
aliases: ['uc'],
|
package/dist/compiler/index.js
CHANGED
|
@@ -70,7 +70,7 @@ class Compiler {
|
|
|
70
70
|
return fs_extra_1.default.existsSync(path_1.default.join(item, globalsFile));
|
|
71
71
|
});
|
|
72
72
|
if (!globalsLib) {
|
|
73
|
-
throw Error(
|
|
73
|
+
throw Error(`Could not locate @graphprotocol/graph-ts package in parent directories of subgraph manifest. ${this.libsDirs}`);
|
|
74
74
|
}
|
|
75
75
|
this.globalsFile = path_1.default.join(globalsLib, globalsFile);
|
|
76
76
|
process.on('uncaughtException', e => {
|
package/dist/schema.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ export default class Schema {
|
|
|
7
7
|
constructor(filename: string, document: string, ast: DocumentNode);
|
|
8
8
|
codeGenerator(): SchemaCodeGenerator;
|
|
9
9
|
static load(filename: string): Promise<Schema>;
|
|
10
|
+
static loadFromString(filename: string, document: string): Promise<Schema>;
|
|
10
11
|
}
|
package/dist/schema.js
CHANGED
|
@@ -29,6 +29,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
30
30
|
const graphql = __importStar(require("graphql/language"));
|
|
31
31
|
const schema_1 = __importDefault(require("./codegen/schema"));
|
|
32
|
+
const debug_1 = __importDefault(require("./debug"));
|
|
33
|
+
const schemaDebug = (0, debug_1.default)('graph-cli:type-generator');
|
|
32
34
|
class Schema {
|
|
33
35
|
constructor(filename, document, ast) {
|
|
34
36
|
this.filename = filename;
|
|
@@ -46,5 +48,16 @@ class Schema {
|
|
|
46
48
|
const ast = graphql.parse(document);
|
|
47
49
|
return new Schema(filename, document, ast);
|
|
48
50
|
}
|
|
51
|
+
static async loadFromString(filename, document) {
|
|
52
|
+
try {
|
|
53
|
+
const ast = graphql.parse(document);
|
|
54
|
+
schemaDebug('Loaded schema from string');
|
|
55
|
+
return new Schema(filename, document, ast);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
schemaDebug('Failed to load schema from string: %s', e.message);
|
|
59
|
+
throw new Error(`Failed to load schema from string: ${e.message}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
49
62
|
}
|
|
50
63
|
exports.default = Schema;
|
package/dist/type-generator.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface TypeGeneratorOptions {
|
|
|
9
9
|
skipMigrations?: boolean;
|
|
10
10
|
uncrashable: boolean;
|
|
11
11
|
uncrashableConfig: string;
|
|
12
|
+
subgraphSources: string[];
|
|
13
|
+
ipfsUrl: string;
|
|
12
14
|
}
|
|
13
15
|
export default class TypeGenerator {
|
|
14
16
|
private sourceDir;
|
|
@@ -17,12 +19,14 @@ export default class TypeGenerator {
|
|
|
17
19
|
private protocolTypeGenerator;
|
|
18
20
|
constructor(options: TypeGeneratorOptions);
|
|
19
21
|
generateTypes(): Promise<boolean | undefined>;
|
|
22
|
+
loadSubgraphSchemaFromIPFS(ipfsClient: any, manifest: string): Promise<string>;
|
|
20
23
|
generateUncrashableEntities(graphSchema: any): Promise<any>;
|
|
21
24
|
loadSubgraph({ quiet }?: {
|
|
22
25
|
quiet: boolean;
|
|
23
26
|
}): Promise<any>;
|
|
24
27
|
loadSchema(subgraph: immutable.Map<any, any>): Promise<any>;
|
|
25
|
-
generateTypesForSchema(schema: any
|
|
28
|
+
generateTypesForSchema(schema: any, fileName?: string, // Default file name
|
|
29
|
+
outputDir?: string): Promise<any>;
|
|
26
30
|
generateTypesForDataSourceTemplates(subgraph: immutable.Map<any, any>): Promise<any>;
|
|
27
31
|
getFilesToWatch(): Promise<string[]>;
|
|
28
32
|
watchAndGenerateTypes(): Promise<void>;
|
package/dist/type-generator.js
CHANGED
|
@@ -31,13 +31,17 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
31
31
|
const toolbox = __importStar(require("gluegun"));
|
|
32
32
|
const graphql = __importStar(require("graphql/language"));
|
|
33
33
|
const immutable_1 = __importDefault(require("immutable"));
|
|
34
|
+
const ipfs_http_client_1 = require("ipfs-http-client");
|
|
35
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
34
36
|
const prettier_1 = __importDefault(require("prettier"));
|
|
35
37
|
// @ts-expect-error TODO: type out if necessary
|
|
36
38
|
const Index_bs_js_1 = __importDefault(require("@float-capital/float-subgraph-uncrashable/src/Index.bs.js"));
|
|
37
39
|
const template_1 = __importDefault(require("./codegen/template"));
|
|
38
40
|
const typescript_1 = require("./codegen/typescript");
|
|
41
|
+
const compiler_1 = require("./command-helpers/compiler");
|
|
39
42
|
const fs_1 = require("./command-helpers/fs");
|
|
40
43
|
const spinner_1 = require("./command-helpers/spinner");
|
|
44
|
+
const constants_1 = require("./constants");
|
|
41
45
|
const debug_1 = __importDefault(require("./debug"));
|
|
42
46
|
const migrations_1 = require("./migrations");
|
|
43
47
|
const schema_1 = __importDefault(require("./schema"));
|
|
@@ -66,6 +70,10 @@ class TypeGenerator {
|
|
|
66
70
|
process.exit(0);
|
|
67
71
|
return;
|
|
68
72
|
}
|
|
73
|
+
if (this.options.subgraphSources.length > 0) {
|
|
74
|
+
typeGenDebug.extend('generateTypes')('Subgraph uses subgraph datasources.');
|
|
75
|
+
toolbox.print.success('Subgraph uses subgraph datasources.');
|
|
76
|
+
}
|
|
69
77
|
try {
|
|
70
78
|
if (!this.options.skipMigrations && this.options.subgraphManifest) {
|
|
71
79
|
await (0, migrations_1.applyMigrations)({
|
|
@@ -90,6 +98,20 @@ class TypeGenerator {
|
|
|
90
98
|
const schema = await this.loadSchema(subgraph);
|
|
91
99
|
typeGenDebug.extend('generateTypes')('Generating types for schema');
|
|
92
100
|
await this.generateTypesForSchema(schema);
|
|
101
|
+
if (this.options.subgraphSources.length > 0) {
|
|
102
|
+
const ipfsClient = (0, ipfs_http_client_1.create)({
|
|
103
|
+
url: (0, compiler_1.appendApiVersionForGraph)(this.options.ipfsUrl.toString()),
|
|
104
|
+
headers: {
|
|
105
|
+
...constants_1.GRAPH_CLI_SHARED_HEADERS,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
await Promise.all(this.options.subgraphSources.map(async (manifest) => {
|
|
109
|
+
const subgraphSchemaFile = await this.loadSubgraphSchemaFromIPFS(ipfsClient, manifest);
|
|
110
|
+
const subgraphSchema = await schema_1.default.loadFromString(`js${manifest}.graphql`, subgraphSchemaFile);
|
|
111
|
+
typeGenDebug.extend('generateTypes')(`Generating types for subgraph datasource ${manifest}`);
|
|
112
|
+
await this.generateTypesForSchema(subgraphSchema, `subgraph-${manifest}.ts`);
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
93
115
|
toolbox.print.success('\nTypes generated successfully\n');
|
|
94
116
|
if (this.options.uncrashable && this.options.uncrashableConfig) {
|
|
95
117
|
await this.generateUncrashableEntities(schema);
|
|
@@ -101,6 +123,32 @@ class TypeGenerator {
|
|
|
101
123
|
return false;
|
|
102
124
|
}
|
|
103
125
|
}
|
|
126
|
+
async loadSubgraphSchemaFromIPFS(ipfsClient, manifest) {
|
|
127
|
+
typeGenDebug.extend('loadSubgraphSchemaFromIPFS')(`Loading schema from IPFS ${manifest}`);
|
|
128
|
+
try {
|
|
129
|
+
const manifestBuffer = ipfsClient.cat(manifest);
|
|
130
|
+
let manifestFile = '';
|
|
131
|
+
for await (const chunk of manifestBuffer) {
|
|
132
|
+
manifestFile += Buffer.from(chunk).toString('utf8'); // Explicitly convert each chunk to UTF-8
|
|
133
|
+
}
|
|
134
|
+
const manifestYaml = js_yaml_1.default.safeLoad(manifestFile);
|
|
135
|
+
let schema = manifestYaml.schema.file['/'];
|
|
136
|
+
if (schema.startsWith('/ipfs/')) {
|
|
137
|
+
schema = schema.slice(6);
|
|
138
|
+
}
|
|
139
|
+
const schemaBuffer = ipfsClient.cat(schema);
|
|
140
|
+
let schemaFile = '';
|
|
141
|
+
for await (const chunk of schemaBuffer) {
|
|
142
|
+
schemaFile += Buffer.from(chunk).toString('utf8'); // Explicitly convert each chunk to UTF-8
|
|
143
|
+
}
|
|
144
|
+
return schemaFile;
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
typeGenDebug.extend('loadSubgraphSchemaFromIPFS')(`Failed to load schema from IPFS ${manifest}`);
|
|
148
|
+
typeGenDebug.extend('loadSubgraphSchemaFromIPFS')(e);
|
|
149
|
+
throw Error(`Failed to load schema from IPFS ${manifest}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
104
152
|
async generateUncrashableEntities(graphSchema) {
|
|
105
153
|
const ast = graphql.parse(graphSchema.document);
|
|
106
154
|
const entityDefinitions = ast['definitions'];
|
|
@@ -132,7 +180,8 @@ class TypeGenerator {
|
|
|
132
180
|
return schema_1.default.load(absolutePath);
|
|
133
181
|
});
|
|
134
182
|
}
|
|
135
|
-
async generateTypesForSchema(schema
|
|
183
|
+
async generateTypesForSchema(schema, fileName = 'schema.ts', // Default file name
|
|
184
|
+
outputDir = this.options.outputDir) {
|
|
136
185
|
return await (0, spinner_1.withSpinner)(`Generate types for GraphQL schema`, `Failed to generate types for GraphQL schema`, `Warnings while generating types for GraphQL schema`, async (spinner) => {
|
|
137
186
|
// Generate TypeScript module from schema
|
|
138
187
|
const codeGenerator = schema.codeGenerator();
|
|
@@ -144,7 +193,7 @@ class TypeGenerator {
|
|
|
144
193
|
].join('\n'), {
|
|
145
194
|
parser: 'typescript',
|
|
146
195
|
});
|
|
147
|
-
const outputFile = path_1.default.join(
|
|
196
|
+
const outputFile = path_1.default.join(outputDir, fileName); // Use provided outputDir and fileName
|
|
148
197
|
(0, spinner_1.step)(spinner, 'Write types to', (0, fs_1.displayPath)(outputFile));
|
|
149
198
|
await fs_extra_1.default.mkdirs(path_1.default.dirname(outputFile));
|
|
150
199
|
await fs_extra_1.default.writeFile(outputFile, code);
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.79.0-alpha-
|
|
2
|
+
"version": "0.79.0-alpha-20241030130848-e62b29d",
|
|
3
3
|
"commands": {
|
|
4
4
|
"add": {
|
|
5
5
|
"id": "add",
|
|
@@ -267,6 +267,14 @@
|
|
|
267
267
|
"summary": "Generate Float Subgraph Uncrashable helper file.",
|
|
268
268
|
"allowNo": false
|
|
269
269
|
},
|
|
270
|
+
"ipfs": {
|
|
271
|
+
"name": "ipfs",
|
|
272
|
+
"type": "option",
|
|
273
|
+
"char": "i",
|
|
274
|
+
"summary": "Upload build results to an IPFS node.",
|
|
275
|
+
"multiple": false,
|
|
276
|
+
"default": "https://api.thegraph.com/ipfs/api/v0"
|
|
277
|
+
},
|
|
270
278
|
"uncrashable-config": {
|
|
271
279
|
"name": "uncrashable-config",
|
|
272
280
|
"type": "option",
|
package/package.json
CHANGED