@graphprotocol/graph-cli 0.88.0-alpha-20241031145713-add2ae3 → 0.88.0-alpha-20241105083740-b45cf73
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 +24 -1
- package/README.md +14 -6
- package/dist/codegen/schema.d.ts +2 -2
- package/dist/codegen/schema.js +7 -5
- package/dist/command-helpers/node.d.ts +2 -13
- package/dist/command-helpers/node.js +4 -54
- package/dist/command-helpers/subgraph.d.ts +0 -3
- package/dist/command-helpers/subgraph.js +1 -15
- package/dist/commands/auth.d.ts +0 -3
- package/dist/commands/auth.js +2 -35
- package/dist/commands/codegen.d.ts +1 -0
- package/dist/commands/codegen.js +13 -1
- package/dist/commands/deploy.d.ts +0 -3
- package/dist/commands/deploy.js +5 -164
- package/dist/commands/init.d.ts +0 -3
- package/dist/commands/init.js +9 -141
- package/dist/protocols/index.d.ts +2 -2
- package/dist/protocols/index.js +23 -2
- package/dist/protocols/subgraph/manifest.graphql +65 -0
- package/dist/protocols/subgraph/scaffold/manifest.d.ts +4 -0
- package/dist/protocols/subgraph/scaffold/manifest.js +12 -0
- package/dist/protocols/subgraph/subgraph.d.ts +10 -0
- package/dist/protocols/subgraph/subgraph.js +20 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +9 -0
- package/dist/type-generator.d.ts +11 -1
- package/dist/type-generator.js +58 -4
- package/oclif.manifest.json +11 -89
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.88.0-alpha-
|
|
3
|
+
## 0.88.0-alpha-20241105083740-b45cf73
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
+
- [#1680](https://github.com/graphprotocol/graph-tooling/pull/1680)
|
|
8
|
+
[`08914a8`](https://github.com/graphprotocol/graph-tooling/commit/08914a89179e31363765bb3a6e72945f4585e207)
|
|
9
|
+
Thanks [@saihaj](https://github.com/saihaj)! - Breaking changes to the CLI to prepare for the
|
|
10
|
+
sunset of the hosted service.
|
|
11
|
+
|
|
12
|
+
- `graph auth`
|
|
13
|
+
- Removed `--product` flag
|
|
14
|
+
- Removed `--studio` flag
|
|
15
|
+
- Removed `node` argument
|
|
16
|
+
- `graph deploy`
|
|
17
|
+
- Removed `--product` flag
|
|
18
|
+
- Removed `--studio` flag
|
|
19
|
+
- Removed `--from-hosted-service` flag
|
|
20
|
+
- `graph init`
|
|
21
|
+
- Removed `--product` flag
|
|
22
|
+
- Removed `--studio` flag
|
|
23
|
+
- Removed `--allow-simple-name` flag
|
|
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
|
+
|
|
7
30
|
- [#1749](https://github.com/graphprotocol/graph-tooling/pull/1749)
|
|
8
31
|
[`bf43cbf`](https://github.com/graphprotocol/graph-tooling/commit/bf43cbf8283c53f0005d7cb9dfa681c92f3a6a91)
|
|
9
32
|
Thanks [@0237h](https://github.com/0237h)! - Add warning for available CLI updates
|
package/README.md
CHANGED
|
@@ -29,12 +29,16 @@ As of today, the command line interface supports the following commands:
|
|
|
29
29
|
The Graph CLI takes a subgraph manifest (defaults to `subgraph.yaml`) with references to:
|
|
30
30
|
|
|
31
31
|
- A GraphQL schema,
|
|
32
|
-
- Smart contract ABIs,
|
|
33
|
-
- Mappings written in AssemblyScript
|
|
32
|
+
- Smart contract ABIs,
|
|
33
|
+
- Mappings written in AssemblyScript for traditional subgraphs,
|
|
34
|
+
- Substreams package and triggers for substreams-based subgraphs
|
|
34
35
|
|
|
35
36
|
It compiles the mappings to WebAssembly, builds a ready-to-use version of the subgraph saved to IPFS
|
|
36
37
|
or a local directory for debugging, and deploys the subgraph to a
|
|
37
|
-
[Graph Node](https://github.com/graphprotocol/graph-node)
|
|
38
|
+
[Graph Node](https://github.com/graphprotocol/graph-node) instance or
|
|
39
|
+
[Subgraph Studio](https://thegraph.com/studio/). Additionally it allows you to publish your subgraph
|
|
40
|
+
to the decentralized network directly, making it available for indexing via
|
|
41
|
+
[Graph Explorer](https://thegraph.com/explorer)
|
|
38
42
|
|
|
39
43
|
## Installation
|
|
40
44
|
|
|
@@ -73,11 +77,15 @@ Use one of the following commands depending on your distribution:
|
|
|
73
77
|
|
|
74
78
|
The Graph CLI can be used with a local or self-hosted
|
|
75
79
|
[Graph Node](https://github.com/graphprotocol/graph-node) or with the
|
|
76
|
-
[
|
|
77
|
-
[quick start guides](https://thegraph.com/docs/en/
|
|
80
|
+
[Subgraph Studio](https://thegraph.com/studio/). To help you get going, there are
|
|
81
|
+
[quick start guides](https://thegraph.com/docs/en/quick-start/) available for both.
|
|
82
|
+
|
|
83
|
+
Additionally, you can use Graph CLI to
|
|
84
|
+
[publish](https://thegraph.com/docs/en/quick-start/#publishing-from-the-cli) your subgraph to the
|
|
85
|
+
decentralized network directly.
|
|
78
86
|
|
|
79
87
|
If you are ready to dive into the details of building a subgraph from scratch, there is a
|
|
80
|
-
[detailed walkthrough](https://thegraph.com/docs/en/
|
|
88
|
+
[detailed walkthrough](https://thegraph.com/docs/en/developing/creating-a-subgraph/) for that as
|
|
81
89
|
well, along with API documentation for the
|
|
82
90
|
[AssemblyScript API](https://thegraph.com/docs/en/developer/assemblyscript-api/).
|
|
83
91
|
|
package/dist/codegen/schema.d.ts
CHANGED
|
@@ -20,12 +20,12 @@ export default class SchemaCodeGenerator {
|
|
|
20
20
|
private schema;
|
|
21
21
|
constructor(schema: Schema);
|
|
22
22
|
generateModuleImports(): tsCodegen.ModuleImports[];
|
|
23
|
-
generateTypes(): Array<tsCodegen.Class>;
|
|
23
|
+
generateTypes(generateStoreMethods?: boolean): Array<tsCodegen.Class>;
|
|
24
24
|
generateDerivedLoaders(): any[];
|
|
25
25
|
_isEntityTypeDefinition(def: DefinitionNode): def is ObjectTypeDefinitionNode;
|
|
26
26
|
_isDerivedField(field: FieldDefinitionNode | undefined): boolean;
|
|
27
27
|
_isInterfaceDefinition(def: DefinitionNode): def is InterfaceTypeDefinitionNode;
|
|
28
|
-
_generateEntityType(def: ObjectTypeDefinitionNode): tsCodegen.Class;
|
|
28
|
+
_generateEntityType(def: ObjectTypeDefinitionNode, generateStoreMethods?: boolean): tsCodegen.Class;
|
|
29
29
|
_generateDerivedLoader(typeName: string): any;
|
|
30
30
|
_getTypeNameForField(gqlType: TypeNode): string;
|
|
31
31
|
_generateConstructor(_entityName: string, fields: readonly FieldDefinitionNode[] | undefined): tsCodegen.Method;
|
package/dist/codegen/schema.js
CHANGED
|
@@ -94,12 +94,12 @@ class SchemaCodeGenerator {
|
|
|
94
94
|
], '@graphprotocol/graph-ts'),
|
|
95
95
|
];
|
|
96
96
|
}
|
|
97
|
-
generateTypes() {
|
|
97
|
+
generateTypes(generateStoreMethods = true) {
|
|
98
98
|
return this.schema.ast.definitions
|
|
99
99
|
.map(def => {
|
|
100
100
|
if (this._isEntityTypeDefinition(def)) {
|
|
101
101
|
schemaCodeGeneratorDebug.extend('generateTypes')(`Generating entity type for ${def.name.value}`);
|
|
102
|
-
return this._generateEntityType(def);
|
|
102
|
+
return this._generateEntityType(def, generateStoreMethods);
|
|
103
103
|
}
|
|
104
104
|
})
|
|
105
105
|
.filter(Boolean);
|
|
@@ -132,15 +132,17 @@ class SchemaCodeGenerator {
|
|
|
132
132
|
_isInterfaceDefinition(def) {
|
|
133
133
|
return def.kind === 'InterfaceTypeDefinition';
|
|
134
134
|
}
|
|
135
|
-
_generateEntityType(def) {
|
|
135
|
+
_generateEntityType(def, generateStoreMethods = true) {
|
|
136
136
|
const name = def.name.value;
|
|
137
137
|
const klass = tsCodegen.klass(name, { export: true, extends: 'Entity' });
|
|
138
138
|
const fields = def.fields;
|
|
139
139
|
const idField = IdField.fromFields(fields);
|
|
140
140
|
// Generate and add a constructor
|
|
141
141
|
klass.addMethod(this._generateConstructor(name, fields));
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
if (generateStoreMethods) {
|
|
143
|
+
// Generate and add save() and getById() methods
|
|
144
|
+
this._generateStoreMethods(name, idField).forEach(method => klass.addMethod(method));
|
|
145
|
+
}
|
|
144
146
|
// Generate and add entity field getters and setters
|
|
145
147
|
def.fields
|
|
146
148
|
?.reduce((methods, field) => methods.concat(this._generateEntityFieldMethods(def, field)), [])
|
|
@@ -3,19 +3,8 @@ import { URL } from 'url';
|
|
|
3
3
|
export declare const SUBGRAPH_STUDIO_URL = "https://api.studio.thegraph.com/deploy/";
|
|
4
4
|
export declare const validateNodeUrl: (node: string) => URL;
|
|
5
5
|
export declare const normalizeNodeUrl: (node: string) => string;
|
|
6
|
-
export declare function chooseNodeUrl({
|
|
7
|
-
product: string | undefined;
|
|
8
|
-
studio: boolean | undefined;
|
|
6
|
+
export declare function chooseNodeUrl({ node }: {
|
|
9
7
|
node?: string;
|
|
10
|
-
allowSimpleName?: boolean;
|
|
11
8
|
}): {
|
|
12
|
-
node: string
|
|
13
|
-
allowSimpleName: boolean | undefined;
|
|
9
|
+
node: string;
|
|
14
10
|
};
|
|
15
|
-
export declare function getHostedServiceSubgraphId({ subgraphName, }: {
|
|
16
|
-
subgraphName: string;
|
|
17
|
-
}): Promise<{
|
|
18
|
-
subgraph: string;
|
|
19
|
-
synced: boolean;
|
|
20
|
-
health: 'healthy' | 'unhealthy' | 'failed';
|
|
21
|
-
}>;
|
|
@@ -1,74 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.chooseNodeUrl = exports.normalizeNodeUrl = exports.validateNodeUrl = exports.SUBGRAPH_STUDIO_URL = void 0;
|
|
4
4
|
const url_1 = require("url");
|
|
5
5
|
const gluegun_1 = require("gluegun");
|
|
6
|
-
const constants_1 = require("../constants");
|
|
7
6
|
exports.SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/';
|
|
8
|
-
const HOSTED_SERVICE_URL = 'https://api.thegraph.com/deploy/';
|
|
9
|
-
const HOSTED_SERVICE_INDEX_NODE_URL = 'https://api.thegraph.com/index-node/graphql';
|
|
10
7
|
const validateNodeUrl = (node) => new url_1.URL(node);
|
|
11
8
|
exports.validateNodeUrl = validateNodeUrl;
|
|
12
9
|
const normalizeNodeUrl = (node) => new url_1.URL(node).toString();
|
|
13
10
|
exports.normalizeNodeUrl = normalizeNodeUrl;
|
|
14
|
-
function chooseNodeUrl({
|
|
11
|
+
function chooseNodeUrl({ node }) {
|
|
15
12
|
if (node) {
|
|
16
13
|
try {
|
|
17
14
|
(0, exports.validateNodeUrl)(node);
|
|
15
|
+
return { node };
|
|
18
16
|
}
|
|
19
17
|
catch (e) {
|
|
20
18
|
gluegun_1.print.error(`Graph node "${node}" is invalid: ${e.message}`);
|
|
21
19
|
process.exit(1);
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
if (studio) {
|
|
26
|
-
product = 'subgraph-studio';
|
|
27
|
-
}
|
|
28
|
-
switch (product) {
|
|
29
|
-
case 'subgraph-studio':
|
|
30
|
-
node = exports.SUBGRAPH_STUDIO_URL;
|
|
31
|
-
break;
|
|
32
|
-
case 'hosted-service':
|
|
33
|
-
node = HOSTED_SERVICE_URL;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (node?.match(/studio/) || product === 'subgraph-studio') {
|
|
38
|
-
allowSimpleName = true;
|
|
39
|
-
}
|
|
40
|
-
return { node, allowSimpleName };
|
|
22
|
+
return { node: exports.SUBGRAPH_STUDIO_URL };
|
|
41
23
|
}
|
|
42
24
|
exports.chooseNodeUrl = chooseNodeUrl;
|
|
43
|
-
async function getHostedServiceSubgraphId({ subgraphName, }) {
|
|
44
|
-
const response = await fetch(HOSTED_SERVICE_INDEX_NODE_URL, {
|
|
45
|
-
method: 'POST',
|
|
46
|
-
body: JSON.stringify({
|
|
47
|
-
query: /* GraphQL */ `
|
|
48
|
-
query GraphCli_getSubgraphId($subgraphName: String!) {
|
|
49
|
-
indexingStatusForCurrentVersion(subgraphName: $subgraphName) {
|
|
50
|
-
subgraph
|
|
51
|
-
synced
|
|
52
|
-
health
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
`,
|
|
56
|
-
variables: {
|
|
57
|
-
subgraphName,
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
headers: {
|
|
61
|
-
'content-type': 'application/json',
|
|
62
|
-
...constants_1.GRAPH_CLI_SHARED_HEADERS,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
const { data, errors } = await response.json();
|
|
66
|
-
if (errors) {
|
|
67
|
-
throw new Error(errors[0].message);
|
|
68
|
-
}
|
|
69
|
-
if (!data.indexingStatusForCurrentVersion) {
|
|
70
|
-
throw new Error(`Subgraph "${subgraphName}" not found on the hosted service`);
|
|
71
|
-
}
|
|
72
|
-
return data.indexingStatusForCurrentVersion;
|
|
73
|
-
}
|
|
74
|
-
exports.getHostedServiceSubgraphId = getHostedServiceSubgraphId;
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSubgraphBasename =
|
|
4
|
-
const validateSubgraphName = (name, { allowSimpleName }) => {
|
|
5
|
-
if (allowSimpleName) {
|
|
6
|
-
return name;
|
|
7
|
-
}
|
|
8
|
-
if (name.split('/').length !== 2) {
|
|
9
|
-
throw new Error(`Subgraph name "${name}" needs to have the format "<PREFIX>/${name}".
|
|
10
|
-
|
|
11
|
-
When using the Hosted Service at https://thegraph.com, <PREFIX> is the
|
|
12
|
-
name of your GitHub user or organization.
|
|
13
|
-
|
|
14
|
-
You can bypass this check with --allow-simple-name.`);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
exports.validateSubgraphName = validateSubgraphName;
|
|
3
|
+
exports.getSubgraphBasename = void 0;
|
|
18
4
|
const getSubgraphBasename = (name) => {
|
|
19
5
|
const segments = name.split('/', 2);
|
|
20
6
|
return segments[segments.length - 1];
|
package/dist/commands/auth.d.ts
CHANGED
|
@@ -2,13 +2,10 @@ import { Command } from '@oclif/core';
|
|
|
2
2
|
export default class AuthCommand extends Command {
|
|
3
3
|
static description: string;
|
|
4
4
|
static args: {
|
|
5
|
-
node: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
|
|
6
5
|
'deploy-key': import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
|
|
7
6
|
};
|
|
8
7
|
static flags: {
|
|
9
8
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
10
|
-
product: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
-
studio: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
9
|
};
|
|
13
10
|
run(): Promise<void>;
|
|
14
11
|
}
|
package/dist/commands/auth.js
CHANGED
|
@@ -6,23 +6,8 @@ const auth_1 = require("../command-helpers/auth");
|
|
|
6
6
|
const node_1 = require("../command-helpers/node");
|
|
7
7
|
class AuthCommand extends core_1.Command {
|
|
8
8
|
async run() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let node;
|
|
12
|
-
let deployKey = deployKeyFlag;
|
|
13
|
-
if (product || studio) {
|
|
14
|
-
({ node } = (0, node_1.chooseNodeUrl)({ product, studio, node }));
|
|
15
|
-
deployKey = nodeOrDeployKey;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
node = nodeOrDeployKey;
|
|
19
|
-
}
|
|
20
|
-
// eslint-disable-next-line -- prettier has problems with ||=
|
|
21
|
-
node =
|
|
22
|
-
node ||
|
|
23
|
-
(await core_1.ux.prompt('Which product to initialize?', {
|
|
24
|
-
required: true,
|
|
25
|
-
}));
|
|
9
|
+
let { args: { 'deploy-key': deployKey }, } = await this.parse(AuthCommand);
|
|
10
|
+
const { node } = (0, node_1.chooseNodeUrl)({});
|
|
26
11
|
// eslint-disable-next-line -- prettier has problems with ||=
|
|
27
12
|
deployKey =
|
|
28
13
|
deployKey ||
|
|
@@ -33,9 +18,6 @@ class AuthCommand extends core_1.Command {
|
|
|
33
18
|
if (deployKey.length > 200) {
|
|
34
19
|
this.error('✖ Deploy key must not exceed 200 characters', { exit: 1 });
|
|
35
20
|
}
|
|
36
|
-
if (product === 'hosted-service' || node?.match(/api.thegraph.com/)) {
|
|
37
|
-
this.error('✖ The hosted service is deprecated', { exit: 1 });
|
|
38
|
-
}
|
|
39
21
|
try {
|
|
40
22
|
await (0, auth_1.saveDeployKey)(node, deployKey);
|
|
41
23
|
gluegun_1.print.success(`Deploy key set for ${node}`);
|
|
@@ -47,26 +29,11 @@ class AuthCommand extends core_1.Command {
|
|
|
47
29
|
}
|
|
48
30
|
AuthCommand.description = 'Sets the deploy key to use when deploying to a Graph node.';
|
|
49
31
|
AuthCommand.args = {
|
|
50
|
-
node: core_1.Args.string(),
|
|
51
32
|
'deploy-key': core_1.Args.string(),
|
|
52
33
|
};
|
|
53
34
|
AuthCommand.flags = {
|
|
54
35
|
help: core_1.Flags.help({
|
|
55
36
|
char: 'h',
|
|
56
37
|
}),
|
|
57
|
-
product: core_1.Flags.string({
|
|
58
|
-
summary: 'Select a product for which to authenticate.',
|
|
59
|
-
options: ['subgraph-studio', 'hosted-service'],
|
|
60
|
-
deprecated: {
|
|
61
|
-
message: 'In next major version, this flag will be removed. By default we will deploy to the Graph Studio. Learn more about Sunrise of Decentralized Data https://thegraph.com/blog/unveiling-updated-sunrise-decentralized-data/',
|
|
62
|
-
},
|
|
63
|
-
}),
|
|
64
|
-
studio: core_1.Flags.boolean({
|
|
65
|
-
summary: 'Shortcut for "--product subgraph-studio".',
|
|
66
|
-
exclusive: ['product'],
|
|
67
|
-
deprecated: {
|
|
68
|
-
message: 'In next major version, this flag will be removed. By default we will deploy to the Graph Studio. Learn more about Sunrise of Decentralized Data https://thegraph.com/blog/unveiling-updated-sunrise-decentralized-data/',
|
|
69
|
-
},
|
|
70
|
-
}),
|
|
71
38
|
};
|
|
72
39
|
exports.default = AuthCommand;
|
|
@@ -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: 'IPFS node to use for fetching subgraph data.',
|
|
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'],
|
|
@@ -7,8 +7,6 @@ export default class DeployCommand extends Command {
|
|
|
7
7
|
};
|
|
8
8
|
static flags: {
|
|
9
9
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
10
|
-
product: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
-
studio: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
12
10
|
node: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
11
|
'deploy-key': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
12
|
'access-token': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
@@ -22,7 +20,6 @@ export default class DeployCommand extends Command {
|
|
|
22
20
|
watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
23
21
|
network: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
24
22
|
'network-file': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
25
|
-
'from-hosted-service': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
26
23
|
};
|
|
27
24
|
run(): Promise<void>;
|
|
28
25
|
}
|
package/dist/commands/deploy.js
CHANGED
|
@@ -48,149 +48,21 @@ const headersFlag = core_1.Flags.custom({
|
|
|
48
48
|
parse: val => JSON.parse(val),
|
|
49
49
|
default: {},
|
|
50
50
|
});
|
|
51
|
-
const productOptions = ['subgraph-studio', 'hosted-service'];
|
|
52
51
|
const deployDebugger = (0, debug_1.default)('graph-cli:deploy');
|
|
53
52
|
class DeployCommand extends core_1.Command {
|
|
54
53
|
async run() {
|
|
55
|
-
const { args: { 'subgraph-name': subgraphNameArg, 'subgraph-manifest': manifest }, flags: {
|
|
56
|
-
if (hostedServiceSubgraphName) {
|
|
57
|
-
const { health, subgraph: subgraphIpfsHash } = await (0, node_1.getHostedServiceSubgraphId)({
|
|
58
|
-
subgraphName: hostedServiceSubgraphName,
|
|
59
|
-
});
|
|
60
|
-
const safeToDeployFailedSubgraph = health === 'failed'
|
|
61
|
-
? await core_1.ux.confirm('This subgraph has failed indexing on hosted service. Do you wish to continue the deploy?')
|
|
62
|
-
: true;
|
|
63
|
-
if (!safeToDeployFailedSubgraph)
|
|
64
|
-
return;
|
|
65
|
-
const safeToDeployUnhealthySubgraph = health === 'unhealthy'
|
|
66
|
-
? await core_1.ux.confirm('This subgraph is not healthy on hosted service. Do you wish to continue the deploy?')
|
|
67
|
-
: true;
|
|
68
|
-
if (!safeToDeployUnhealthySubgraph)
|
|
69
|
-
return;
|
|
70
|
-
const { node } = (0, node_1.chooseNodeUrl)({ studio: true, product: undefined });
|
|
71
|
-
// shouldn't happen, but we need to satisfy the compiler
|
|
72
|
-
if (!node) {
|
|
73
|
-
this.error('No node URL available');
|
|
74
|
-
}
|
|
75
|
-
const requestUrl = new url_1.URL(node);
|
|
76
|
-
const client = (0, jsonrpc_1.createJsonRpcClient)(requestUrl);
|
|
77
|
-
// Exit with an error code if the client couldn't be created
|
|
78
|
-
if (!client) {
|
|
79
|
-
this.error('Failed to create RPC client');
|
|
80
|
-
}
|
|
81
|
-
// Use the deploy key, if one is set
|
|
82
|
-
let deployKey = deployKeyFlag;
|
|
83
|
-
if (!deployKey && accessToken) {
|
|
84
|
-
deployKey = accessToken; // backwards compatibility
|
|
85
|
-
}
|
|
86
|
-
deployKey = await (0, auth_1.identifyDeployKey)(node, deployKey);
|
|
87
|
-
if (!deployKey) {
|
|
88
|
-
this.error('No deploy key available');
|
|
89
|
-
}
|
|
90
|
-
// @ts-expect-error options property seems to exist
|
|
91
|
-
client.options.headers = {
|
|
92
|
-
...constants_1.GRAPH_CLI_SHARED_HEADERS,
|
|
93
|
-
Authorization: 'Bearer ' + deployKey,
|
|
94
|
-
};
|
|
95
|
-
const subgraphName = await core_1.ux.prompt('What is the name of the subgraph you want to deploy?', {
|
|
96
|
-
required: true,
|
|
97
|
-
});
|
|
98
|
-
// Ask for label if not on hosted service
|
|
99
|
-
const versionLabel = versionLabelFlag ||
|
|
100
|
-
(await core_1.ux.prompt('Which version label to use? (e.g. "v0.0.1")', {
|
|
101
|
-
required: true,
|
|
102
|
-
}));
|
|
103
|
-
const spinner = gluegun_1.print.spin(`Deploying to Graph node ${requestUrl}`);
|
|
104
|
-
client.request('subgraph_deploy', {
|
|
105
|
-
name: subgraphName,
|
|
106
|
-
ipfs_hash: subgraphIpfsHash,
|
|
107
|
-
version_label: versionLabel,
|
|
108
|
-
debug_fork: debugFork,
|
|
109
|
-
}, async (
|
|
110
|
-
// @ts-expect-error TODO: why are the arguments not typed?
|
|
111
|
-
requestError,
|
|
112
|
-
// @ts-expect-error TODO: why are the arguments not typed?
|
|
113
|
-
jsonRpcError,
|
|
114
|
-
// @ts-expect-error TODO: why are the arguments not typed?
|
|
115
|
-
res) => {
|
|
116
|
-
deployDebugger('requestError: %O', requestError);
|
|
117
|
-
deployDebugger('jsonRpcError: %O', jsonRpcError);
|
|
118
|
-
if (jsonRpcError) {
|
|
119
|
-
const message = jsonRpcError?.message || jsonRpcError?.code?.toString();
|
|
120
|
-
deployDebugger('message: %O', message);
|
|
121
|
-
let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${message}`;
|
|
122
|
-
// Provide helpful advice when the subgraph has not been created yet
|
|
123
|
-
if (message?.match(/subgraph name not found/)) {
|
|
124
|
-
errorMessage += `
|
|
125
|
-
Make sure to create the subgraph first by running the following command:
|
|
126
|
-
$ graph create --node ${node} ${subgraphName}`;
|
|
127
|
-
}
|
|
128
|
-
if (message?.match(/auth failure/)) {
|
|
129
|
-
errorMessage += '\nYou may need to authenticate first.';
|
|
130
|
-
}
|
|
131
|
-
spinner.fail(errorMessage);
|
|
132
|
-
process.exit(1);
|
|
133
|
-
}
|
|
134
|
-
else if (requestError) {
|
|
135
|
-
spinner.fail(`HTTP error deploying the subgraph ${requestError.code}`);
|
|
136
|
-
process.exit(1);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
spinner.stop();
|
|
140
|
-
const base = requestUrl.protocol + '//' + requestUrl.hostname;
|
|
141
|
-
let playground = res.playground;
|
|
142
|
-
let queries = res.queries;
|
|
143
|
-
// Add a base URL if graph-node did not return the full URL
|
|
144
|
-
if (playground.charAt(0) === ':') {
|
|
145
|
-
playground = base + playground;
|
|
146
|
-
}
|
|
147
|
-
if (queries.charAt(0) === ':') {
|
|
148
|
-
queries = base + queries;
|
|
149
|
-
}
|
|
150
|
-
gluegun_1.print.success(`Deployed to ${playground}`);
|
|
151
|
-
gluegun_1.print.info('\nSubgraph endpoints:');
|
|
152
|
-
gluegun_1.print.info(`Queries (HTTP): ${queries}`);
|
|
153
|
-
gluegun_1.print.info(``);
|
|
154
|
-
process.exit(0);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
54
|
+
const { args: { 'subgraph-name': subgraphNameArg, 'subgraph-manifest': manifest }, flags: { 'deploy-key': deployKeyFlag, 'access-token': accessToken, 'version-label': versionLabelFlag, ipfs, headers, node: nodeFlag, 'output-dir': outputDir, 'skip-migrations': skipMigrations, watch, 'debug-fork': debugFork, network, 'network-file': networkFile, 'ipfs-hash': ipfsHash, }, } = await this.parse(DeployCommand);
|
|
159
55
|
const subgraphName = subgraphNameArg ||
|
|
160
56
|
(await core_1.ux.prompt('What is the subgraph name?', {
|
|
161
57
|
required: true,
|
|
162
58
|
}));
|
|
163
|
-
// We are given a node URL, so we prioritize that over the product flag
|
|
164
|
-
const product = nodeFlag
|
|
165
|
-
? productFlag
|
|
166
|
-
: studio
|
|
167
|
-
? 'subgraph-studio'
|
|
168
|
-
: productFlag ||
|
|
169
|
-
(await gluegun_1.prompt
|
|
170
|
-
.ask([
|
|
171
|
-
{
|
|
172
|
-
name: 'product',
|
|
173
|
-
message: 'Which product to deploy for?',
|
|
174
|
-
required: true,
|
|
175
|
-
type: 'select',
|
|
176
|
-
choices: productOptions,
|
|
177
|
-
},
|
|
178
|
-
])
|
|
179
|
-
.then(({ product }) => product));
|
|
180
|
-
if (product === 'hosted-service') {
|
|
181
|
-
this.error('✖ The hosted service is deprecated', { exit: 1 });
|
|
182
|
-
}
|
|
183
59
|
const { node } = (0, node_1.chooseNodeUrl)({
|
|
184
|
-
product,
|
|
185
|
-
studio,
|
|
186
60
|
node: nodeFlag,
|
|
187
61
|
});
|
|
188
62
|
if (!node) {
|
|
189
63
|
// shouldn't happen, but we do the check to satisfy TS
|
|
190
64
|
this.error('No Graph node provided');
|
|
191
65
|
}
|
|
192
|
-
const isStudio = node.match(/studio/);
|
|
193
|
-
const isHostedService = node.match(/thegraph.com/) && !isStudio;
|
|
194
66
|
const requestUrl = new url_1.URL(node);
|
|
195
67
|
const client = (0, jsonrpc_1.createJsonRpcClient)(requestUrl);
|
|
196
68
|
// Exit with an error code if the client couldn't be created
|
|
@@ -213,11 +85,9 @@ class DeployCommand extends core_1.Command {
|
|
|
213
85
|
}
|
|
214
86
|
// Ask for label if not on hosted service
|
|
215
87
|
let versionLabel = versionLabelFlag;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
});
|
|
220
|
-
}
|
|
88
|
+
versionLabel || (versionLabel = await core_1.ux.prompt('Which version label to use? (e.g. "v0.0.1")', {
|
|
89
|
+
required: true,
|
|
90
|
+
}));
|
|
221
91
|
const deploySubgraph = async (ipfsHash) => {
|
|
222
92
|
const spinner = gluegun_1.print.spin(`Deploying to Graph node ${requestUrl}`);
|
|
223
93
|
client.request('subgraph_deploy', {
|
|
@@ -238,18 +108,6 @@ class DeployCommand extends core_1.Command {
|
|
|
238
108
|
const message = jsonRpcError?.message || jsonRpcError?.code?.toString();
|
|
239
109
|
deployDebugger('message: %O', message);
|
|
240
110
|
let errorMessage = `Failed to deploy to Graph node ${requestUrl}: ${message}`;
|
|
241
|
-
// Provide helpful advice when the subgraph has not been created yet
|
|
242
|
-
if (message?.match(/subgraph name not found/)) {
|
|
243
|
-
if (isHostedService) {
|
|
244
|
-
errorMessage +=
|
|
245
|
-
'\nYou may need to create it at https://thegraph.com/explorer/dashboard.';
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
errorMessage += `
|
|
249
|
-
Make sure to create the subgraph first by running the following command:
|
|
250
|
-
$ graph create --node ${node} ${subgraphName}`;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
111
|
if (message?.match(/auth failure/)) {
|
|
254
112
|
errorMessage += '\nYou may need to authenticate first.';
|
|
255
113
|
}
|
|
@@ -272,12 +130,7 @@ class DeployCommand extends core_1.Command {
|
|
|
272
130
|
if (queries.charAt(0) === ':') {
|
|
273
131
|
queries = base + queries;
|
|
274
132
|
}
|
|
275
|
-
|
|
276
|
-
gluegun_1.print.success(`Deployed to https://thegraph.com/explorer/subgraph/${subgraphName}`);
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
gluegun_1.print.success(`Deployed to ${playground}`);
|
|
280
|
-
}
|
|
133
|
+
gluegun_1.print.success(`Deployed to ${playground}`);
|
|
281
134
|
gluegun_1.print.info('\nSubgraph endpoints:');
|
|
282
135
|
gluegun_1.print.info(`Queries (HTTP): ${queries}`);
|
|
283
136
|
gluegun_1.print.info(``);
|
|
@@ -371,14 +224,6 @@ DeployCommand.flags = {
|
|
|
371
224
|
help: core_1.Flags.help({
|
|
372
225
|
char: 'h',
|
|
373
226
|
}),
|
|
374
|
-
product: core_1.Flags.string({
|
|
375
|
-
summary: 'Select a product for which to authenticate.',
|
|
376
|
-
options: productOptions,
|
|
377
|
-
}),
|
|
378
|
-
studio: core_1.Flags.boolean({
|
|
379
|
-
summary: 'Shortcut for "--product subgraph-studio".',
|
|
380
|
-
exclusive: ['product'],
|
|
381
|
-
}),
|
|
382
227
|
node: core_1.Flags.string({
|
|
383
228
|
summary: 'Graph node for which to initialize.',
|
|
384
229
|
char: 'g',
|
|
@@ -426,13 +271,9 @@ DeployCommand.flags = {
|
|
|
426
271
|
network: core_1.Flags.string({
|
|
427
272
|
summary: 'Network configuration to use from the networks config file.',
|
|
428
273
|
}),
|
|
429
|
-
// TODO: should be networksFile (with an "s"), or?
|
|
430
274
|
'network-file': core_1.Flags.file({
|
|
431
275
|
summary: 'Networks config file path.',
|
|
432
276
|
default: 'networks.json',
|
|
433
277
|
}),
|
|
434
|
-
'from-hosted-service': core_1.Flags.string({
|
|
435
|
-
summary: 'Hosted service Subgraph Name to deploy to studio.',
|
|
436
|
-
}),
|
|
437
278
|
};
|
|
438
279
|
exports.default = DeployCommand;
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -8,10 +8,7 @@ export default class InitCommand extends Command {
|
|
|
8
8
|
static flags: {
|
|
9
9
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
10
10
|
protocol: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
-
product: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
-
studio: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
13
11
|
node: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
-
'allow-simple-name': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
15
12
|
'from-contract': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
13
|
'from-example': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
14
|
'contract-name': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|