@graphprotocol/graph-cli 0.88.0-alpha-20241105081141-b7a8358 → 0.88.0
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 +9 -6
- package/dist/command-helpers/abi.js +3 -3
- package/dist/commands/codegen.d.ts +0 -1
- package/dist/commands/codegen.js +1 -13
- package/dist/commands/init.js +11 -12
- package/dist/protocols/index.d.ts +2 -2
- package/dist/protocols/index.js +2 -23
- package/dist/schema.d.ts +0 -1
- package/dist/schema.js +0 -9
- package/dist/type-generator.d.ts +1 -5
- package/dist/type-generator.js +2 -51
- package/oclif.manifest.json +2 -11
- package/package.json +1 -1
- package/dist/protocols/subgraph/manifest.graphql +0 -65
- package/dist/protocols/subgraph/scaffold/manifest.d.ts +0 -4
- package/dist/protocols/subgraph/scaffold/manifest.js +0 -12
- package/dist/protocols/subgraph/subgraph.d.ts +0 -10
- package/dist/protocols/subgraph/subgraph.js +0 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.88.0
|
|
3
|
+
## 0.88.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -22,11 +22,6 @@
|
|
|
22
22
|
- Removed `--studio` flag
|
|
23
23
|
- Removed `--allow-simple-name` flag
|
|
24
24
|
|
|
25
|
-
- [#1754](https://github.com/graphprotocol/graph-tooling/pull/1754)
|
|
26
|
-
[`b7a8358`](https://github.com/graphprotocol/graph-tooling/commit/b7a83589dc108158927a9610f3b27d642040c497)
|
|
27
|
-
Thanks [@incrypto32](https://github.com/incrypto32)! - Add support for subgraph datasource and
|
|
28
|
-
associated types.
|
|
29
|
-
|
|
30
25
|
- [#1749](https://github.com/graphprotocol/graph-tooling/pull/1749)
|
|
31
26
|
[`bf43cbf`](https://github.com/graphprotocol/graph-tooling/commit/bf43cbf8283c53f0005d7cb9dfa681c92f3a6a91)
|
|
32
27
|
Thanks [@0237h](https://github.com/0237h)! - Add warning for available CLI updates
|
|
@@ -38,6 +33,14 @@
|
|
|
38
33
|
Thanks [@0237h](https://github.com/0237h)! - Using `graph add` with `localhost` network now
|
|
39
34
|
prompts the user for input
|
|
40
35
|
|
|
36
|
+
- [#1750](https://github.com/graphprotocol/graph-tooling/pull/1750)
|
|
37
|
+
[`d764867`](https://github.com/graphprotocol/graph-tooling/commit/d764867dc7eab32e2f1db8505419ea4fa03ed503)
|
|
38
|
+
Thanks [@0237h](https://github.com/0237h)! - Add prompt for existing directory in `init` flow
|
|
39
|
+
|
|
40
|
+
- [#1756](https://github.com/graphprotocol/graph-tooling/pull/1756)
|
|
41
|
+
[`04bd901`](https://github.com/graphprotocol/graph-tooling/commit/04bd901d3ff974c197b82fd29426309ce7de1558)
|
|
42
|
+
Thanks [@0237h](https://github.com/0237h)! - Fix `matic` RPC endpoint and improve error message
|
|
43
|
+
|
|
41
44
|
## 0.87.0
|
|
42
45
|
|
|
43
46
|
### Minor Changes
|
|
@@ -62,8 +62,8 @@ const fetchContractCreationHashWithRetry = async (url, retryCount) => {
|
|
|
62
62
|
exports.fetchContractCreationHashWithRetry = fetchContractCreationHashWithRetry;
|
|
63
63
|
const fetchTransactionByHashFromRPC = async (network, transactionHash) => {
|
|
64
64
|
let json;
|
|
65
|
+
const RPCURL = getPublicRPCEndpoint(network);
|
|
65
66
|
try {
|
|
66
|
-
const RPCURL = getPublicRPCEndpoint(network);
|
|
67
67
|
if (!RPCURL)
|
|
68
68
|
throw new Error(`Unable to fetch RPC URL for ${network}`);
|
|
69
69
|
const result = await (0, fetch_1.default)(String(RPCURL), {
|
|
@@ -84,7 +84,7 @@ const fetchTransactionByHashFromRPC = async (network, transactionHash) => {
|
|
|
84
84
|
}
|
|
85
85
|
catch (error) {
|
|
86
86
|
logger('Failed to fetchTransactionByHashFromRPC: %O', error);
|
|
87
|
-
throw new Error(
|
|
87
|
+
throw new Error(`Failed to run \`eth_getTransactionByHash\` on RPC (${RPCURL}) (run with env \`DEBUG=*\` for full error).`);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
exports.fetchTransactionByHashFromRPC = fetchTransactionByHashFromRPC;
|
|
@@ -326,7 +326,7 @@ const getPublicRPCEndpoint = (network) => {
|
|
|
326
326
|
case 'mainnet':
|
|
327
327
|
return 'https://rpc.ankr.com/eth';
|
|
328
328
|
case 'matic':
|
|
329
|
-
return 'https://rpc
|
|
329
|
+
return 'https://polygon-rpc.com/';
|
|
330
330
|
case 'mbase':
|
|
331
331
|
return 'https://rpc.moonbase.moonbeam.network';
|
|
332
332
|
case 'mumbai':
|
|
@@ -10,7 +10,6 @@ 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>;
|
|
14
13
|
'uncrashable-config': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
14
|
};
|
|
16
15
|
run(): Promise<void>;
|
package/dist/commands/codegen.js
CHANGED
|
@@ -29,7 +29,6 @@ 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");
|
|
33
32
|
const version_1 = require("../command-helpers/version");
|
|
34
33
|
const debug_1 = __importDefault(require("../debug"));
|
|
35
34
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
@@ -37,10 +36,9 @@ const type_generator_1 = __importDefault(require("../type-generator"));
|
|
|
37
36
|
const codegenDebug = (0, debug_1.default)('graph-cli:codegen');
|
|
38
37
|
class CodegenCommand extends core_1.Command {
|
|
39
38
|
async run() {
|
|
40
|
-
const { args: { 'subgraph-manifest': manifest }, flags: { 'output-dir': outputDir, 'skip-migrations': skipMigrations, watch,
|
|
39
|
+
const { args: { 'subgraph-manifest': manifest }, flags: { 'output-dir': outputDir, 'skip-migrations': skipMigrations, watch, uncrashable, 'uncrashable-config': uncrashableConfig, }, } = await this.parse(CodegenCommand);
|
|
41
40
|
codegenDebug('Initialized codegen manifest: %o', manifest);
|
|
42
41
|
let protocol;
|
|
43
|
-
let subgraphSources;
|
|
44
42
|
try {
|
|
45
43
|
// Checks to make sure codegen doesn't run against
|
|
46
44
|
// older subgraphs (both apiVersion and graph-ts version).
|
|
@@ -52,9 +50,6 @@ class CodegenCommand extends core_1.Command {
|
|
|
52
50
|
await (0, version_1.assertGraphTsVersion)(path_1.default.dirname(manifest), '0.25.0');
|
|
53
51
|
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
|
|
54
52
|
protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
55
|
-
subgraphSources = dataSourcesAndTemplates
|
|
56
|
-
.filter((ds) => ds.kind == 'subgraph')
|
|
57
|
-
.map((ds) => ds.source.address);
|
|
58
53
|
}
|
|
59
54
|
catch (e) {
|
|
60
55
|
this.error(e, { exit: 1 });
|
|
@@ -65,9 +60,7 @@ class CodegenCommand extends core_1.Command {
|
|
|
65
60
|
skipMigrations,
|
|
66
61
|
protocol,
|
|
67
62
|
uncrashable,
|
|
68
|
-
subgraphSources,
|
|
69
63
|
uncrashableConfig: uncrashableConfig || 'uncrashable-config.yaml',
|
|
70
|
-
ipfsUrl: ipfs,
|
|
71
64
|
});
|
|
72
65
|
// Watch working directory for file updates or additions, trigger
|
|
73
66
|
// type generation (if watch argument specified)
|
|
@@ -105,11 +98,6 @@ CodegenCommand.flags = {
|
|
|
105
98
|
summary: 'Generate Float Subgraph Uncrashable helper file.',
|
|
106
99
|
char: 'u',
|
|
107
100
|
}),
|
|
108
|
-
ipfs: core_1.Flags.string({
|
|
109
|
-
summary: 'IPFS node to use for fetching subgraph data.',
|
|
110
|
-
char: 'i',
|
|
111
|
-
default: ipfs_1.DEFAULT_IPFS_URL,
|
|
112
|
-
}),
|
|
113
101
|
'uncrashable-config': core_1.Flags.file({
|
|
114
102
|
summary: 'Directory for uncrashable config.',
|
|
115
103
|
aliases: ['uc'],
|
package/dist/commands/init.js
CHANGED
|
@@ -330,9 +330,6 @@ async function processFromExampleInitForm({ directory: initDirectory, subgraphNa
|
|
|
330
330
|
name: 'directory',
|
|
331
331
|
message: 'Directory to create the subgraph in',
|
|
332
332
|
initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
|
|
333
|
-
validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
|
|
334
|
-
? 'Directory already exists'
|
|
335
|
-
: true,
|
|
336
333
|
},
|
|
337
334
|
]);
|
|
338
335
|
return {
|
|
@@ -398,9 +395,6 @@ async function processInitForm({ protocol: initProtocol, abi: initAbi, abiPath:
|
|
|
398
395
|
name: 'directory',
|
|
399
396
|
message: 'Directory to create the subgraph in',
|
|
400
397
|
initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
|
|
401
|
-
validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
|
|
402
|
-
? 'Directory already exists'
|
|
403
|
-
: true,
|
|
404
398
|
},
|
|
405
399
|
]);
|
|
406
400
|
let choices = (await AVAILABLE_NETWORKS())?.['studio'];
|
|
@@ -685,9 +679,13 @@ Subgraph ${subgraphName} created in ${relativeDir}
|
|
|
685
679
|
Make sure to visit the documentation on https://thegraph.com/docs/ for further information.`);
|
|
686
680
|
}
|
|
687
681
|
async function initSubgraphFromExample({ fromExample, subgraphName, directory, skipInstall, skipGit, }, { commands, }) {
|
|
688
|
-
|
|
682
|
+
let overwrite = false;
|
|
689
683
|
if (gluegun_1.filesystem.exists(directory)) {
|
|
690
|
-
|
|
684
|
+
overwrite = await gluegun_1.prompt.confirm('Directory already exists, do you want to initialize the subgraph here (files will be overwritten) ?', false);
|
|
685
|
+
if (!overwrite) {
|
|
686
|
+
this.exit(1);
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
691
689
|
}
|
|
692
690
|
// Clone the example subgraph repository
|
|
693
691
|
const cloned = await (0, spinner_1.withSpinner)(`Cloning example subgraph`, `Failed to clone example subgraph`, `Warnings while cloning example subgraph`, async () => {
|
|
@@ -708,7 +706,7 @@ async function initSubgraphFromExample({ fromExample, subgraphName, directory, s
|
|
|
708
706
|
if (!gluegun_1.filesystem.exists(exampleSubgraphPath)) {
|
|
709
707
|
return { result: false, error: `Example not found: ${fromExample}` };
|
|
710
708
|
}
|
|
711
|
-
gluegun_1.filesystem.copy(exampleSubgraphPath, directory);
|
|
709
|
+
gluegun_1.filesystem.copy(exampleSubgraphPath, directory, { overwrite });
|
|
712
710
|
return true;
|
|
713
711
|
}
|
|
714
712
|
finally {
|
|
@@ -779,9 +777,10 @@ async function initSubgraphFromExample({ fromExample, subgraphName, directory, s
|
|
|
779
777
|
}
|
|
780
778
|
async function initSubgraphFromContract({ protocolInstance, subgraphName, directory, abi, network, contract, indexEvents, contractName, node, startBlock, spkgPath, skipInstall, skipGit, }, { commands, addContract, }) {
|
|
781
779
|
const isSubstreams = protocolInstance.name === 'substreams';
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
this.
|
|
780
|
+
if (gluegun_1.filesystem.exists(directory) &&
|
|
781
|
+
!(await gluegun_1.prompt.confirm('Directory already exists, do you want to initialize the subgraph here (files will be overwritten) ?', false))) {
|
|
782
|
+
this.exit(1);
|
|
783
|
+
return;
|
|
785
784
|
}
|
|
786
785
|
if (protocolInstance.hasABIs() &&
|
|
787
786
|
((0, schema_1.abiEvents)(abi).size === 0 ||
|
|
@@ -8,7 +8,7 @@ export default class Protocol {
|
|
|
8
8
|
config: ProtocolConfig;
|
|
9
9
|
constructor(datasource: any);
|
|
10
10
|
static availableProtocols(): immutable.Collection<ProtocolName, string[]>;
|
|
11
|
-
static availableNetworks(): immutable.Map<"ethereum" | "arweave" | "near" | "cosmos" | "substreams" | "substreams/triggers"
|
|
11
|
+
static availableNetworks(): immutable.Map<"ethereum" | "arweave" | "near" | "cosmos" | "substreams" | "substreams/triggers", immutable.List<string>>;
|
|
12
12
|
static normalizeName(name: ProtocolName): ProtocolName;
|
|
13
13
|
displayName(): string;
|
|
14
14
|
isValidKindName(kind: string): boolean;
|
|
@@ -25,7 +25,7 @@ export default class Protocol {
|
|
|
25
25
|
getManifestScaffold(): any;
|
|
26
26
|
getMappingScaffold(): any;
|
|
27
27
|
}
|
|
28
|
-
export type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams' | 'substreams/triggers'
|
|
28
|
+
export type ProtocolName = 'arweave' | 'ethereum' | 'near' | 'cosmos' | 'substreams' | 'substreams/triggers';
|
|
29
29
|
export interface ProtocolConfig {
|
|
30
30
|
displayName: string;
|
|
31
31
|
abi?: any;
|
package/dist/protocols/index.js
CHANGED
|
@@ -45,9 +45,8 @@ const contract_2 = __importDefault(require("./near/contract"));
|
|
|
45
45
|
const NearManifestScaffold = __importStar(require("./near/scaffold/manifest"));
|
|
46
46
|
const NearMappingScaffold = __importStar(require("./near/scaffold/mapping"));
|
|
47
47
|
const subgraph_4 = __importDefault(require("./near/subgraph"));
|
|
48
|
-
const subgraph_5 = __importDefault(require("./subgraph/subgraph"));
|
|
49
48
|
const SubstreamsManifestScaffold = __importStar(require("./substreams/scaffold/manifest"));
|
|
50
|
-
const
|
|
49
|
+
const subgraph_5 = __importDefault(require("./substreams/subgraph"));
|
|
51
50
|
const protocolDebug = (0, debug_1.default)('graph-cli:protocol');
|
|
52
51
|
class Protocol {
|
|
53
52
|
static fromDataSources(dataSourcesAndTemplates) {
|
|
@@ -61,7 +60,6 @@ class Protocol {
|
|
|
61
60
|
* some other places use datasource object
|
|
62
61
|
*/
|
|
63
62
|
const name = typeof datasource === 'string' ? datasource : datasource.kind;
|
|
64
|
-
protocolDebug('Initializing protocol with datasource %O', datasource);
|
|
65
63
|
this.name = Protocol.normalizeName(name);
|
|
66
64
|
protocolDebug('Initializing protocol %s', this.name);
|
|
67
65
|
switch (this.name) {
|
|
@@ -77,9 +75,6 @@ class Protocol {
|
|
|
77
75
|
case 'near':
|
|
78
76
|
this.config = nearProtocol;
|
|
79
77
|
break;
|
|
80
|
-
case 'subgraph':
|
|
81
|
-
this.config = subgraphProtocol;
|
|
82
|
-
break;
|
|
83
78
|
case 'substreams':
|
|
84
79
|
this.config = substreamsProtocol;
|
|
85
80
|
/**
|
|
@@ -104,7 +99,6 @@ class Protocol {
|
|
|
104
99
|
near: ['near'],
|
|
105
100
|
cosmos: ['cosmos'],
|
|
106
101
|
substreams: ['substreams'],
|
|
107
|
-
subgraph: ['subgraph'],
|
|
108
102
|
});
|
|
109
103
|
}
|
|
110
104
|
static availableNetworks() {
|
|
@@ -159,7 +153,6 @@ class Protocol {
|
|
|
159
153
|
'uni-3', // Juno testnet
|
|
160
154
|
],
|
|
161
155
|
substreams: ['mainnet'],
|
|
162
|
-
subgraph: ['mainnet'],
|
|
163
156
|
});
|
|
164
157
|
}
|
|
165
158
|
static normalizeName(name) {
|
|
@@ -262,20 +255,6 @@ const ethereumProtocol = {
|
|
|
262
255
|
manifestScaffold: EthereumManifestScaffold,
|
|
263
256
|
mappingScaffold: EthereumMappingScaffold,
|
|
264
257
|
};
|
|
265
|
-
const subgraphProtocol = {
|
|
266
|
-
displayName: 'Subgraph',
|
|
267
|
-
abi: abi_1.default,
|
|
268
|
-
contract: undefined,
|
|
269
|
-
getTemplateCodeGen: undefined,
|
|
270
|
-
getTypeGenerator(options) {
|
|
271
|
-
return new type_generator_1.default(options);
|
|
272
|
-
},
|
|
273
|
-
getSubgraph(options) {
|
|
274
|
-
return new subgraph_5.default(options);
|
|
275
|
-
},
|
|
276
|
-
manifestScaffold: undefined,
|
|
277
|
-
mappingScaffold: undefined,
|
|
278
|
-
};
|
|
279
258
|
const nearProtocol = {
|
|
280
259
|
displayName: 'NEAR',
|
|
281
260
|
abi: undefined,
|
|
@@ -295,7 +274,7 @@ const substreamsProtocol = {
|
|
|
295
274
|
getTypeGenerator: undefined,
|
|
296
275
|
getTemplateCodeGen: undefined,
|
|
297
276
|
getSubgraph(options) {
|
|
298
|
-
return new
|
|
277
|
+
return new subgraph_5.default(options);
|
|
299
278
|
},
|
|
300
279
|
manifestScaffold: SubstreamsManifestScaffold,
|
|
301
280
|
mappingScaffold: undefined,
|
package/dist/schema.d.ts
CHANGED
|
@@ -7,5 +7,4 @@ 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>;
|
|
11
10
|
}
|
package/dist/schema.js
CHANGED
|
@@ -46,14 +46,5 @@ class Schema {
|
|
|
46
46
|
const ast = graphql.parse(document);
|
|
47
47
|
return new Schema(filename, document, ast);
|
|
48
48
|
}
|
|
49
|
-
static async loadFromString(filename, document) {
|
|
50
|
-
try {
|
|
51
|
-
const ast = graphql.parse(document);
|
|
52
|
-
return new Schema(filename, document, ast);
|
|
53
|
-
}
|
|
54
|
-
catch (e) {
|
|
55
|
-
throw new Error(`Failed to load schema from string: ${e.message}`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
49
|
}
|
|
59
50
|
exports.default = Schema;
|
package/dist/type-generator.d.ts
CHANGED
|
@@ -9,8 +9,6 @@ export interface TypeGeneratorOptions {
|
|
|
9
9
|
skipMigrations?: boolean;
|
|
10
10
|
uncrashable: boolean;
|
|
11
11
|
uncrashableConfig: string;
|
|
12
|
-
subgraphSources: string[];
|
|
13
|
-
ipfsUrl: string;
|
|
14
12
|
}
|
|
15
13
|
export default class TypeGenerator {
|
|
16
14
|
private sourceDir;
|
|
@@ -19,14 +17,12 @@ export default class TypeGenerator {
|
|
|
19
17
|
private protocolTypeGenerator;
|
|
20
18
|
constructor(options: TypeGeneratorOptions);
|
|
21
19
|
generateTypes(): Promise<boolean | undefined>;
|
|
22
|
-
loadSubgraphSchemaFromIPFS(ipfsClient: any, manifest: string): Promise<string>;
|
|
23
20
|
generateUncrashableEntities(graphSchema: any): Promise<any>;
|
|
24
21
|
loadSubgraph({ quiet }?: {
|
|
25
22
|
quiet: boolean;
|
|
26
23
|
}): Promise<any>;
|
|
27
24
|
loadSchema(subgraph: immutable.Map<any, any>): Promise<any>;
|
|
28
|
-
generateTypesForSchema(schema: any
|
|
29
|
-
outputDir?: string): Promise<any>;
|
|
25
|
+
generateTypesForSchema(schema: any): Promise<any>;
|
|
30
26
|
generateTypesForDataSourceTemplates(subgraph: immutable.Map<any, any>): Promise<any>;
|
|
31
27
|
getFilesToWatch(): Promise<string[]>;
|
|
32
28
|
watchAndGenerateTypes(): Promise<void>;
|
package/dist/type-generator.js
CHANGED
|
@@ -31,17 +31,13 @@ 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"));
|
|
36
34
|
const prettier_1 = __importDefault(require("prettier"));
|
|
37
35
|
// @ts-expect-error TODO: type out if necessary
|
|
38
36
|
const Index_bs_js_1 = __importDefault(require("@float-capital/float-subgraph-uncrashable/src/Index.bs.js"));
|
|
39
37
|
const template_1 = __importDefault(require("./codegen/template"));
|
|
40
38
|
const typescript_1 = require("./codegen/typescript");
|
|
41
|
-
const compiler_1 = require("./command-helpers/compiler");
|
|
42
39
|
const fs_1 = require("./command-helpers/fs");
|
|
43
40
|
const spinner_1 = require("./command-helpers/spinner");
|
|
44
|
-
const constants_1 = require("./constants");
|
|
45
41
|
const debug_1 = __importDefault(require("./debug"));
|
|
46
42
|
const migrations_1 = require("./migrations");
|
|
47
43
|
const schema_1 = __importDefault(require("./schema"));
|
|
@@ -70,10 +66,6 @@ class TypeGenerator {
|
|
|
70
66
|
process.exit(0);
|
|
71
67
|
return;
|
|
72
68
|
}
|
|
73
|
-
if (this.options.subgraphSources.length > 0) {
|
|
74
|
-
typeGenDebug.extend('generateTypes')('Subgraph uses subgraph datasources.');
|
|
75
|
-
toolbox.print.success('Subgraph uses subgraph datasources.');
|
|
76
|
-
}
|
|
77
69
|
try {
|
|
78
70
|
if (!this.options.skipMigrations && this.options.subgraphManifest) {
|
|
79
71
|
await (0, migrations_1.applyMigrations)({
|
|
@@ -98,20 +90,6 @@ class TypeGenerator {
|
|
|
98
90
|
const schema = await this.loadSchema(subgraph);
|
|
99
91
|
typeGenDebug.extend('generateTypes')('Generating types for schema');
|
|
100
92
|
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
|
-
}
|
|
115
93
|
toolbox.print.success('\nTypes generated successfully\n');
|
|
116
94
|
if (this.options.uncrashable && this.options.uncrashableConfig) {
|
|
117
95
|
await this.generateUncrashableEntities(schema);
|
|
@@ -123,32 +101,6 @@ class TypeGenerator {
|
|
|
123
101
|
return false;
|
|
124
102
|
}
|
|
125
103
|
}
|
|
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
|
-
}
|
|
152
104
|
async generateUncrashableEntities(graphSchema) {
|
|
153
105
|
const ast = graphql.parse(graphSchema.document);
|
|
154
106
|
const entityDefinitions = ast['definitions'];
|
|
@@ -180,8 +132,7 @@ class TypeGenerator {
|
|
|
180
132
|
return schema_1.default.load(absolutePath);
|
|
181
133
|
});
|
|
182
134
|
}
|
|
183
|
-
async generateTypesForSchema(schema
|
|
184
|
-
outputDir = this.options.outputDir) {
|
|
135
|
+
async generateTypesForSchema(schema) {
|
|
185
136
|
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) => {
|
|
186
137
|
// Generate TypeScript module from schema
|
|
187
138
|
const codeGenerator = schema.codeGenerator();
|
|
@@ -193,7 +144,7 @@ class TypeGenerator {
|
|
|
193
144
|
].join('\n'), {
|
|
194
145
|
parser: 'typescript',
|
|
195
146
|
});
|
|
196
|
-
const outputFile = path_1.default.join(outputDir,
|
|
147
|
+
const outputFile = path_1.default.join(this.options.outputDir, 'schema.ts');
|
|
197
148
|
(0, spinner_1.step)(spinner, 'Write types to', (0, fs_1.displayPath)(outputFile));
|
|
198
149
|
await fs_extra_1.default.mkdirs(path_1.default.dirname(outputFile));
|
|
199
150
|
await fs_extra_1.default.writeFile(outputFile, code);
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.88.0
|
|
2
|
+
"version": "0.88.0",
|
|
3
3
|
"commands": {
|
|
4
4
|
"add": {
|
|
5
5
|
"id": "add",
|
|
@@ -239,14 +239,6 @@
|
|
|
239
239
|
"summary": "Generate Float Subgraph Uncrashable helper file.",
|
|
240
240
|
"allowNo": false
|
|
241
241
|
},
|
|
242
|
-
"ipfs": {
|
|
243
|
-
"name": "ipfs",
|
|
244
|
-
"type": "option",
|
|
245
|
-
"char": "i",
|
|
246
|
-
"summary": "IPFS node to use for fetching subgraph data.",
|
|
247
|
-
"multiple": false,
|
|
248
|
-
"default": "https://api.thegraph.com/ipfs/api/v0"
|
|
249
|
-
},
|
|
250
242
|
"uncrashable-config": {
|
|
251
243
|
"name": "uncrashable-config",
|
|
252
244
|
"type": "option",
|
|
@@ -461,8 +453,7 @@
|
|
|
461
453
|
"ethereum",
|
|
462
454
|
"near",
|
|
463
455
|
"cosmos",
|
|
464
|
-
"substreams"
|
|
465
|
-
"subgraph"
|
|
456
|
+
"substreams"
|
|
466
457
|
]
|
|
467
458
|
},
|
|
468
459
|
"node": {
|
package/package.json
CHANGED
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
scalar Boolean
|
|
11
|
-
scalar JSON
|
|
12
|
-
|
|
13
|
-
type SubgraphManifest {
|
|
14
|
-
specVersion: String!
|
|
15
|
-
features: [String!]
|
|
16
|
-
schema: Schema!
|
|
17
|
-
description: String
|
|
18
|
-
repository: String
|
|
19
|
-
graft: Graft
|
|
20
|
-
dataSources: [DataSource!]!
|
|
21
|
-
indexerHints: IndexerHints
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type Schema {
|
|
25
|
-
file: File!
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type DataSource {
|
|
29
|
-
kind: String!
|
|
30
|
-
name: String!
|
|
31
|
-
network: String
|
|
32
|
-
context: JSON
|
|
33
|
-
source: ContractSource!
|
|
34
|
-
mapping: ContractMapping!
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type ContractSource {
|
|
38
|
-
address: String!
|
|
39
|
-
startBlock: BigInt
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type ContractMapping {
|
|
43
|
-
kind: String
|
|
44
|
-
apiVersion: String!
|
|
45
|
-
language: String!
|
|
46
|
-
file: File!
|
|
47
|
-
abis: [ContractABI!]!
|
|
48
|
-
entities: [String!]!
|
|
49
|
-
handlers: [EntityHandler!]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type ContractABI {
|
|
53
|
-
name: String!
|
|
54
|
-
file: File!
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
type EntityHandler {
|
|
58
|
-
handler: String!
|
|
59
|
-
entity: String!
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
type Graft {
|
|
63
|
-
base: String!
|
|
64
|
-
block: BigInt!
|
|
65
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapping = exports.source = void 0;
|
|
4
|
-
const source = ({ spkgPath }) => `
|
|
5
|
-
package:
|
|
6
|
-
moduleName: graph_out
|
|
7
|
-
file: ${spkgPath || 'substreams-eth-block-meta-v0.1.0.spkg'}`;
|
|
8
|
-
exports.source = source;
|
|
9
|
-
const mapping = () => `
|
|
10
|
-
apiVersion: 0.0.5
|
|
11
|
-
kind: substreams/graph-entities`;
|
|
12
|
-
exports.mapping = mapping;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import immutable from 'immutable';
|
|
2
|
-
import { Subgraph, SubgraphOptions } from '../subgraph';
|
|
3
|
-
export default class SubgraphDS implements Subgraph {
|
|
4
|
-
manifest: SubgraphOptions['manifest'];
|
|
5
|
-
resolveFile: SubgraphOptions['resolveFile'];
|
|
6
|
-
protocol: SubgraphOptions['protocol'];
|
|
7
|
-
constructor(options: SubgraphOptions);
|
|
8
|
-
validateManifest(): immutable.List<unknown>;
|
|
9
|
-
handlerTypes(): immutable.List<never>;
|
|
10
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
-
class SubgraphDS {
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.manifest = options.manifest;
|
|
10
|
-
this.resolveFile = options.resolveFile;
|
|
11
|
-
this.protocol = options.protocol;
|
|
12
|
-
}
|
|
13
|
-
validateManifest() {
|
|
14
|
-
return immutable_1.default.List();
|
|
15
|
-
}
|
|
16
|
-
handlerTypes() {
|
|
17
|
-
return immutable_1.default.List([]);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.default = SubgraphDS;
|