@graphprotocol/graph-cli 0.57.0-alpha-20230902184128-dbf8426 → 0.57.0-alpha-20230904080157-a384f00
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 -50
- package/dist/codegen/schema.d.ts +1 -1
- package/dist/command-helpers/abi.js +1 -1
- package/dist/command-helpers/data-sources.js +1 -1
- package/dist/command-helpers/scaffold.d.ts +10 -10
- package/dist/command-helpers/scaffold.js +2 -6
- package/dist/commands/add.js +2 -2
- package/dist/commands/auth.js +1 -1
- package/dist/commands/build.js +1 -1
- package/dist/commands/clean.js +1 -1
- package/dist/commands/create.js +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/init.js +1 -1
- package/dist/commands/local.js +1 -1
- package/dist/commands/remove.js +1 -1
- package/dist/commands/test.js +2 -2
- package/dist/debug.js +0 -6
- package/dist/protocols/arweave/manifest.graphql +2 -0
- package/dist/protocols/cosmos/manifest.graphql +2 -0
- package/dist/protocols/ethereum/manifest.graphql +2 -0
- package/dist/protocols/near/manifest.graphql +2 -0
- package/dist/scaffold/index.d.ts +19 -19
- package/dist/scaffold/schema.js +2 -6
- package/dist/scaffold/tests.d.ts +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/subgraph.js +4 -28
- package/dist/type-generator.js +2 -2
- package/dist/validation/manifest.js +14 -0
- package/dist/validation/schema.js +70 -152
- package/oclif.manifest.json +1 -1
- package/package.json +2 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,54 +1,13 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.57.0-alpha-
|
|
3
|
+
## 0.57.0-alpha-20230904080157-a384f00
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- [#
|
|
8
|
-
[`
|
|
9
|
-
Thanks [@
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
graph autocomplete
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
and follow the steps in the prompt.
|
|
17
|
-
|
|
18
|
-
- [#1441](https://github.com/graphprotocol/graph-tooling/pull/1441)
|
|
19
|
-
[`2e656e9`](https://github.com/graphprotocol/graph-tooling/commit/2e656e9cdaaea6d87866adaa142da597fcd7ce65)
|
|
20
|
-
Thanks [@saihaj](https://github.com/saihaj)! - show suggestions when an invalid command is entered
|
|
21
|
-
|
|
22
|
-
### Patch Changes
|
|
23
|
-
|
|
24
|
-
- [#1439](https://github.com/graphprotocol/graph-tooling/pull/1439)
|
|
25
|
-
[`b583097`](https://github.com/graphprotocol/graph-tooling/commit/b583097f464a478151068d96d668334602bed3ba)
|
|
26
|
-
Thanks [@saihaj](https://github.com/saihaj)! - dependencies updates:
|
|
27
|
-
|
|
28
|
-
- Added dependency
|
|
29
|
-
[`@oclif/plugin-autocomplete@^2.3.6` ↗︎](https://www.npmjs.com/package/@oclif/plugin-autocomplete/v/2.3.6)
|
|
30
|
-
(to `dependencies`)
|
|
31
|
-
|
|
32
|
-
- [#1441](https://github.com/graphprotocol/graph-tooling/pull/1441)
|
|
33
|
-
[`2e656e9`](https://github.com/graphprotocol/graph-tooling/commit/2e656e9cdaaea6d87866adaa142da597fcd7ce65)
|
|
34
|
-
Thanks [@saihaj](https://github.com/saihaj)! - dependencies updates:
|
|
35
|
-
|
|
36
|
-
- Added dependency
|
|
37
|
-
[`@oclif/plugin-not-found@^2.4.0` ↗︎](https://www.npmjs.com/package/@oclif/plugin-not-found/v/2.4.0)
|
|
38
|
-
(to `dependencies`)
|
|
39
|
-
|
|
40
|
-
- [#1435](https://github.com/graphprotocol/graph-tooling/pull/1435)
|
|
41
|
-
[`f05b47c`](https://github.com/graphprotocol/graph-tooling/commit/f05b47cf64912d0c66255c9f0076f1696a708ff2)
|
|
42
|
-
Thanks [@saihaj](https://github.com/saihaj)! - update prettier
|
|
43
|
-
|
|
44
|
-
- [#1433](https://github.com/graphprotocol/graph-tooling/pull/1433)
|
|
45
|
-
[`4492e4f`](https://github.com/graphprotocol/graph-tooling/commit/4492e4fdefb48407ef89df82eeef4d92bb0747e9)
|
|
46
|
-
Thanks [@saihaj](https://github.com/saihaj)! - when generating nested tuples make sure they are
|
|
47
|
-
non-nullable
|
|
48
|
-
|
|
49
|
-
- [#1433](https://github.com/graphprotocol/graph-tooling/pull/1433)
|
|
50
|
-
[`4492e4f`](https://github.com/graphprotocol/graph-tooling/commit/4492e4fdefb48407ef89df82eeef4d92bb0747e9)
|
|
51
|
-
Thanks [@saihaj](https://github.com/saihaj)! - 2D arrays are valid entities
|
|
7
|
+
- [#1434](https://github.com/graphprotocol/graph-tooling/pull/1434)
|
|
8
|
+
[`4c8bdf8`](https://github.com/graphprotocol/graph-tooling/commit/4c8bdf8acb655cd397f24f2e1639baf6cff4ac3e)
|
|
9
|
+
Thanks [@incrypto32](https://github.com/incrypto32)! - Add data source context support in ethereum
|
|
10
|
+
manifest
|
|
52
11
|
|
|
53
12
|
## 0.56.0
|
|
54
13
|
|
|
@@ -678,8 +637,8 @@
|
|
|
678
637
|
[`044cd92`](https://github.com/graphprotocol/graph-tooling/commit/044cd92d0ceb9628c7f7fbe3627a09b867710247)
|
|
679
638
|
Thanks [@enisdenjo](https://github.com/enisdenjo)! - dependencies updates:
|
|
680
639
|
|
|
681
|
-
- Added dependency [`@oclif/core@2.0.7` ↗︎](https://www.npmjs.com/package/@oclif/core/v/2.0.7)
|
|
682
|
-
|
|
640
|
+
- Added dependency [`@oclif/core@2.0.7` ↗︎](https://www.npmjs.com/package/@oclif/core/v/2.0.7) (to
|
|
641
|
+
`dependencies`)
|
|
683
642
|
|
|
684
643
|
- [#1074](https://github.com/graphprotocol/graph-tooling/pull/1074)
|
|
685
644
|
[`e84d1e8`](https://github.com/graphprotocol/graph-tooling/commit/e84d1e873d9b2a8967c5fe2a85fce48b2caeb75f)
|
|
@@ -775,8 +734,8 @@
|
|
|
775
734
|
[`4c5e452`](https://github.com/graphprotocol/graph-cli/commit/4c5e452cbc2eceb75db29019fb3b4c769c9618f4)
|
|
776
735
|
Thanks [@saihaj](https://github.com/saihaj)! - dependencies updates:
|
|
777
736
|
|
|
778
|
-
- Updated dependency [`immutable@4.2.1` ↗︎](https://www.npmjs.com/package/immutable/v/4.2.1)
|
|
779
|
-
|
|
737
|
+
- Updated dependency [`immutable@4.2.1` ↗︎](https://www.npmjs.com/package/immutable/v/4.2.1) (from
|
|
738
|
+
`3.8.2`, in `dependencies`)
|
|
780
739
|
|
|
781
740
|
- [`d42f199`](https://github.com/graphprotocol/graph-cli/commit/d42f199502df7bac79e8cafc667d5c712f5a3599)
|
|
782
741
|
Thanks [@darienmh](https://github.com/darienmh)! - fix `chapel` network etherscan URL
|
package/dist/codegen/schema.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { DefinitionNode, FieldDefinitionNode, InterfaceTypeDefinitionNode, NamedTypeNode, ObjectTypeDefinitionNode, TypeNode } from 'graphql/language';
|
|
2
1
|
import Schema from '../schema';
|
|
3
2
|
import * as tsCodegen from './typescript';
|
|
3
|
+
import type { DefinitionNode, FieldDefinitionNode, InterfaceTypeDefinitionNode, NamedTypeNode, ObjectTypeDefinitionNode, TypeNode } from 'graphql/language';
|
|
4
4
|
declare class IdField {
|
|
5
5
|
static BYTES: symbol;
|
|
6
6
|
static STRING: symbol;
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadAbiFromBlockScout = exports.getStartBlockForContract = exports.fetchTransactionByHashFromRPC = exports.fetchContractCreationHashWithRetry = exports.fetchDeployContractTransactionFromEtherscan = exports.loadStartBlockForContract = exports.loadAbiFromEtherscan = void 0;
|
|
7
|
-
const immutable_1 = __importDefault(require("immutable"));
|
|
8
7
|
const fetch_1 = require("@whatwg-node/fetch");
|
|
8
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
9
9
|
const spinner_1 = require("./spinner");
|
|
10
10
|
const loadAbiFromEtherscan = async (ABICtor, network, address) => await (0, spinner_1.withSpinner)(`Fetching ABI from Etherscan`, `Failed to fetch ABI from Etherscan`, `Warnings while fetching ABI from Etherscan`, async () => {
|
|
11
11
|
const scanApiUrl = getEtherscanLikeAPIUrl(network);
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fromManifest = exports.fromManifestString = exports.fromFilePath = void 0;
|
|
7
|
-
const immutable_1 = __importDefault(require("immutable"));
|
|
8
7
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
8
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
9
9
|
const load_manifest_1 = require("../migrations/util/load-manifest");
|
|
10
10
|
// Loads manifest from file path and returns all:
|
|
11
11
|
// - data sources
|
|
@@ -15,26 +15,26 @@ export declare const generateScaffold: ({ protocolInstance, abi, contract, netwo
|
|
|
15
15
|
node?: string | undefined;
|
|
16
16
|
spkgPath?: string | undefined;
|
|
17
17
|
}, spinner: Spinner) => Promise<{
|
|
18
|
-
'subgraph.yaml':
|
|
19
|
-
'schema.graphql':
|
|
20
|
-
'package.json':
|
|
18
|
+
'subgraph.yaml': string;
|
|
19
|
+
'schema.graphql': string;
|
|
20
|
+
'package.json': string;
|
|
21
21
|
'tsconfig.json'?: undefined;
|
|
22
22
|
src?: undefined;
|
|
23
23
|
abis?: undefined;
|
|
24
24
|
tests?: undefined;
|
|
25
25
|
} | {
|
|
26
|
-
'package.json':
|
|
27
|
-
'subgraph.yaml':
|
|
28
|
-
'schema.graphql':
|
|
29
|
-
'tsconfig.json':
|
|
26
|
+
'package.json': string;
|
|
27
|
+
'subgraph.yaml': string;
|
|
28
|
+
'schema.graphql': string;
|
|
29
|
+
'tsconfig.json': string;
|
|
30
30
|
src: {
|
|
31
|
-
[x: string]:
|
|
31
|
+
[x: string]: string;
|
|
32
32
|
} | undefined;
|
|
33
33
|
abis: {
|
|
34
|
-
[x: string]:
|
|
34
|
+
[x: string]: string;
|
|
35
35
|
} | undefined;
|
|
36
36
|
tests: {
|
|
37
|
-
[x: string]:
|
|
37
|
+
[x: string]: string;
|
|
38
38
|
} | undefined;
|
|
39
39
|
}>;
|
|
40
40
|
export declare const writeScaffold: (scaffold: any, directory: string, spinner: Spinner) => Promise<void>;
|
|
@@ -17,13 +17,9 @@ const tests_1 = require("../scaffold/tests");
|
|
|
17
17
|
const spinner_1 = require("./spinner");
|
|
18
18
|
const generateDataSource = async (protocol, contractName, network, contractAddress, abi, startBlock) => {
|
|
19
19
|
const protocolManifest = protocol.getManifestScaffold();
|
|
20
|
-
return immutable_1.Map.of('kind', protocol.name, 'name', contractName, 'network', network, 'source', yaml_1.default.parse(
|
|
21
|
-
contract: contractAddress,
|
|
22
|
-
contractName,
|
|
23
|
-
startBlock,
|
|
24
|
-
}), {
|
|
20
|
+
return immutable_1.Map.of('kind', protocol.name, 'name', contractName, 'network', network, 'source', yaml_1.default.parse(prettier_1.default.format(protocolManifest.source({ contract: contractAddress, contractName, startBlock }), {
|
|
25
21
|
parser: 'yaml',
|
|
26
|
-
})), 'mapping', yaml_1.default.parse(
|
|
22
|
+
})), 'mapping', yaml_1.default.parse(prettier_1.default.format(protocolManifest.mapping({ abi, contractName }), {
|
|
27
23
|
parser: 'yaml',
|
|
28
24
|
}))).asMutable();
|
|
29
25
|
};
|
package/dist/commands/add.js
CHANGED
|
@@ -26,10 +26,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const gluegun_1 = require("gluegun");
|
|
30
|
-
const immutable_1 = __importDefault(require("immutable"));
|
|
31
29
|
const core_1 = require("@oclif/core");
|
|
32
30
|
const errors_1 = require("@oclif/core/lib/errors");
|
|
31
|
+
const gluegun_1 = require("gluegun");
|
|
32
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
33
33
|
const abi_1 = require("../command-helpers/abi");
|
|
34
34
|
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
35
35
|
const network_1 = require("../command-helpers/network");
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const gluegun_1 = require("gluegun");
|
|
4
3
|
const core_1 = require("@oclif/core");
|
|
4
|
+
const gluegun_1 = require("gluegun");
|
|
5
5
|
const auth_1 = require("../command-helpers/auth");
|
|
6
6
|
const node_1 = require("../command-helpers/node");
|
|
7
7
|
class AuthCommand extends core_1.Command {
|
package/dist/commands/build.js
CHANGED
|
@@ -26,8 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const gluegun_1 = require("gluegun");
|
|
30
29
|
const core_1 = require("@oclif/core");
|
|
30
|
+
const gluegun_1 = require("gluegun");
|
|
31
31
|
const compiler_1 = require("../command-helpers/compiler");
|
|
32
32
|
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
33
33
|
const network_1 = require("../command-helpers/network");
|
package/dist/commands/clean.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const gluegun_1 = require("gluegun");
|
|
4
3
|
const core_1 = require("@oclif/core");
|
|
4
|
+
const gluegun_1 = require("gluegun");
|
|
5
5
|
class CleanCommand extends core_1.Command {
|
|
6
6
|
async run() {
|
|
7
7
|
const { flags: { 'codegen-dir': codegenDir, 'build-dir': buildDir }, } = await this.parse(CleanCommand);
|
package/dist/commands/create.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const url_1 = require("url");
|
|
4
|
-
const gluegun_1 = require("gluegun");
|
|
5
4
|
const core_1 = require("@oclif/core");
|
|
5
|
+
const gluegun_1 = require("gluegun");
|
|
6
6
|
const auth_1 = require("../command-helpers/auth");
|
|
7
7
|
const jsonrpc_1 = require("../command-helpers/jsonrpc");
|
|
8
8
|
const node_1 = require("../command-helpers/node");
|
package/dist/commands/deploy.js
CHANGED
|
@@ -28,9 +28,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const path_1 = __importDefault(require("path"));
|
|
30
30
|
const url_1 = require("url");
|
|
31
|
-
const gluegun_1 = require("gluegun");
|
|
32
|
-
const ipfs_http_client_1 = require("ipfs-http-client");
|
|
33
31
|
const core_1 = require("@oclif/core");
|
|
32
|
+
const gluegun_1 = require("gluegun");
|
|
34
33
|
const auth_1 = require("../command-helpers/auth");
|
|
35
34
|
const compiler_1 = require("../command-helpers/compiler");
|
|
36
35
|
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
@@ -41,6 +40,7 @@ const node_1 = require("../command-helpers/node");
|
|
|
41
40
|
const studio_1 = require("../command-helpers/studio");
|
|
42
41
|
const version_1 = require("../command-helpers/version");
|
|
43
42
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
43
|
+
const ipfs_http_client_1 = require("ipfs-http-client");
|
|
44
44
|
const headersFlag = core_1.Flags.custom({
|
|
45
45
|
summary: 'Add custom headers that will be used by the IPFS HTTP client.',
|
|
46
46
|
aliases: ['hdr'],
|
package/dist/commands/init.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const gluegun_1 = require("gluegun");
|
|
10
9
|
const core_1 = require("@oclif/core");
|
|
10
|
+
const gluegun_1 = require("gluegun");
|
|
11
11
|
const abi_1 = require("../command-helpers/abi");
|
|
12
12
|
const network_1 = require("../command-helpers/network");
|
|
13
13
|
const node_1 = require("../command-helpers/node");
|
package/dist/commands/local.js
CHANGED
|
@@ -7,11 +7,11 @@ const child_process_1 = require("child_process");
|
|
|
7
7
|
const http_1 = __importDefault(require("http"));
|
|
8
8
|
const net_1 = __importDefault(require("net"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const core_1 = require("@oclif/core");
|
|
10
11
|
const docker_compose_1 = __importDefault(require("docker-compose"));
|
|
11
12
|
const gluegun_1 = require("gluegun");
|
|
12
13
|
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
13
14
|
const tmp_promise_1 = __importDefault(require("tmp-promise"));
|
|
14
|
-
const core_1 = require("@oclif/core");
|
|
15
15
|
const spinner_1 = require("../command-helpers/spinner");
|
|
16
16
|
// Clean up temporary files even when an uncaught exception occurs
|
|
17
17
|
tmp_promise_1.default.setGracefulCleanup();
|
package/dist/commands/remove.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const url_1 = require("url");
|
|
4
|
-
const gluegun_1 = require("gluegun");
|
|
5
4
|
const core_1 = require("@oclif/core");
|
|
5
|
+
const gluegun_1 = require("gluegun");
|
|
6
6
|
const auth_1 = require("../command-helpers/auth");
|
|
7
7
|
const jsonrpc_1 = require("../command-helpers/jsonrpc");
|
|
8
8
|
const node_1 = require("../command-helpers/node");
|
package/dist/commands/test.js
CHANGED
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const child_process_1 = require("child_process");
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const core_1 = require("@oclif/core");
|
|
10
|
+
const fetch_1 = require("@whatwg-node/fetch");
|
|
9
11
|
const binary_install_raw_1 = require("binary-install-raw");
|
|
10
12
|
const gluegun_1 = require("gluegun");
|
|
11
13
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
12
14
|
const semver_1 = __importDefault(require("semver"));
|
|
13
|
-
const core_1 = require("@oclif/core");
|
|
14
|
-
const fetch_1 = require("@whatwg-node/fetch");
|
|
15
15
|
class TestCommand extends core_1.Command {
|
|
16
16
|
async run() {
|
|
17
17
|
const { args: { datasource }, flags: { coverage, docker, force, logs, recompile, version }, } = await this.parse(TestCommand);
|
package/dist/debug.js
CHANGED
|
@@ -11,12 +11,6 @@ debug_1.default.formatters.M = immutableMap => {
|
|
|
11
11
|
if (immutableMap.toMap != null) {
|
|
12
12
|
return JSON.stringify(immutableMap.toMap());
|
|
13
13
|
}
|
|
14
|
-
if (typeof immutableMap.toJS === 'function') {
|
|
15
|
-
return JSON.stringify(immutableMap.toJS());
|
|
16
|
-
}
|
|
17
|
-
if (typeof immutableMap === 'object') {
|
|
18
|
-
return JSON.stringify(immutableMap);
|
|
19
|
-
}
|
|
20
14
|
return immutableMap;
|
|
21
15
|
};
|
|
22
16
|
exports.default = debug_1.default;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
scalar String
|
|
8
8
|
scalar File
|
|
9
9
|
scalar BigInt
|
|
10
|
+
scalar JSON
|
|
10
11
|
|
|
11
12
|
type SubgraphManifest {
|
|
12
13
|
specVersion: String!
|
|
@@ -25,6 +26,7 @@ type DataSource {
|
|
|
25
26
|
kind: String!
|
|
26
27
|
name: String!
|
|
27
28
|
network: String
|
|
29
|
+
context: JSON
|
|
28
30
|
source: ContractSource!
|
|
29
31
|
mapping: ContractMapping!
|
|
30
32
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
scalar String
|
|
8
8
|
scalar File
|
|
9
9
|
scalar BigInt
|
|
10
|
+
scalar JSON
|
|
10
11
|
|
|
11
12
|
type SubgraphManifest {
|
|
12
13
|
specVersion: String!
|
|
@@ -26,6 +27,7 @@ type DataSource {
|
|
|
26
27
|
kind: String!
|
|
27
28
|
name: String!
|
|
28
29
|
network: String
|
|
30
|
+
context: JSON
|
|
29
31
|
source: ContractSource!
|
|
30
32
|
mapping: ContractMapping!
|
|
31
33
|
}
|
|
@@ -8,6 +8,7 @@ scalar String
|
|
|
8
8
|
scalar File
|
|
9
9
|
scalar BigInt
|
|
10
10
|
scalar Boolean
|
|
11
|
+
scalar JSON
|
|
11
12
|
|
|
12
13
|
type SubgraphManifest {
|
|
13
14
|
specVersion: String!
|
|
@@ -28,6 +29,7 @@ type DataSource {
|
|
|
28
29
|
kind: String!
|
|
29
30
|
name: String!
|
|
30
31
|
network: String
|
|
32
|
+
context: JSON
|
|
31
33
|
source: ContractSource!
|
|
32
34
|
mapping: ContractMapping!
|
|
33
35
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
scalar String
|
|
8
8
|
scalar File
|
|
9
9
|
scalar BigInt
|
|
10
|
+
scalar JSON
|
|
10
11
|
|
|
11
12
|
type SubgraphManifest {
|
|
12
13
|
specVersion: String!
|
|
@@ -26,6 +27,7 @@ type DataSource {
|
|
|
26
27
|
kind: String!
|
|
27
28
|
name: String!
|
|
28
29
|
network: String
|
|
30
|
+
context: JSON
|
|
29
31
|
source: ContractSource!
|
|
30
32
|
mapping: ContractMapping!
|
|
31
33
|
}
|
package/dist/scaffold/index.d.ts
CHANGED
|
@@ -24,42 +24,42 @@ export default class Scaffold {
|
|
|
24
24
|
startBlock?: string;
|
|
25
25
|
spkgPath?: string;
|
|
26
26
|
constructor(options: ScaffoldOptions);
|
|
27
|
-
generatePackageJson():
|
|
28
|
-
generatePackageJsonForSubstreams():
|
|
29
|
-
generateManifest():
|
|
30
|
-
generateSchema():
|
|
31
|
-
generateTsConfig():
|
|
27
|
+
generatePackageJson(): string;
|
|
28
|
+
generatePackageJsonForSubstreams(): string;
|
|
29
|
+
generateManifest(): string;
|
|
30
|
+
generateSchema(): string;
|
|
31
|
+
generateTsConfig(): string;
|
|
32
32
|
generateMappings(): {
|
|
33
|
-
[x: string]:
|
|
33
|
+
[x: string]: string;
|
|
34
34
|
} | undefined;
|
|
35
|
-
generateMapping():
|
|
35
|
+
generateMapping(): string;
|
|
36
36
|
generateABIs(): {
|
|
37
|
-
[x: string]:
|
|
37
|
+
[x: string]: string;
|
|
38
38
|
} | undefined;
|
|
39
39
|
generateTests(): {
|
|
40
|
-
[x: string]:
|
|
40
|
+
[x: string]: string;
|
|
41
41
|
} | undefined;
|
|
42
42
|
generate(): {
|
|
43
|
-
'subgraph.yaml':
|
|
44
|
-
'schema.graphql':
|
|
45
|
-
'package.json':
|
|
43
|
+
'subgraph.yaml': string;
|
|
44
|
+
'schema.graphql': string;
|
|
45
|
+
'package.json': string;
|
|
46
46
|
'tsconfig.json'?: undefined;
|
|
47
47
|
src?: undefined;
|
|
48
48
|
abis?: undefined;
|
|
49
49
|
tests?: undefined;
|
|
50
50
|
} | {
|
|
51
|
-
'package.json':
|
|
52
|
-
'subgraph.yaml':
|
|
53
|
-
'schema.graphql':
|
|
54
|
-
'tsconfig.json':
|
|
51
|
+
'package.json': string;
|
|
52
|
+
'subgraph.yaml': string;
|
|
53
|
+
'schema.graphql': string;
|
|
54
|
+
'tsconfig.json': string;
|
|
55
55
|
src: {
|
|
56
|
-
[x: string]:
|
|
56
|
+
[x: string]: string;
|
|
57
57
|
} | undefined;
|
|
58
58
|
abis: {
|
|
59
|
-
[x: string]:
|
|
59
|
+
[x: string]: string;
|
|
60
60
|
} | undefined;
|
|
61
61
|
tests: {
|
|
62
|
-
[x: string]:
|
|
62
|
+
[x: string]: string;
|
|
63
63
|
} | undefined;
|
|
64
64
|
};
|
|
65
65
|
}
|
package/dist/scaffold/schema.js
CHANGED
|
@@ -46,18 +46,14 @@ const protocolTypeToGraphQL = (protocol, name) => {
|
|
|
46
46
|
// TODO: this is a hack to make array type non-nullable
|
|
47
47
|
// We should refactor the way we convert the Values from ASC to GraphQL
|
|
48
48
|
// For arrays we always want non-nullable children
|
|
49
|
-
return convertedType.endsWith(']') ? convertedType.replace(
|
|
49
|
+
return convertedType.endsWith(']') ? convertedType.replace(']', '!]') : convertedType;
|
|
50
50
|
};
|
|
51
51
|
exports.protocolTypeToGraphQL = protocolTypeToGraphQL;
|
|
52
52
|
const generateField = ({ name, type, protocolName, }) => `${name}: ${(0, exports.protocolTypeToGraphQL)(protocolName, type)}! # ${type}`;
|
|
53
53
|
exports.generateField = generateField;
|
|
54
54
|
const generateEventFields = ({ index, input, protocolName, }) => input.type == 'tuple'
|
|
55
55
|
? util
|
|
56
|
-
.unrollTuple({
|
|
57
|
-
value: input,
|
|
58
|
-
path: [input.name || `param${index}`],
|
|
59
|
-
index,
|
|
60
|
-
})
|
|
56
|
+
.unrollTuple({ value: input, path: [input.name || `param${index}`], index })
|
|
61
57
|
.map(({ path, type }) => (0, exports.generateField)({ name: path.join('_'), type, protocolName }))
|
|
62
58
|
: [
|
|
63
59
|
(0, exports.generateField)({
|
package/dist/scaffold/tests.d.ts
CHANGED
package/dist/schema.d.ts
CHANGED
package/dist/subgraph.js
CHANGED
|
@@ -49,9 +49,8 @@ const buildCombinedWarning = (filename, warnings) => warnings.size > 0
|
|
|
49
49
|
: null;
|
|
50
50
|
class Subgraph {
|
|
51
51
|
static async validate(data, protocol, { resolveFile }) {
|
|
52
|
-
subgraphDebug
|
|
52
|
+
subgraphDebug(`Validating Subgraph with protocol "%s"`, protocol);
|
|
53
53
|
if (protocol.name == null) {
|
|
54
|
-
subgraphDebug.extend('validate')('Protocol has no name, skipping validation');
|
|
55
54
|
return immutable_1.default.fromJS([
|
|
56
55
|
{
|
|
57
56
|
path: [],
|
|
@@ -67,18 +66,13 @@ class Subgraph {
|
|
|
67
66
|
return definition.name.value === 'SubgraphManifest';
|
|
68
67
|
});
|
|
69
68
|
// Validate the subgraph manifest using this schema
|
|
70
|
-
return validation.validateManifest(data, rootType, schema, protocol, {
|
|
71
|
-
resolveFile,
|
|
72
|
-
});
|
|
69
|
+
return validation.validateManifest(data, rootType, schema, protocol, { resolveFile });
|
|
73
70
|
}
|
|
74
71
|
static validateSchema(manifest, { resolveFile }) {
|
|
75
|
-
subgraphDebug.extend('validate')('Validating schema in manifest');
|
|
76
72
|
const filename = resolveFile(manifest.getIn(['schema', 'file']));
|
|
77
|
-
subgraphDebug.extend('validate')('Loaded schema from %s', filename);
|
|
78
73
|
const validationErrors = validation.validateSchema(filename);
|
|
79
74
|
let errors;
|
|
80
75
|
if (validationErrors.size > 0) {
|
|
81
|
-
subgraphDebug.extend('validate')('Schema validation failed for %s', filename);
|
|
82
76
|
errors = validationErrors.groupBy(error => error.get('entity')).sort();
|
|
83
77
|
const msg = errors.reduce((msg, errors, entity) => {
|
|
84
78
|
errors = errors.groupBy((error) => error.get('directive'));
|
|
@@ -100,7 +94,6 @@ class Subgraph {
|
|
|
100
94
|
}
|
|
101
95
|
}
|
|
102
96
|
static validateRepository(manifest) {
|
|
103
|
-
subgraphDebug.extend('validate')('Validating repository in manifest');
|
|
104
97
|
const repository = manifest.get('repository');
|
|
105
98
|
return /^https:\/\/github\.com\/graphprotocol\/graph-tooling?$/.test(repository) ||
|
|
106
99
|
// For legacy reasons, we should error on example subgraphs
|
|
@@ -114,7 +107,6 @@ Please replace it with a link to your subgraph source code.`,
|
|
|
114
107
|
: immutable_1.default.List();
|
|
115
108
|
}
|
|
116
109
|
static validateDescription(manifest) {
|
|
117
|
-
subgraphDebug.extend('validate')('Validating description in manifest');
|
|
118
110
|
// TODO: Maybe implement this in the future for each protocol example description
|
|
119
111
|
return manifest.get('description', '').startsWith('Gravatar for ')
|
|
120
112
|
? immutable_1.default.List().push(immutable_1.default.fromJS({
|
|
@@ -126,7 +118,6 @@ Please update it to tell users more about your subgraph.`,
|
|
|
126
118
|
: immutable_1.default.List();
|
|
127
119
|
}
|
|
128
120
|
static validateHandlers(manifest, protocol, protocolSubgraph) {
|
|
129
|
-
subgraphDebug.extend('validate')('Validating handlers for protocol %s', protocol?.name);
|
|
130
121
|
return manifest
|
|
131
122
|
.get('dataSources')
|
|
132
123
|
.filter((dataSource) => protocol.isValidKindName(dataSource.get('kind')))
|
|
@@ -134,7 +125,7 @@ Please update it to tell users more about your subgraph.`,
|
|
|
134
125
|
const path = ['dataSources', dataSourceIndex, 'mapping'];
|
|
135
126
|
const mapping = dataSource.get('mapping');
|
|
136
127
|
const handlerTypes = protocolSubgraph.handlerTypes();
|
|
137
|
-
subgraphDebug
|
|
128
|
+
subgraphDebug('Validating dataSource "%s" handlers with %d handlers types defined for protocol', dataSource.get('name'), handlerTypes.size);
|
|
138
129
|
if (handlerTypes.size == 0) {
|
|
139
130
|
return errors;
|
|
140
131
|
}
|
|
@@ -153,16 +144,13 @@ At least one such handler must be defined.`,
|
|
|
153
144
|
}, immutable_1.default.List());
|
|
154
145
|
}
|
|
155
146
|
static validateContractValues(manifest, protocol) {
|
|
156
|
-
subgraphDebug.extend('validate')('Validating contract values for protocol %s', protocol?.name);
|
|
157
147
|
if (!protocol.hasContract()) {
|
|
158
|
-
subgraphDebug.extend('validate')('Protocol has no contract, skipping validation');
|
|
159
148
|
return immutable_1.default.List();
|
|
160
149
|
}
|
|
161
150
|
return validation.validateContractValues(manifest, protocol);
|
|
162
151
|
}
|
|
163
152
|
// Validate that data source names are unique, so they don't overwrite each other.
|
|
164
153
|
static validateUniqueDataSourceNames(manifest) {
|
|
165
|
-
subgraphDebug.extend('validate')('Validating that data source names are unique');
|
|
166
154
|
const names = [];
|
|
167
155
|
return manifest
|
|
168
156
|
.get('dataSources')
|
|
@@ -170,7 +158,6 @@ At least one such handler must be defined.`,
|
|
|
170
158
|
const path = ['dataSources', dataSourceIndex, 'name'];
|
|
171
159
|
const name = dataSource.get('name');
|
|
172
160
|
if (names.includes(name)) {
|
|
173
|
-
subgraphDebug.extend('validate')("Found duplicate data source name '%s', adding error");
|
|
174
161
|
errors = errors.push(immutable_1.default.fromJS({
|
|
175
162
|
path,
|
|
176
163
|
message: `\
|
|
@@ -182,7 +169,6 @@ More than one data source named '${name}', data source names must be unique.`,
|
|
|
182
169
|
}, immutable_1.default.List());
|
|
183
170
|
}
|
|
184
171
|
static validateUniqueTemplateNames(manifest) {
|
|
185
|
-
subgraphDebug.extend('validate')('Validating that template names are unique');
|
|
186
172
|
const names = [];
|
|
187
173
|
return manifest
|
|
188
174
|
.get('templates', immutable_1.default.List())
|
|
@@ -190,7 +176,6 @@ More than one data source named '${name}', data source names must be unique.`,
|
|
|
190
176
|
const path = ['templates', templateIndex, 'name'];
|
|
191
177
|
const name = template.get('name');
|
|
192
178
|
if (names.includes(name)) {
|
|
193
|
-
subgraphDebug.extend('validate')("Found duplicate template name '%s', adding error");
|
|
194
179
|
errors = errors.push(immutable_1.default.fromJS({
|
|
195
180
|
path,
|
|
196
181
|
message: `\
|
|
@@ -217,30 +202,21 @@ More than one template named '${name}', template names must be unique.`,
|
|
|
217
202
|
data = require(path_1.default.resolve(filename));
|
|
218
203
|
}
|
|
219
204
|
else {
|
|
220
|
-
subgraphDebug('Loading manifest from %s', filename);
|
|
221
205
|
const raw_data = await fs_extra_1.default.readFile(filename, 'utf-8');
|
|
222
|
-
subgraphDebug('Checking for file data sources in %s', filename);
|
|
223
206
|
has_file_data_sources = raw_data.includes('kind: file');
|
|
224
|
-
subgraphDebug('Parsing manifest from %s', filename);
|
|
225
207
|
data = yaml_1.default.parse(raw_data);
|
|
226
208
|
}
|
|
227
209
|
// Helper to resolve files relative to the subgraph manifest
|
|
228
210
|
const resolveFile = maybeRelativeFile => path_1.default.resolve(path_1.default.dirname(filename), maybeRelativeFile);
|
|
229
211
|
// TODO: Validation for file data sources
|
|
230
212
|
if (!has_file_data_sources) {
|
|
231
|
-
|
|
232
|
-
const manifestErrors = await Subgraph.validate(data, protocol, {
|
|
233
|
-
resolveFile,
|
|
234
|
-
});
|
|
213
|
+
const manifestErrors = await Subgraph.validate(data, protocol, { resolveFile });
|
|
235
214
|
if (manifestErrors.size > 0) {
|
|
236
|
-
subgraphDebug('Manifest validation failed for %s', filename);
|
|
237
215
|
throwCombinedError(filename, manifestErrors);
|
|
238
216
|
}
|
|
239
217
|
}
|
|
240
218
|
const manifest = immutable_1.default.fromJS(data);
|
|
241
|
-
subgraphDebug.extend('manifest')('Loaded: %M', manifest);
|
|
242
219
|
// Validate the schema
|
|
243
|
-
subgraphDebug.extend('manifest')('Validating schema');
|
|
244
220
|
Subgraph.validateSchema(manifest, { resolveFile });
|
|
245
221
|
// Perform other validations
|
|
246
222
|
const protocolSubgraph = protocol.getSubgraph({
|
package/dist/type-generator.js
CHANGED
|
@@ -27,13 +27,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const path_1 = __importDefault(require("path"));
|
|
30
|
+
// @ts-expect-error TODO: type out if necessary
|
|
31
|
+
const Index_bs_js_1 = __importDefault(require("@float-capital/float-subgraph-uncrashable/src/Index.bs.js"));
|
|
30
32
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
31
33
|
const toolbox = __importStar(require("gluegun"));
|
|
32
34
|
const graphql = __importStar(require("graphql/language"));
|
|
33
35
|
const immutable_1 = __importDefault(require("immutable"));
|
|
34
36
|
const prettier_1 = __importDefault(require("prettier"));
|
|
35
|
-
// @ts-expect-error TODO: type out if necessary
|
|
36
|
-
const Index_bs_js_1 = __importDefault(require("@float-capital/float-subgraph-uncrashable/src/Index.bs.js"));
|
|
37
37
|
const template_1 = __importDefault(require("./codegen/template"));
|
|
38
38
|
const typescript_1 = require("./codegen/typescript");
|
|
39
39
|
const fs_1 = require("./command-helpers/fs");
|
|
@@ -154,6 +154,20 @@ const validators = immutable_1.default.fromJS({
|
|
|
154
154
|
message: `Expected filename, found ${typeName(value)}:\n${value}`,
|
|
155
155
|
},
|
|
156
156
|
]),
|
|
157
|
+
JSON: (value, ctx) => {
|
|
158
|
+
try {
|
|
159
|
+
JSON.parse(JSON.stringify(value));
|
|
160
|
+
return List();
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
return immutable_1.default.fromJS([
|
|
164
|
+
{
|
|
165
|
+
path: ctx.get('path'),
|
|
166
|
+
message: `Invalid JSON value: ${e.message}`,
|
|
167
|
+
},
|
|
168
|
+
]);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
157
171
|
Boolean: (value, ctx) => typeof value === 'boolean'
|
|
158
172
|
? List()
|
|
159
173
|
: immutable_1.default.fromJS([
|
|
@@ -30,8 +30,6 @@ exports.validateSchema = exports.typeSuggestion = void 0;
|
|
|
30
30
|
const fs_1 = __importDefault(require("fs"));
|
|
31
31
|
const graphql = __importStar(require("graphql/language"));
|
|
32
32
|
const immutable_1 = __importDefault(require("immutable"));
|
|
33
|
-
const debug_1 = __importDefault(require("../debug"));
|
|
34
|
-
const validateDebugger = (0, debug_1.default)('graph-cli:validation');
|
|
35
33
|
const List = immutable_1.default.List;
|
|
36
34
|
const Set = immutable_1.default.Set;
|
|
37
35
|
// Builtin scalar types
|
|
@@ -103,23 +101,18 @@ const parseSchema = (doc) => {
|
|
|
103
101
|
throw new Error(`Invalid GraphQL schema: ${e}`);
|
|
104
102
|
}
|
|
105
103
|
};
|
|
106
|
-
const validateEntityDirective = (def) =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
},
|
|
116
|
-
]);
|
|
117
|
-
};
|
|
104
|
+
const validateEntityDirective = (def) => def.directives.find((directive) => directive.name.value === 'entity')
|
|
105
|
+
? List()
|
|
106
|
+
: immutable_1.default.fromJS([
|
|
107
|
+
{
|
|
108
|
+
loc: def.loc,
|
|
109
|
+
entity: def.name.value,
|
|
110
|
+
message: `Defined without @entity directive`,
|
|
111
|
+
},
|
|
112
|
+
]);
|
|
118
113
|
const validateEntityID = (def) => {
|
|
119
|
-
validateDebugger('Validating entity ID for %s', def?.name?.value);
|
|
120
114
|
const idField = def.fields.find((field) => field.name.value === 'id');
|
|
121
115
|
if (idField === undefined) {
|
|
122
|
-
validateDebugger('Entity %s has no id field', def?.name?.value);
|
|
123
116
|
return immutable_1.default.fromJS([
|
|
124
117
|
{
|
|
125
118
|
loc: def.loc,
|
|
@@ -133,10 +126,8 @@ const validateEntityID = (def) => {
|
|
|
133
126
|
(idField.type.type.name.value === 'ID' ||
|
|
134
127
|
idField.type.type.name.value === 'Bytes' ||
|
|
135
128
|
idField.type.type.name.value === 'String')) {
|
|
136
|
-
validateDebugger('Entity %s has valid id field', def?.name?.value);
|
|
137
129
|
return List();
|
|
138
130
|
}
|
|
139
|
-
validateDebugger('Entity %s has invalid id field', def?.name?.value);
|
|
140
131
|
return immutable_1.default.fromJS([
|
|
141
132
|
{
|
|
142
133
|
loc: idField.loc,
|
|
@@ -145,80 +136,52 @@ const validateEntityID = (def) => {
|
|
|
145
136
|
},
|
|
146
137
|
]);
|
|
147
138
|
};
|
|
148
|
-
const validateListFieldType = (def, field) =>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
entity: def.name.value,
|
|
157
|
-
message: `\
|
|
139
|
+
const validateListFieldType = (def, field) => field.type.kind === 'NonNullType' &&
|
|
140
|
+
field.type.kind === 'ListType' &&
|
|
141
|
+
field.type.type.kind !== 'NonNullType'
|
|
142
|
+
? immutable_1.default.fromJS([
|
|
143
|
+
{
|
|
144
|
+
loc: field.loc,
|
|
145
|
+
entity: def.name.value,
|
|
146
|
+
message: `\
|
|
158
147
|
Field '${field.name.value}':
|
|
159
148
|
Field has type [${field.type.type.name.value}]! but
|
|
160
149
|
must have type [${field.type.type.name.value}!]!
|
|
161
150
|
|
|
162
151
|
Reason: Lists with null elements are not supported.`,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
152
|
+
},
|
|
153
|
+
])
|
|
154
|
+
: field.type.kind === 'ListType' && field.type.type.kind !== 'NonNullType'
|
|
155
|
+
? immutable_1.default.fromJS([
|
|
156
|
+
{
|
|
157
|
+
loc: field.loc,
|
|
158
|
+
entity: def.name.value,
|
|
159
|
+
message: `\
|
|
171
160
|
Field '${field.name.value}':
|
|
172
161
|
Field has type [${field.type.type.name.value}] but
|
|
173
162
|
must have type [${field.type.type.name.value}!]
|
|
174
163
|
|
|
175
164
|
Reason: Lists with null elements are not supported.`,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
};
|
|
165
|
+
},
|
|
166
|
+
])
|
|
167
|
+
: List();
|
|
180
168
|
const unwrapType = (type) => {
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
validateDebugger.extend('unwrapType').extend('definition')('Unwrapping list type %M', listType);
|
|
184
|
-
if (listType.type.kind === 'NonNullType') {
|
|
185
|
-
validateDebugger.extend('unwrapType').extend('innerTypeFromList')('Returning non-null list type');
|
|
186
|
-
return innerTypeFromNonNull(listType.type);
|
|
187
|
-
}
|
|
188
|
-
validateDebugger.extend('unwrapType').extend('innerTypeFromList')('Returning list type');
|
|
189
|
-
return unwrapType(listType.type);
|
|
190
|
-
};
|
|
191
|
-
const innerTypeFromNonNull = (nonNullType) => {
|
|
192
|
-
validateDebugger.extend('unwrapType').extend('definition')('Unwrapping non-null type %M', nonNullType);
|
|
193
|
-
if (nonNullType.type.kind === 'ListType') {
|
|
194
|
-
validateDebugger.extend('unwrapType').extend('innerTypeFromNonNull')('Returning non-null list type');
|
|
195
|
-
return innerTypeFromList(nonNullType.type);
|
|
196
|
-
}
|
|
197
|
-
validateDebugger.extend('unwrapType').extend('innerTypeFromNonNull')('Returning non-null type');
|
|
198
|
-
return unwrapType(nonNullType.type);
|
|
199
|
-
};
|
|
169
|
+
const innerTypeFromList = (listType) => listType.type.kind === 'NonNullType' ? innerTypeFromNonNull(listType.type) : listType.type;
|
|
170
|
+
const innerTypeFromNonNull = (nonNullType) => nonNullType.type.kind === 'ListType' ? innerTypeFromList(nonNullType.type) : nonNullType.type;
|
|
200
171
|
// Obtain the inner-most type from the field
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return defs
|
|
215
|
-
.filter(def => def.kind === 'ObjectTypeDefinition' ||
|
|
216
|
-
def.kind === 'EnumTypeDefinition' ||
|
|
217
|
-
def.kind === 'InterfaceTypeDefinition')
|
|
218
|
-
.map(def =>
|
|
219
|
-
// @ts-expect-error TODO: name field does not exist on definition, really?
|
|
220
|
-
def.name.value);
|
|
221
|
-
};
|
|
172
|
+
return type.kind === 'NonNullType'
|
|
173
|
+
? innerTypeFromNonNull(type)
|
|
174
|
+
: type.kind === 'ListType'
|
|
175
|
+
? innerTypeFromList(type)
|
|
176
|
+
: type;
|
|
177
|
+
};
|
|
178
|
+
const gatherLocalTypes = (defs) => defs
|
|
179
|
+
.filter(def => def.kind === 'ObjectTypeDefinition' ||
|
|
180
|
+
def.kind === 'EnumTypeDefinition' ||
|
|
181
|
+
def.kind === 'InterfaceTypeDefinition')
|
|
182
|
+
.map(def =>
|
|
183
|
+
// @ts-expect-error TODO: name field does not exist on definition, really?
|
|
184
|
+
def.name.value);
|
|
222
185
|
const gatherImportedTypes = (defs) => defs
|
|
223
186
|
.filter(def => def.kind === 'ObjectTypeDefinition' &&
|
|
224
187
|
def.name.value == RESERVED_TYPE &&
|
|
@@ -243,28 +206,19 @@ def.directives
|
|
|
243
206
|
}
|
|
244
207
|
return flattened;
|
|
245
208
|
}, [])), []);
|
|
246
|
-
const entityTypeByName = (defs, name) =>
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
.find(def => def.name.value === name);
|
|
253
|
-
};
|
|
254
|
-
const fieldTargetEntityName = (field) => {
|
|
255
|
-
validateDebugger('Looking up field target entity name for %s', field?.name?.value);
|
|
256
|
-
return unwrapType(field.type).name.value;
|
|
257
|
-
};
|
|
209
|
+
const entityTypeByName = (defs, name) => defs
|
|
210
|
+
.filter(def => def.kind === 'InterfaceTypeDefinition' ||
|
|
211
|
+
(def.kind === 'ObjectTypeDefinition' &&
|
|
212
|
+
def.directives.find((directive) => directive.name.value === 'entity')))
|
|
213
|
+
.find(def => def.name.value === name);
|
|
214
|
+
const fieldTargetEntityName = (field) => unwrapType(field.type).name.value;
|
|
258
215
|
const fieldTargetEntity = (defs, field) => entityTypeByName(defs, fieldTargetEntityName(field));
|
|
259
216
|
const validateInnerFieldType = (defs, def, field) => {
|
|
260
|
-
validateDebugger('Validating inner field type for %s', def?.name?.value);
|
|
261
217
|
const innerType = unwrapType(field.type);
|
|
262
218
|
// Get the name of the type
|
|
263
219
|
const typeName = innerType.name.value;
|
|
264
|
-
validateDebugger('Inner field type name: %s', typeName);
|
|
265
220
|
// Look up a possible suggestion for the type to catch common mistakes
|
|
266
221
|
const suggestion = (0, exports.typeSuggestion)(typeName);
|
|
267
|
-
validateDebugger('Inner field type suggestion: %s', suggestion);
|
|
268
222
|
// Collect all types that we can use here: built-ins + entities + enums + interfaces
|
|
269
223
|
const availableTypes = List.of(...BUILTIN_SCALAR_TYPES, ...gatherLocalTypes(defs), ...gatherImportedTypes(defs));
|
|
270
224
|
// Check whether the type name is available, otherwise return an error
|
|
@@ -338,7 +292,6 @@ does not exist on type '${targetEntity.name.value}'`,
|
|
|
338
292
|
]);
|
|
339
293
|
}
|
|
340
294
|
const backrefTypeName = unwrapType(derivedFromField.type);
|
|
341
|
-
validateDebugger.extend('definition')('Backref type name: %M', backrefTypeName);
|
|
342
295
|
const backRefEntity = entityTypeByName(defs, backrefTypeName.name.value);
|
|
343
296
|
// The field we are deriving from must either have type 'def' or one of the
|
|
344
297
|
// interface types that 'def' is implementing
|
|
@@ -729,7 +682,6 @@ const validateImportDirectiveArgumentFrom = (def, directive, argument) => {
|
|
|
729
682
|
}, List());
|
|
730
683
|
};
|
|
731
684
|
const validateImportDirectiveFields = (def, directive) => {
|
|
732
|
-
validateDebugger('Validating import directive fields: %s', def?.name?.value);
|
|
733
685
|
return directive.arguments.reduce((errors, argument) => {
|
|
734
686
|
return errors.concat(['types', 'from'].includes(argument.name.value)
|
|
735
687
|
? List([])
|
|
@@ -743,7 +695,6 @@ const validateImportDirectiveFields = (def, directive) => {
|
|
|
743
695
|
}, List([]));
|
|
744
696
|
};
|
|
745
697
|
const validateImportDirectiveTypes = (def, directive) => {
|
|
746
|
-
validateDebugger('Validating import directive types: %s', def?.name?.value);
|
|
747
698
|
const types = directive.arguments.find((argument) => argument.name.value == 'types');
|
|
748
699
|
return types
|
|
749
700
|
? validateImportDirectiveArgumentTypes(def, directive, types)
|
|
@@ -756,7 +707,6 @@ const validateImportDirectiveTypes = (def, directive) => {
|
|
|
756
707
|
]);
|
|
757
708
|
};
|
|
758
709
|
const validateImportDirectiveFrom = (def, directive) => {
|
|
759
|
-
validateDebugger('Validating import directive from: %s', def?.name?.value);
|
|
760
710
|
const from = directive.arguments.find((argument) => argument.name.value == 'from');
|
|
761
711
|
return from
|
|
762
712
|
? validateImportDirectiveArgumentFrom(def, directive, from)
|
|
@@ -768,19 +718,13 @@ const validateImportDirectiveFrom = (def, directive) => {
|
|
|
768
718
|
}),
|
|
769
719
|
]);
|
|
770
720
|
};
|
|
771
|
-
const validateImportDirective = (def, directive) =>
|
|
772
|
-
validateDebugger('Validating import directive: %s', def?.name?.value);
|
|
773
|
-
return List.of(...validateImportDirectiveFields(def, directive), ...validateImportDirectiveTypes(def, directive), ...validateImportDirectiveFrom(def, directive));
|
|
774
|
-
};
|
|
721
|
+
const validateImportDirective = (def, directive) => List.of(...validateImportDirectiveFields(def, directive), ...validateImportDirectiveTypes(def, directive), ...validateImportDirectiveFrom(def, directive));
|
|
775
722
|
const validateFulltext = (def, directive) => List.of(...validateFulltextFields(def, directive), ...validateFulltextName(def, directive), ...validateFulltextLanguage(def, directive), ...validateFulltextAlgorithm(def, directive), ...validateFulltextInclude(def, directive));
|
|
776
723
|
const validateSubgraphSchemaDirective = (def, directive) => {
|
|
777
|
-
validateDebugger('Validating subgraph schema directive: %s', def?.name?.value);
|
|
778
724
|
if (directive.name.value == 'import') {
|
|
779
|
-
validateDebugger('Validating import directive: %s', def?.name?.value);
|
|
780
725
|
return validateImportDirective(def, directive);
|
|
781
726
|
}
|
|
782
727
|
if (directive.name.value == 'fulltext') {
|
|
783
|
-
validateDebugger('Validating fulltext directive: %s', def?.name?.value);
|
|
784
728
|
return validateFulltext(def, directive);
|
|
785
729
|
}
|
|
786
730
|
return List([
|
|
@@ -791,52 +735,32 @@ const validateSubgraphSchemaDirective = (def, directive) => {
|
|
|
791
735
|
}),
|
|
792
736
|
]);
|
|
793
737
|
};
|
|
794
|
-
const validateSubgraphSchemaDirectives = (def) =>
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
entity: def.name.value,
|
|
805
|
-
message: `${def.name.value} type is not allowed any fields by convention`,
|
|
806
|
-
}),
|
|
807
|
-
])
|
|
808
|
-
: List();
|
|
809
|
-
};
|
|
738
|
+
const validateSubgraphSchemaDirectives = (def) => def.directives.reduce((errors, directive) => errors.concat(validateSubgraphSchemaDirective(def, directive)), List());
|
|
739
|
+
const validateTypeHasNoFields = (def) => def.fields.length
|
|
740
|
+
? List([
|
|
741
|
+
immutable_1.default.fromJS({
|
|
742
|
+
loc: def.name.loc,
|
|
743
|
+
entity: def.name.value,
|
|
744
|
+
message: `${def.name.value} type is not allowed any fields by convention`,
|
|
745
|
+
}),
|
|
746
|
+
])
|
|
747
|
+
: List();
|
|
810
748
|
const validateAtLeastOneExtensionField = (_def) => List();
|
|
811
749
|
const typeDefinitionValidators = {
|
|
812
|
-
ObjectTypeDefinition: (defs, def) =>
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
},
|
|
822
|
-
};
|
|
823
|
-
const validateTypeDefinition = (defs, def) => {
|
|
824
|
-
validateDebugger.extend('definition')('Validating type definition: %M', def);
|
|
825
|
-
return typeDefinitionValidators[def.kind] === undefined
|
|
826
|
-
? List()
|
|
827
|
-
: typeDefinitionValidators[def.kind](defs, def);
|
|
828
|
-
};
|
|
829
|
-
const validateTypeDefinitions = (defs) => {
|
|
830
|
-
validateDebugger('Validating type definitions');
|
|
831
|
-
return defs.reduce((errors, def) => errors.concat(validateTypeDefinition(defs, def)), List());
|
|
832
|
-
};
|
|
750
|
+
ObjectTypeDefinition: (defs, def) => def.name && def.name.value == RESERVED_TYPE
|
|
751
|
+
? List.of(...validateSubgraphSchemaDirectives(def), ...validateTypeHasNoFields(def))
|
|
752
|
+
: List.of(...validateEntityDirective(def), ...validateEntityID(def), ...validateEntityFields(defs, def), ...validateNoImportDirective(def), ...validateNoFulltext(def)),
|
|
753
|
+
ObjectTypeExtension: (_defs, def) => validateAtLeastOneExtensionField(def),
|
|
754
|
+
};
|
|
755
|
+
const validateTypeDefinition = (defs, def) => typeDefinitionValidators[def.kind] === undefined
|
|
756
|
+
? List()
|
|
757
|
+
: typeDefinitionValidators[def.kind](defs, def);
|
|
758
|
+
const validateTypeDefinitions = (defs) => defs.reduce((errors, def) => errors.concat(validateTypeDefinition(defs, def)), List());
|
|
833
759
|
const validateNamingCollisionsInTypes = (types) => {
|
|
834
|
-
validateDebugger('Validating naming collisions in types');
|
|
835
760
|
let seen = Set();
|
|
836
761
|
let conflicting = Set();
|
|
837
762
|
return types.reduce((errors, type) => {
|
|
838
763
|
if (seen.has(type) && !conflicting.has(type)) {
|
|
839
|
-
validateDebugger('Found naming collision');
|
|
840
764
|
errors = errors.push(immutable_1.default.fromJS({
|
|
841
765
|
loc: { start: 1, end: 1 },
|
|
842
766
|
entity: type,
|
|
@@ -850,16 +774,10 @@ const validateNamingCollisionsInTypes = (types) => {
|
|
|
850
774
|
return errors;
|
|
851
775
|
}, List());
|
|
852
776
|
};
|
|
853
|
-
const validateNamingCollisions = (local, imported) =>
|
|
854
|
-
validateDebugger('Validating naming collisions');
|
|
855
|
-
return validateNamingCollisionsInTypes(local.concat(imported));
|
|
856
|
-
};
|
|
777
|
+
const validateNamingCollisions = (local, imported) => validateNamingCollisionsInTypes(local.concat(imported));
|
|
857
778
|
const validateSchema = (filename) => {
|
|
858
|
-
validateDebugger('Validating schema: %s', filename);
|
|
859
779
|
const doc = loadSchema(filename);
|
|
860
|
-
validateDebugger('Loaded schema: %s', filename);
|
|
861
780
|
const schema = parseSchema(doc);
|
|
862
|
-
validateDebugger.extend('schema')('Parsed schema: %M', schema);
|
|
863
781
|
return List.of(...validateTypeDefinitions(schema.definitions), ...validateNamingCollisions(gatherLocalTypes(schema.definitions), gatherImportedTypes(schema.definitions)));
|
|
864
782
|
};
|
|
865
783
|
exports.validateSchema = validateSchema;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.57.0-alpha-
|
|
3
|
+
"version": "0.57.0-alpha-20230904080157-a384f00",
|
|
4
4
|
"description": "CLI for building for and deploying to The Graph",
|
|
5
5
|
"license": "(Apache-2.0 OR MIT)",
|
|
6
6
|
"engines": {
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@float-capital/float-subgraph-uncrashable": "^0.0.0-alpha.4",
|
|
23
23
|
"@oclif/core": "2.8.6",
|
|
24
|
-
"@oclif/plugin-autocomplete": "^2.3.6",
|
|
25
|
-
"@oclif/plugin-not-found": "^2.4.0",
|
|
26
24
|
"@whatwg-node/fetch": "^0.8.4",
|
|
27
25
|
"assemblyscript": "0.19.23",
|
|
28
26
|
"binary-install-raw": "0.0.13",
|
|
@@ -56,7 +54,7 @@
|
|
|
56
54
|
"@types/semver": "^7.3.13",
|
|
57
55
|
"@types/which": "^2.0.1",
|
|
58
56
|
"copyfiles": "^2.4.1",
|
|
59
|
-
"jest": "29.
|
|
57
|
+
"jest": "29.5.0",
|
|
60
58
|
"oclif": "3.8.1",
|
|
61
59
|
"spawn-command": "0.0.2-1",
|
|
62
60
|
"strip-ansi": "6.0.1",
|
|
@@ -74,10 +72,6 @@
|
|
|
74
72
|
],
|
|
75
73
|
"additionalVersionFlags": [
|
|
76
74
|
"-v"
|
|
77
|
-
],
|
|
78
|
-
"plugins": [
|
|
79
|
-
"@oclif/plugin-not-found",
|
|
80
|
-
"@oclif/plugin-autocomplete"
|
|
81
75
|
]
|
|
82
76
|
},
|
|
83
77
|
"scripts": {
|