@graphprotocol/graph-cli 0.37.3 → 0.37.4
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 +8 -0
- package/package.json +5 -1
- package/babel.config.js +0 -3
- package/jest.config.js +0 -175
- package/src/bin.ts +0 -6
- package/src/cli.ts +0 -30
- package/src/codegen/schema.test.ts +0 -460
- package/src/codegen/schema.ts +0 -299
- package/src/codegen/template.ts +0 -45
- package/src/codegen/types/conversions.ts +0 -358
- package/src/codegen/types/index.test.ts +0 -715
- package/src/codegen/types/index.ts +0 -111
- package/src/codegen/typescript.ts +0 -224
- package/src/codegen/util.test.ts +0 -112
- package/src/codegen/util.ts +0 -54
- package/src/command-helpers/abi.ts +0 -99
- package/src/command-helpers/auth.ts +0 -46
- package/src/command-helpers/compiler.ts +0 -60
- package/src/command-helpers/data-sources.ts +0 -36
- package/src/command-helpers/fs.ts +0 -5
- package/src/command-helpers/gluegun.ts +0 -52
- package/src/command-helpers/ipfs-http-client.d.ts +0 -1
- package/src/command-helpers/ipfs.ts +0 -3
- package/src/command-helpers/jsonrpc.ts +0 -22
- package/src/command-helpers/network.test.ts +0 -85
- package/src/command-helpers/network.ts +0 -133
- package/src/command-helpers/node.ts +0 -46
- package/src/command-helpers/scaffold.ts +0 -174
- package/src/command-helpers/spinner.ts +0 -60
- package/src/command-helpers/studio.test.ts +0 -84
- package/src/command-helpers/studio.ts +0 -25
- package/src/command-helpers/subgraph.ts +0 -21
- package/src/command-helpers/version.test.ts +0 -241
- package/src/command-helpers/version.ts +0 -53
- package/src/commands/add.ts +0 -220
- package/src/commands/auth.ts +0 -138
- package/src/commands/binary-install-raw.d.ts +0 -1
- package/src/commands/build.ts +0 -147
- package/src/commands/codegen.ts +0 -123
- package/src/commands/create.ts +0 -109
- package/src/commands/deploy.ts +0 -388
- package/src/commands/init.ts +0 -1060
- package/src/commands/local.ts +0 -539
- package/src/commands/remove.ts +0 -110
- package/src/commands/test.ts +0 -369
- package/src/compiler/asc.ts +0 -77
- package/src/compiler/index.ts +0 -677
- package/src/debug.ts +0 -15
- package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
- package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
- package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
- package/src/migrations/spec_version_0_0_2.ts +0 -24
- package/src/migrations/spec_version_0_0_3.ts +0 -29
- package/src/migrations/util/load-manifest.ts +0 -10
- package/src/migrations/util/versions.ts +0 -27
- package/src/migrations.ts +0 -33
- package/src/protocols/arweave/manifest.graphql +0 -57
- package/src/protocols/arweave/scaffold/manifest.ts +0 -14
- package/src/protocols/arweave/scaffold/mapping.ts +0 -49
- package/src/protocols/arweave/subgraph.ts +0 -22
- package/src/protocols/contract.ts +0 -9
- package/src/protocols/cosmos/manifest.graphql +0 -76
- package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
- package/src/protocols/cosmos/scaffold/mapping.ts +0 -35
- package/src/protocols/cosmos/subgraph.ts +0 -27
- package/src/protocols/ethereum/abi.ts +0 -153
- package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
- package/src/protocols/ethereum/codegen/abi.ts +0 -719
- package/src/protocols/ethereum/codegen/template.ts +0 -41
- package/src/protocols/ethereum/contract.ts +0 -24
- package/src/protocols/ethereum/manifest.graphql +0 -94
- package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
- package/src/protocols/ethereum/scaffold/mapping.ts +0 -76
- package/src/protocols/ethereum/subgraph.ts +0 -189
- package/src/protocols/ethereum/type-generator.ts +0 -191
- package/src/protocols/index.ts +0 -287
- package/src/protocols/ipfs/codegen/file_template.ts +0 -43
- package/src/protocols/near/contract.ts +0 -47
- package/src/protocols/near/manifest.graphql +0 -64
- package/src/protocols/near/scaffold/manifest.ts +0 -13
- package/src/protocols/near/scaffold/mapping.ts +0 -35
- package/src/protocols/near/subgraph.ts +0 -22
- package/src/protocols/subgraph.ts +0 -12
- package/src/protocols/substreams/manifest.graphql +0 -45
- package/src/protocols/substreams/scaffold/manifest.ts +0 -8
- package/src/protocols/substreams/subgraph.ts +0 -22
- package/src/scaffold/cosmos.test.ts +0 -83
- package/src/scaffold/ethereum.test.ts +0 -512
- package/src/scaffold/index.ts +0 -172
- package/src/scaffold/mapping.ts +0 -44
- package/src/scaffold/near.test.ts +0 -86
- package/src/scaffold/schema.ts +0 -89
- package/src/scaffold/tests.ts +0 -217
- package/src/schema.ts +0 -26
- package/src/subgraph.ts +0 -302
- package/src/type-generator.ts +0 -266
- package/src/validation/contract.ts +0 -51
- package/src/validation/index.ts +0 -5
- package/src/validation/manifest.ts +0 -360
- package/src/validation/schema.test.ts +0 -38
- package/src/validation/schema.ts +0 -957
- package/src/watcher.ts +0 -96
- package/tests/cli/globalSetup.ts +0 -8
- package/tests/cli/globalTeardown.ts +0 -8
- package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
- package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
- package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
- package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
- package/tests/cli/init/ethereum/from-contract.stderr +0 -16
- package/tests/cli/init/ethereum/from-contract.stdout +0 -12
- package/tests/cli/init/ethereum/from-example.stderr +0 -12
- package/tests/cli/init/ethereum/from-example.stdout +0 -12
- package/tests/cli/init/near/from-contract.stderr +0 -14
- package/tests/cli/init/near/from-contract.stdout +0 -12
- package/tests/cli/init.test.ts +0 -157
- package/tests/cli/spawn-command.d.ts +0 -7
- package/tests/cli/util.ts +0 -132
- package/tests/cli/validation/abi-not-found/Abi.json +0 -7
- package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
- package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
- package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
- package/tests/cli/validation/abi-not-found copy.stderr +0 -13
- package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
- package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
- package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
- package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
- package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
- package/tests/cli/validation/call-function-not-found.stderr +0 -10
- package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
- package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
- package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
- package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
- package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
- package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
- package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-network-names.stderr +0 -10
- package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
- package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
- package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
- package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
- package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
- package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
- package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
- package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
- package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
- package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
- package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
- package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
- package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
- package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
- package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
- package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
- package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
- package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
- package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
- package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
- package/tests/cli/validation/duplicate-template-name.stderr +0 -5
- package/tests/cli/validation/entity-field-args/Abi.json +0 -7
- package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
- package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
- package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
- package/tests/cli/validation/entity-field-args.stderr +0 -5
- package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
- package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
- package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
- package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
- package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
- package/tests/cli/validation/event-not-found/Abi.json +0 -7
- package/tests/cli/validation/event-not-found/mapping.ts +0 -0
- package/tests/cli/validation/event-not-found/schema.graphql +0 -3
- package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
- package/tests/cli/validation/event-not-found.stderr +0 -12
- package/tests/cli/validation/example-values-found/Abi.json +0 -7
- package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
- package/tests/cli/validation/example-values-found/mapping.ts +0 -0
- package/tests/cli/validation/example-values-found/schema.graphql +0 -3
- package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
- package/tests/cli/validation/example-values-found.stderr +0 -34
- package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
- package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
- package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
- package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-abis.stderr +0 -5
- package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
- package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
- package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
- package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
- package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
- package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
- package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
- package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
- package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
- package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
- package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
- package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
- package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
- package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
- package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
- package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
- package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
- package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
- package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
- package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
- package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
- package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
- package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
- package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
- package/tests/cli/validation/invalid-manifest.stderr +0 -28
- package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
- package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
- package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
- package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
- package/tests/cli/validation/missing-entity-id.stderr +0 -5
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
- package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
- package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
- package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
- package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
- package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
- package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
- package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
- package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
- package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
- package/tests/cli/validation/no-network-names/Abi.json +0 -7
- package/tests/cli/validation/no-network-names/mapping.ts +0 -0
- package/tests/cli/validation/no-network-names/schema.graphql +0 -3
- package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
- package/tests/cli/validation/no-network-names.stderr +0 -34
- package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
- package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
- package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
- package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
- package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
- package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
- package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
- package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
- package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
- package/tests/cli/validation.test.ts +0 -226
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -19
package/src/commands/local.ts
DELETED
|
@@ -1,539 +0,0 @@
|
|
|
1
|
-
import { ChildProcess, spawn } from 'child_process';
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import net from 'net';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import compose from 'docker-compose';
|
|
7
|
-
import { GluegunToolbox } from 'gluegun';
|
|
8
|
-
import stripAnsi from 'strip-ansi';
|
|
9
|
-
import tmp from 'tmp-promise';
|
|
10
|
-
import { fixParameters } from '../command-helpers/gluegun';
|
|
11
|
-
import { step, withSpinner } from '../command-helpers/spinner';
|
|
12
|
-
|
|
13
|
-
// Clean up temporary files even when an uncaught exception occurs
|
|
14
|
-
tmp.setGracefulCleanup();
|
|
15
|
-
|
|
16
|
-
const HELP = `
|
|
17
|
-
${chalk.bold('graph local')} [options] ${chalk.bold('<local-command>')}
|
|
18
|
-
|
|
19
|
-
Options:
|
|
20
|
-
|
|
21
|
-
-h, --help Show usage information
|
|
22
|
-
--node-logs Print the Graph Node logs (optional)
|
|
23
|
-
--ethereum-logs Print the Ethereum logs (optional)
|
|
24
|
-
--compose-file <file> Custom Docker Compose file for additional services (optional)
|
|
25
|
-
--node-image <image> Custom Graph Node image to test against (default: graphprotocol/graph-node:latest)
|
|
26
|
-
--standalone-node <cmd> Use a standalone Graph Node outside Docker Compose (optional)
|
|
27
|
-
--standalone-node-args Custom arguments to be passed to the standalone Graph Node (optional)
|
|
28
|
-
--skip-wait-for-ipfs Don't wait for IPFS to be up at localhost:15001 (optional)
|
|
29
|
-
--skip-wait-for-ethereum Don't wait for Ethereum to be up at localhost:18545 (optional)
|
|
30
|
-
--skip-wait-for-postgres Don't wait for Postgres to be up at localhost:15432 (optional)
|
|
31
|
-
--timeout Time to wait for service containers. (optional, defaults to 120000 milliseconds)
|
|
32
|
-
`;
|
|
33
|
-
|
|
34
|
-
export interface LocalOptions {
|
|
35
|
-
help?: boolean;
|
|
36
|
-
nodeLogs?: boolean;
|
|
37
|
-
ethereumLogs?: boolean;
|
|
38
|
-
composeFile?: string;
|
|
39
|
-
nodeImage?: string;
|
|
40
|
-
standaloneNode?: string;
|
|
41
|
-
standaloneNodeArgs?: string;
|
|
42
|
-
skipWaitForIpfs?: boolean;
|
|
43
|
-
skipWaitForEthereum?: boolean;
|
|
44
|
-
skipWaitForPostgres?: boolean;
|
|
45
|
-
timeout?: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default {
|
|
49
|
-
description: 'Runs local tests against a Graph Node environment (using Ganache by default)',
|
|
50
|
-
run: async (toolbox: GluegunToolbox) => {
|
|
51
|
-
// Obtain tools
|
|
52
|
-
const { filesystem, print } = toolbox;
|
|
53
|
-
|
|
54
|
-
// Parse CLI parameters
|
|
55
|
-
let {
|
|
56
|
-
composeFile,
|
|
57
|
-
ethereumLogs,
|
|
58
|
-
h,
|
|
59
|
-
help,
|
|
60
|
-
nodeImage,
|
|
61
|
-
nodeLogs,
|
|
62
|
-
skipWaitForEthereum,
|
|
63
|
-
skipWaitForIpfs,
|
|
64
|
-
skipWaitForPostgres,
|
|
65
|
-
standaloneNode,
|
|
66
|
-
standaloneNodeArgs,
|
|
67
|
-
timeout,
|
|
68
|
-
} = toolbox.parameters.options;
|
|
69
|
-
|
|
70
|
-
// Support both short and long option variants
|
|
71
|
-
help ||= h;
|
|
72
|
-
|
|
73
|
-
// Extract test command
|
|
74
|
-
const params = fixParameters(toolbox.parameters, {
|
|
75
|
-
ethereumLogs,
|
|
76
|
-
h,
|
|
77
|
-
help,
|
|
78
|
-
nodeLogs,
|
|
79
|
-
skipWaitForEthereum,
|
|
80
|
-
skipWaitForIpfs,
|
|
81
|
-
skipWaitForPostgres,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Show help text if requested
|
|
85
|
-
if (help) {
|
|
86
|
-
print.info(HELP);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (params.length == 0) {
|
|
91
|
-
print.error(`Test command not provided as the last argument`);
|
|
92
|
-
process.exitCode = 1;
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const testCommand = params[0];
|
|
97
|
-
|
|
98
|
-
// Obtain the Docker Compose file for services that the tests run against
|
|
99
|
-
composeFile ||= path.join(
|
|
100
|
-
__dirname,
|
|
101
|
-
'..',
|
|
102
|
-
'..',
|
|
103
|
-
'resources',
|
|
104
|
-
'test',
|
|
105
|
-
standaloneNode ? 'docker-compose-standalone-node.yml' : 'docker-compose.yml',
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
// parse timeout. Defaults to 120 seconds
|
|
109
|
-
timeout = Math.abs(parseInt(timeout)) || 120_000;
|
|
110
|
-
|
|
111
|
-
if (!filesystem.exists(composeFile)) {
|
|
112
|
-
print.error(`Docker Compose file \`${composeFile}\` not found`);
|
|
113
|
-
process.exitCode = 1;
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Create temporary directory to operate in
|
|
118
|
-
const { path: tempdir } = await tmp.dir({ prefix: 'graph-test', unsafeCleanup: true });
|
|
119
|
-
try {
|
|
120
|
-
await configureTestEnvironment(toolbox, tempdir, composeFile, nodeImage);
|
|
121
|
-
} catch (e) {
|
|
122
|
-
process.exitCode = 1;
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Bring up test environment
|
|
127
|
-
try {
|
|
128
|
-
await startTestEnvironment(tempdir);
|
|
129
|
-
} catch (e) {
|
|
130
|
-
print.error(e);
|
|
131
|
-
process.exitCode = 1;
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Wait for test environment to come up
|
|
136
|
-
try {
|
|
137
|
-
await waitForTestEnvironment({
|
|
138
|
-
skipWaitForEthereum,
|
|
139
|
-
skipWaitForIpfs,
|
|
140
|
-
skipWaitForPostgres,
|
|
141
|
-
timeout,
|
|
142
|
-
});
|
|
143
|
-
} catch (e) {
|
|
144
|
-
await stopTestEnvironment(tempdir);
|
|
145
|
-
process.exitCode = 1;
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Bring up Graph Node separately, if a standalone node is used
|
|
150
|
-
let nodeProcess;
|
|
151
|
-
const nodeOutputChunks: Buffer[] = [];
|
|
152
|
-
if (standaloneNode) {
|
|
153
|
-
try {
|
|
154
|
-
nodeProcess = await startGraphNode(standaloneNode, standaloneNodeArgs, nodeOutputChunks);
|
|
155
|
-
} catch (e) {
|
|
156
|
-
toolbox.print.error('');
|
|
157
|
-
toolbox.print.error(' Graph Node');
|
|
158
|
-
toolbox.print.error(' ----------');
|
|
159
|
-
toolbox.print.error(indent(' ', Buffer.concat(nodeOutputChunks).toString('utf-8')));
|
|
160
|
-
toolbox.print.error('');
|
|
161
|
-
await stopTestEnvironment(tempdir);
|
|
162
|
-
process.exitCode = 1;
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Wait for Graph Node to come up
|
|
168
|
-
try {
|
|
169
|
-
await waitForGraphNode(timeout);
|
|
170
|
-
} catch (e) {
|
|
171
|
-
toolbox.print.error('');
|
|
172
|
-
toolbox.print.error(' Graph Node');
|
|
173
|
-
toolbox.print.error(' ----------');
|
|
174
|
-
toolbox.print.error(
|
|
175
|
-
indent(' ', await collectGraphNodeLogs(tempdir, standaloneNode, nodeOutputChunks)),
|
|
176
|
-
);
|
|
177
|
-
toolbox.print.error('');
|
|
178
|
-
await stopTestEnvironment(tempdir);
|
|
179
|
-
process.exitCode = 1;
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Run tests
|
|
184
|
-
const result = await runTests(testCommand);
|
|
185
|
-
|
|
186
|
-
// Bring down Graph Node, if a standalone node is used
|
|
187
|
-
if (nodeProcess) {
|
|
188
|
-
try {
|
|
189
|
-
await stopGraphNode(nodeProcess);
|
|
190
|
-
} catch (e) {
|
|
191
|
-
// do nothing (the spinner already logs the problem)
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (result.exitCode == 0) {
|
|
196
|
-
toolbox.print.success('✔ Tests passed');
|
|
197
|
-
} else {
|
|
198
|
-
toolbox.print.error('✖ Tests failed');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Capture logs
|
|
202
|
-
nodeLogs =
|
|
203
|
-
nodeLogs || result.exitCode !== 0
|
|
204
|
-
? await collectGraphNodeLogs(tempdir, standaloneNode, nodeOutputChunks)
|
|
205
|
-
: undefined;
|
|
206
|
-
ethereumLogs = ethereumLogs ? await collectEthereumLogs(tempdir) : undefined;
|
|
207
|
-
|
|
208
|
-
// Bring down the test environment
|
|
209
|
-
try {
|
|
210
|
-
await stopTestEnvironment(tempdir);
|
|
211
|
-
} catch (e) {
|
|
212
|
-
// do nothing (the spinner already logs the problem)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (nodeLogs) {
|
|
216
|
-
toolbox.print.info('');
|
|
217
|
-
toolbox.print.info(' Graph node');
|
|
218
|
-
toolbox.print.info(' ----------');
|
|
219
|
-
toolbox.print.info('');
|
|
220
|
-
toolbox.print.info(indent(' ', nodeLogs));
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (ethereumLogs) {
|
|
224
|
-
toolbox.print.info('');
|
|
225
|
-
toolbox.print.info(' Ethereum');
|
|
226
|
-
toolbox.print.info(' --------');
|
|
227
|
-
toolbox.print.info('');
|
|
228
|
-
toolbox.print.info(indent(' ', ethereumLogs));
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Always print the test output
|
|
232
|
-
toolbox.print.info('');
|
|
233
|
-
toolbox.print.info(' Output');
|
|
234
|
-
toolbox.print.info(' ------');
|
|
235
|
-
toolbox.print.info('');
|
|
236
|
-
toolbox.print.info(indent(' ', result.output));
|
|
237
|
-
|
|
238
|
-
// Propagate the exit code from the test run
|
|
239
|
-
process.exitCode = result.exitCode;
|
|
240
|
-
},
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Indents all lines of a string
|
|
245
|
-
*/
|
|
246
|
-
const indent = (indentation: string, str: string) =>
|
|
247
|
-
str
|
|
248
|
-
.split('\n')
|
|
249
|
-
.map(s => `${indentation}${s}`)
|
|
250
|
-
// Remove whitespace from empty lines
|
|
251
|
-
.map(s => s.replace(/^\s+$/g, ''))
|
|
252
|
-
.join('\n');
|
|
253
|
-
|
|
254
|
-
const configureTestEnvironment = async (
|
|
255
|
-
toolbox: GluegunToolbox,
|
|
256
|
-
tempdir: string,
|
|
257
|
-
composeFile: string,
|
|
258
|
-
nodeImage: string,
|
|
259
|
-
) =>
|
|
260
|
-
await withSpinner(
|
|
261
|
-
`Configure test environment`,
|
|
262
|
-
`Failed to configure test environment`,
|
|
263
|
-
`Warnings configuring test environment`,
|
|
264
|
-
async () => {
|
|
265
|
-
// Temporary compose file
|
|
266
|
-
const tempComposeFile = path.join(tempdir, 'compose', 'docker-compose.yml');
|
|
267
|
-
|
|
268
|
-
// Copy the compose file to the temporary directory
|
|
269
|
-
toolbox.filesystem.copy(composeFile, tempComposeFile);
|
|
270
|
-
|
|
271
|
-
// Substitute the graph-node image with the custom one, if appropriate
|
|
272
|
-
if (nodeImage) {
|
|
273
|
-
await toolbox.patching.replace(
|
|
274
|
-
tempComposeFile,
|
|
275
|
-
'graphprotocol/graph-node:latest',
|
|
276
|
-
nodeImage,
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
const waitFor = async (timeout: number, testFn: () => void) => {
|
|
283
|
-
const deadline = Date.now() + timeout;
|
|
284
|
-
let error: Error | undefined = undefined;
|
|
285
|
-
return new Promise((resolve, reject) => {
|
|
286
|
-
const check = async () => {
|
|
287
|
-
if (Date.now() > deadline) {
|
|
288
|
-
reject(error);
|
|
289
|
-
} else {
|
|
290
|
-
try {
|
|
291
|
-
const result = await testFn();
|
|
292
|
-
resolve(result);
|
|
293
|
-
} catch (e) {
|
|
294
|
-
error = e;
|
|
295
|
-
setTimeout(check, 500);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
setTimeout(check, 0);
|
|
301
|
-
});
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
const startTestEnvironment = async (tempdir: string) =>
|
|
305
|
-
await withSpinner(
|
|
306
|
-
`Start test environment`,
|
|
307
|
-
`Failed to start test environment`,
|
|
308
|
-
`Warnings starting test environment`,
|
|
309
|
-
async _spinner => {
|
|
310
|
-
// Bring up the test environment
|
|
311
|
-
await compose.upAll({
|
|
312
|
-
cwd: path.join(tempdir, 'compose'),
|
|
313
|
-
});
|
|
314
|
-
},
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
const waitForTestEnvironment = async ({
|
|
318
|
-
skipWaitForEthereum,
|
|
319
|
-
skipWaitForIpfs,
|
|
320
|
-
skipWaitForPostgres,
|
|
321
|
-
timeout,
|
|
322
|
-
}: {
|
|
323
|
-
skipWaitForEthereum: boolean;
|
|
324
|
-
skipWaitForIpfs: boolean;
|
|
325
|
-
skipWaitForPostgres: boolean;
|
|
326
|
-
timeout: number;
|
|
327
|
-
}) =>
|
|
328
|
-
await withSpinner(
|
|
329
|
-
`Wait for test environment`,
|
|
330
|
-
`Failed to wait for test environment`,
|
|
331
|
-
`Warnings waiting for test environment`,
|
|
332
|
-
async spinner => {
|
|
333
|
-
// Wait 10s for IPFS (if desired)
|
|
334
|
-
if (skipWaitForIpfs) {
|
|
335
|
-
step(spinner, 'Skip waiting for IPFS');
|
|
336
|
-
} else {
|
|
337
|
-
await waitFor(
|
|
338
|
-
timeout,
|
|
339
|
-
async () =>
|
|
340
|
-
new Promise((resolve, reject) => {
|
|
341
|
-
http
|
|
342
|
-
.get('http://localhost:15001/api/v0/version', () => {
|
|
343
|
-
resolve();
|
|
344
|
-
})
|
|
345
|
-
.on('error', e => {
|
|
346
|
-
reject(new Error(`Could not connect to IPFS: ${e}`));
|
|
347
|
-
});
|
|
348
|
-
}),
|
|
349
|
-
);
|
|
350
|
-
step(spinner, 'IPFS is up');
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Wait 10s for Ethereum (if desired)
|
|
354
|
-
if (skipWaitForEthereum) {
|
|
355
|
-
step(spinner, 'Skip waiting for Ethereum');
|
|
356
|
-
} else {
|
|
357
|
-
await waitFor(
|
|
358
|
-
timeout,
|
|
359
|
-
async () =>
|
|
360
|
-
new Promise((resolve, reject) => {
|
|
361
|
-
http
|
|
362
|
-
.get('http://localhost:18545', () => {
|
|
363
|
-
resolve();
|
|
364
|
-
})
|
|
365
|
-
.on('error', e => {
|
|
366
|
-
reject(new Error(`Could not connect to Ethereum: ${e}`));
|
|
367
|
-
});
|
|
368
|
-
}),
|
|
369
|
-
);
|
|
370
|
-
step(spinner, 'Ethereum is up');
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Wait 10s for Postgres (if desired)
|
|
374
|
-
if (skipWaitForPostgres) {
|
|
375
|
-
step(spinner, 'Skip waiting for Postgres');
|
|
376
|
-
} else {
|
|
377
|
-
await waitFor(
|
|
378
|
-
timeout,
|
|
379
|
-
async () =>
|
|
380
|
-
new Promise((resolve, reject) => {
|
|
381
|
-
try {
|
|
382
|
-
const socket = net.connect(15_432, 'localhost', () => resolve());
|
|
383
|
-
socket.on('error', e => reject(new Error(`Could not connect to Postgres: ${e}`)));
|
|
384
|
-
socket.end();
|
|
385
|
-
} catch (e) {
|
|
386
|
-
reject(new Error(`Could not connect to Postgres: ${e}`));
|
|
387
|
-
}
|
|
388
|
-
}),
|
|
389
|
-
);
|
|
390
|
-
step(spinner, 'Postgres is up');
|
|
391
|
-
}
|
|
392
|
-
},
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
const stopTestEnvironment = async (tempdir: string) =>
|
|
396
|
-
await withSpinner(
|
|
397
|
-
`Stop test environment`,
|
|
398
|
-
`Failed to stop test environment`,
|
|
399
|
-
`Warnings stopping test environment`,
|
|
400
|
-
async () => {
|
|
401
|
-
// Our containers do not respond quickly to the SIGTERM which `down` tries before timing out
|
|
402
|
-
// and killing them, so speed things up by sending a SIGKILL right away.
|
|
403
|
-
try {
|
|
404
|
-
await compose.kill({ cwd: path.join(tempdir, 'compose') });
|
|
405
|
-
} catch (e) {
|
|
406
|
-
// Do nothing, we will just try to run 'down'
|
|
407
|
-
// to bring down the environment
|
|
408
|
-
}
|
|
409
|
-
await compose.down({ cwd: path.join(tempdir, 'compose') });
|
|
410
|
-
},
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
const startGraphNode = async (
|
|
414
|
-
standaloneNode: string,
|
|
415
|
-
standaloneNodeArgs: string,
|
|
416
|
-
nodeOutputChunks: Buffer[],
|
|
417
|
-
): Promise<ChildProcess> =>
|
|
418
|
-
await withSpinner(
|
|
419
|
-
`Start Graph node`,
|
|
420
|
-
`Failed to start Graph node`,
|
|
421
|
-
`Warnings starting Graph node`,
|
|
422
|
-
async spinner => {
|
|
423
|
-
const defaultArgs = [
|
|
424
|
-
'--ipfs',
|
|
425
|
-
'localhost:15001',
|
|
426
|
-
'--postgres-url',
|
|
427
|
-
'postgresql://graph:let-me-in@localhost:15432/graph',
|
|
428
|
-
'--ethereum-rpc',
|
|
429
|
-
'test:http://localhost:18545',
|
|
430
|
-
'--http-port',
|
|
431
|
-
'18000',
|
|
432
|
-
'--ws-port',
|
|
433
|
-
'18001',
|
|
434
|
-
'--admin-port',
|
|
435
|
-
'18020',
|
|
436
|
-
'--index-node-port',
|
|
437
|
-
'18030',
|
|
438
|
-
'--metrics-port',
|
|
439
|
-
'18040',
|
|
440
|
-
];
|
|
441
|
-
|
|
442
|
-
const defaultEnv = {
|
|
443
|
-
GRAPH_LOG: 'debug',
|
|
444
|
-
GRAPH_MAX_API_VERSION: '0.0.5',
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
const args = standaloneNodeArgs ? standaloneNodeArgs.split(' ') : defaultArgs;
|
|
448
|
-
const env = { ...defaultEnv, ...process.env };
|
|
449
|
-
|
|
450
|
-
const nodeProcess = spawn(standaloneNode, args, {
|
|
451
|
-
cwd: process.cwd(),
|
|
452
|
-
env,
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
step(spinner, 'Graph node:', String(nodeProcess.spawnargs.join(' ')));
|
|
456
|
-
|
|
457
|
-
nodeProcess.stdout.on('data', data => nodeOutputChunks.push(Buffer.from(data)));
|
|
458
|
-
nodeProcess.stderr.on('data', data => nodeOutputChunks.push(Buffer.from(data)));
|
|
459
|
-
nodeProcess.on('error', e => {
|
|
460
|
-
nodeOutputChunks.push(Buffer.from(String(e), 'utf-8'));
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
// Return the node child process
|
|
464
|
-
return nodeProcess;
|
|
465
|
-
},
|
|
466
|
-
);
|
|
467
|
-
|
|
468
|
-
const waitForGraphNode = async (timeout: number) =>
|
|
469
|
-
await withSpinner(
|
|
470
|
-
`Wait for Graph node`,
|
|
471
|
-
`Failed to wait for Graph node`,
|
|
472
|
-
`Warnings waiting for Graph node`,
|
|
473
|
-
async () => {
|
|
474
|
-
await waitFor(
|
|
475
|
-
timeout,
|
|
476
|
-
async () =>
|
|
477
|
-
new Promise<void>((resolve, reject) => {
|
|
478
|
-
http
|
|
479
|
-
.get('http://localhost:18000', { timeout }, () => resolve())
|
|
480
|
-
.on('error', e => reject(e));
|
|
481
|
-
}),
|
|
482
|
-
);
|
|
483
|
-
},
|
|
484
|
-
);
|
|
485
|
-
|
|
486
|
-
const stopGraphNode = async (nodeProcess: ChildProcess) =>
|
|
487
|
-
await withSpinner(
|
|
488
|
-
`Stop Graph node`,
|
|
489
|
-
`Failed to stop Graph node`,
|
|
490
|
-
`Warnings stopping Graph node`,
|
|
491
|
-
async () => {
|
|
492
|
-
nodeProcess.kill(9);
|
|
493
|
-
},
|
|
494
|
-
);
|
|
495
|
-
|
|
496
|
-
const collectGraphNodeLogs = async (
|
|
497
|
-
tempdir: string,
|
|
498
|
-
standaloneNode: string,
|
|
499
|
-
nodeOutputChunks: Buffer[],
|
|
500
|
-
) => {
|
|
501
|
-
if (standaloneNode) {
|
|
502
|
-
// Pull the logs from the captured output
|
|
503
|
-
return stripAnsi(Buffer.concat(nodeOutputChunks).toString('utf-8'));
|
|
504
|
-
}
|
|
505
|
-
// Pull the logs from docker compose
|
|
506
|
-
const logs = await compose.logs('graph-node', {
|
|
507
|
-
follow: false,
|
|
508
|
-
cwd: path.join(tempdir, 'compose'),
|
|
509
|
-
});
|
|
510
|
-
return stripAnsi(logs.out.trim()).replace(/graph-node_1 {2}\| /g, '');
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
const collectEthereumLogs = async (tempdir: string) => {
|
|
514
|
-
const logs = await compose.logs('ethereum', {
|
|
515
|
-
follow: false,
|
|
516
|
-
cwd: path.join(tempdir, 'compose'),
|
|
517
|
-
});
|
|
518
|
-
return stripAnsi(logs.out.trim()).replace(/ethereum_1 {2}\| /g, '');
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
const runTests = async (testCommand: string) =>
|
|
522
|
-
await withSpinner(
|
|
523
|
-
`Run tests`,
|
|
524
|
-
`Failed to run tests`,
|
|
525
|
-
`Warnings running tests`,
|
|
526
|
-
async () =>
|
|
527
|
-
new Promise(resolve => {
|
|
528
|
-
const output: Buffer[] = [];
|
|
529
|
-
const testProcess = spawn(String(testCommand), { shell: true });
|
|
530
|
-
testProcess.stdout.on('data', data => output.push(Buffer.from(data)));
|
|
531
|
-
testProcess.stderr.on('data', data => output.push(Buffer.from(data)));
|
|
532
|
-
testProcess.on('close', code => {
|
|
533
|
-
resolve({
|
|
534
|
-
exitCode: code,
|
|
535
|
-
output: Buffer.concat(output).toString('utf-8'),
|
|
536
|
-
});
|
|
537
|
-
});
|
|
538
|
-
}),
|
|
539
|
-
);
|
package/src/commands/remove.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { URL } from 'url';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { GluegunToolbox } from 'gluegun';
|
|
4
|
-
import { identifyDeployKey as identifyAccessToken } from '../command-helpers/auth';
|
|
5
|
-
import { createJsonRpcClient } from '../command-helpers/jsonrpc';
|
|
6
|
-
import { validateNodeUrl } from '../command-helpers/node';
|
|
7
|
-
|
|
8
|
-
const HELP = `
|
|
9
|
-
${chalk.bold('graph remove')} ${chalk.dim('[options]')} ${chalk.bold('<subgraph-name>')}
|
|
10
|
-
|
|
11
|
-
${chalk.dim('Options:')}
|
|
12
|
-
|
|
13
|
-
--access-token <token> Graph access token
|
|
14
|
-
-h, --help Show usage information
|
|
15
|
-
-g, --node <url> Graph node to create the subgraph in
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
export interface RemoveOptions {
|
|
19
|
-
accessToken?: string;
|
|
20
|
-
help?: boolean;
|
|
21
|
-
node?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default {
|
|
25
|
-
description: 'Unregisters a subgraph name',
|
|
26
|
-
run: async (toolbox: GluegunToolbox) => {
|
|
27
|
-
// Obtain tools
|
|
28
|
-
const { print } = toolbox;
|
|
29
|
-
|
|
30
|
-
// Read CLI parameters
|
|
31
|
-
let { accessToken, g, h, help, node } = toolbox.parameters.options;
|
|
32
|
-
const subgraphName = toolbox.parameters.first;
|
|
33
|
-
|
|
34
|
-
// Support both long and short option variants
|
|
35
|
-
help ||= h;
|
|
36
|
-
node ||= g;
|
|
37
|
-
|
|
38
|
-
// Show help text if requested
|
|
39
|
-
if (help) {
|
|
40
|
-
print.info(HELP);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Validate the subgraph name
|
|
45
|
-
if (!subgraphName) {
|
|
46
|
-
print.error('No subgraph name provided');
|
|
47
|
-
print.info(HELP);
|
|
48
|
-
process.exitCode = 1;
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Validate node
|
|
53
|
-
if (!node) {
|
|
54
|
-
print.error(`No Graph node provided`);
|
|
55
|
-
print.info(HELP);
|
|
56
|
-
process.exitCode = 1;
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
validateNodeUrl(node);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
print.error(`Graph node "${node}" is invalid: ${e.message}`);
|
|
63
|
-
process.exitCode = 1;
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const requestUrl = new URL(node);
|
|
68
|
-
const client = createJsonRpcClient(requestUrl);
|
|
69
|
-
|
|
70
|
-
// Exit with an error code if the client couldn't be created
|
|
71
|
-
if (!client) {
|
|
72
|
-
process.exitCode = 1;
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Use the access token, if one is set
|
|
77
|
-
accessToken = await identifyAccessToken(node, accessToken);
|
|
78
|
-
if (accessToken !== undefined && accessToken !== null) {
|
|
79
|
-
// @ts-expect-error options property seems to exist
|
|
80
|
-
client.options.headers = { Authorization: `Bearer ${accessToken}` };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const spinner = print.spin(`Creating subgraph in Graph node: ${requestUrl}`);
|
|
84
|
-
client.request(
|
|
85
|
-
'subgraph_remove',
|
|
86
|
-
{ name: subgraphName },
|
|
87
|
-
(
|
|
88
|
-
// @ts-expect-error TODO: why are the arguments not typed?
|
|
89
|
-
requestError,
|
|
90
|
-
// @ts-expect-error TODO: why are the arguments not typed?
|
|
91
|
-
jsonRpcError,
|
|
92
|
-
// TODO: this argument is unused, but removing it from the commands/create.ts fails the basic-event-handlers tests.
|
|
93
|
-
// I'll therefore leave it in here too until we figure out the weirdness
|
|
94
|
-
// @ts-expect-error TODO: why are the arguments not typed?
|
|
95
|
-
_res,
|
|
96
|
-
) => {
|
|
97
|
-
if (jsonRpcError) {
|
|
98
|
-
spinner.fail(`Error removing the subgraph: ${jsonRpcError.message}`);
|
|
99
|
-
process.exitCode = 1;
|
|
100
|
-
} else if (requestError) {
|
|
101
|
-
spinner.fail(`HTTP error removing the subgraph: ${requestError.code}`);
|
|
102
|
-
process.exitCode = 1;
|
|
103
|
-
} else {
|
|
104
|
-
spinner.stop();
|
|
105
|
-
print.success(`Removed subgraph: ${subgraphName}`);
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
},
|
|
110
|
-
};
|