@graphprotocol/graph-cli 0.37.4 → 0.37.5
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/dist/bin.js +6 -0
- package/dist/cli.js +26 -0
- package/dist/codegen/schema.js +244 -0
- package/dist/codegen/schema.test.js +455 -0
- package/dist/codegen/template.js +66 -0
- package/dist/codegen/types/conversions.js +335 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +40 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +76 -0
- package/dist/command-helpers/auth.js +76 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +48 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +27 -0
- package/dist/command-helpers/network.js +90 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +110 -0
- package/dist/command-helpers/spinner.js +80 -0
- package/dist/command-helpers/studio.js +14 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +22 -0
- package/dist/command-helpers/version.js +66 -0
- package/dist/command-helpers/version.test.js +186 -0
- package/dist/commands/add.js +187 -0
- package/dist/commands/auth.js +122 -0
- package/dist/commands/build.js +136 -0
- package/dist/commands/codegen.js +128 -0
- package/dist/commands/create.js +94 -0
- package/dist/commands/deploy.js +335 -0
- package/dist/commands/init.js +800 -0
- package/dist/commands/local.js +380 -0
- package/dist/commands/remove.js +95 -0
- package/dist/commands/test.js +293 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +466 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +83 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +85 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +85 -0
- package/dist/migrations/spec_version_0_0_2.js +45 -0
- package/dist/migrations/spec_version_0_0_3.js +50 -0
- package/dist/migrations/util/load-manifest.js +16 -0
- package/dist/migrations/util/versions.js +28 -0
- package/dist/migrations.js +54 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/contract.js +2 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +28 -0
- package/dist/protocols/ethereum/abi.js +138 -0
- package/dist/protocols/ethereum/codegen/abi.js +474 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +325 -0
- package/dist/protocols/ethereum/codegen/template.js +52 -0
- package/dist/protocols/ethereum/contract.js +22 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +172 -0
- package/dist/protocols/ethereum/type-generator.js +123 -0
- package/dist/protocols/index.js +266 -0
- package/dist/protocols/ipfs/codegen/file_template.js +53 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +23 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +82 -0
- package/dist/scaffold/ethereum.test.js +496 -0
- package/dist/scaffold/index.js +133 -0
- package/dist/scaffold/mapping.js +57 -0
- package/dist/scaffold/near.test.js +85 -0
- package/dist/scaffold/schema.js +86 -0
- package/dist/scaffold/tests.js +179 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +243 -0
- package/dist/type-generator.js +225 -0
- package/dist/validation/contract.js +44 -0
- package/dist/validation/index.js +10 -0
- package/dist/validation/manifest.js +266 -0
- package/dist/validation/schema.js +768 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/package.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Each referenced type's in any of the types below must be listed
|
|
2
|
+
# here either as `scalar` or `type` for the validation code to work
|
|
3
|
+
# properly.
|
|
4
|
+
#
|
|
5
|
+
# That's why `String` is listed as a scalar even though it's built-in
|
|
6
|
+
# GraphQL basic types.
|
|
7
|
+
scalar String
|
|
8
|
+
scalar File
|
|
9
|
+
scalar BigInt
|
|
10
|
+
|
|
11
|
+
type SubgraphManifest {
|
|
12
|
+
specVersion: String!
|
|
13
|
+
features: [String!]
|
|
14
|
+
schema: Schema!
|
|
15
|
+
description: String
|
|
16
|
+
repository: String
|
|
17
|
+
graft: Graft
|
|
18
|
+
dataSources: [DataSource!]!
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type Schema {
|
|
22
|
+
file: File!
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type DataSource {
|
|
26
|
+
kind: String!
|
|
27
|
+
name: String!
|
|
28
|
+
network: String
|
|
29
|
+
source: ContractSource!
|
|
30
|
+
mapping: ContractMapping!
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type ContractSource {
|
|
34
|
+
account: String
|
|
35
|
+
startBlock: BigInt
|
|
36
|
+
accounts: PartialAccount
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type PartialAccount {
|
|
40
|
+
prefixes: [String!]
|
|
41
|
+
suffixes: [String!]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type ContractMapping {
|
|
45
|
+
apiVersion: String!
|
|
46
|
+
language: String!
|
|
47
|
+
file: File!
|
|
48
|
+
entities: [String!]!
|
|
49
|
+
blockHandlers: [BlockHandler!]
|
|
50
|
+
receiptHandlers: [ReceiptHandler!]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type BlockHandler {
|
|
54
|
+
handler: String!
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type ReceiptHandler {
|
|
58
|
+
handler: String!
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type Graft {
|
|
62
|
+
base: String!
|
|
63
|
+
block: BigInt!
|
|
64
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapping = exports.source = void 0;
|
|
4
|
+
const gluegun_1 = require("gluegun");
|
|
5
|
+
const source = ({ contract }) => `
|
|
6
|
+
account: '${contract}'`;
|
|
7
|
+
exports.source = source;
|
|
8
|
+
const mapping = ({ contractName }) => `
|
|
9
|
+
apiVersion: 0.0.5
|
|
10
|
+
language: wasm/assemblyscript
|
|
11
|
+
entities:
|
|
12
|
+
- ExampleEntity
|
|
13
|
+
receiptHandlers:
|
|
14
|
+
- handler: handleReceipt
|
|
15
|
+
file: ./src/${gluegun_1.strings.kebabCase(contractName)}.ts`;
|
|
16
|
+
exports.mapping = mapping;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatePlaceholderHandlers = void 0;
|
|
4
|
+
const generatePlaceholderHandlers = () => `
|
|
5
|
+
import { near, BigInt } from '@graphprotocol/graph-ts'
|
|
6
|
+
import { ExampleEntity } from '../generated/schema'
|
|
7
|
+
|
|
8
|
+
export function handleReceipt(receiptWithOutcome: near.ReceiptWithOutcome): void {
|
|
9
|
+
// Entities can be loaded from the store using a string ID; this ID
|
|
10
|
+
// needs to be unique across all entities of the same type
|
|
11
|
+
let entity = ExampleEntity.load(receiptWithOutcome.receipt.id.toHex())
|
|
12
|
+
|
|
13
|
+
// Entities only exist after they have been saved to the store;
|
|
14
|
+
// \`null\` checks allow to create entities on demand
|
|
15
|
+
if (!entity) {
|
|
16
|
+
entity = new ExampleEntity(receiptWithOutcome.receipt.id.toHex())
|
|
17
|
+
|
|
18
|
+
// Entity fields can be set using simple assignments
|
|
19
|
+
entity.count = BigInt.fromI32(0)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// BigInt and BigDecimal math are supported
|
|
23
|
+
entity.count = entity.count + BigInt.fromI32(1)
|
|
24
|
+
|
|
25
|
+
// Entity fields can be set based on receipt information
|
|
26
|
+
entity.block = receiptWithOutcome.block.header.hash
|
|
27
|
+
|
|
28
|
+
// Entities can be written to the store with \`.save()\`
|
|
29
|
+
entity.save()
|
|
30
|
+
|
|
31
|
+
// Note: If a handler doesn't require existing field values, it is faster
|
|
32
|
+
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
33
|
+
// \`new Entity(...)\`, set the fields that should be updated and save the
|
|
34
|
+
// entity back to the store. Fields that were not set or unset remain
|
|
35
|
+
// unchanged, allowing for partial updates to be applied.
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
exports.generatePlaceholderHandlers = generatePlaceholderHandlers;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
class NearSubgraph {
|
|
8
|
+
manifest;
|
|
9
|
+
resolveFile;
|
|
10
|
+
protocol;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.manifest = options.manifest;
|
|
13
|
+
this.resolveFile = options.resolveFile;
|
|
14
|
+
this.protocol = options.protocol;
|
|
15
|
+
}
|
|
16
|
+
validateManifest() {
|
|
17
|
+
return immutable_1.default.List();
|
|
18
|
+
}
|
|
19
|
+
handlerTypes() {
|
|
20
|
+
return immutable_1.default.List(['blockHandlers', 'receiptHandlers']);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = NearSubgraph;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Each referenced type's in any of the types below must be listed
|
|
2
|
+
# here either as `scalar` or `type` for the validation code to work
|
|
3
|
+
# properly.
|
|
4
|
+
#
|
|
5
|
+
# That's why `String` is listed as a scalar even though it's built-in
|
|
6
|
+
# GraphQL basic types.
|
|
7
|
+
scalar String
|
|
8
|
+
scalar File
|
|
9
|
+
scalar BigInt
|
|
10
|
+
|
|
11
|
+
type SubgraphManifest {
|
|
12
|
+
specVersion: String!
|
|
13
|
+
features: [String!]
|
|
14
|
+
schema: Schema!
|
|
15
|
+
description: String
|
|
16
|
+
repository: String
|
|
17
|
+
graft: Graft
|
|
18
|
+
dataSources: [DataSource!]!
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type Schema {
|
|
22
|
+
file: File!
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type DataSource {
|
|
26
|
+
kind: String!
|
|
27
|
+
name: String!
|
|
28
|
+
network: String
|
|
29
|
+
source: SubstreamsSource!
|
|
30
|
+
mapping: SubstreamMapping!
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type SubstreamsSource {
|
|
34
|
+
package: SubstreamsPackage!
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type SubstreamsPackage {
|
|
38
|
+
moduleName: String!
|
|
39
|
+
file: String!
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type SubstreamMapping {
|
|
43
|
+
apiVersion: String!
|
|
44
|
+
kind: String!
|
|
45
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapping = exports.source = void 0;
|
|
4
|
+
const source = () => `
|
|
5
|
+
package:
|
|
6
|
+
moduleName: graph_out
|
|
7
|
+
file: substreams-eth-block-meta-v0.1.0.spkg`;
|
|
8
|
+
exports.source = source;
|
|
9
|
+
const mapping = () => `
|
|
10
|
+
apiVersion: 0.0.5
|
|
11
|
+
kind: substreams/graph-entities`;
|
|
12
|
+
exports.mapping = mapping;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
7
|
+
class SubstreamsSubgraph {
|
|
8
|
+
manifest;
|
|
9
|
+
resolveFile;
|
|
10
|
+
protocol;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.manifest = options.manifest;
|
|
13
|
+
this.resolveFile = options.resolveFile;
|
|
14
|
+
this.protocol = options.protocol;
|
|
15
|
+
}
|
|
16
|
+
validateManifest() {
|
|
17
|
+
return immutable_1.default.List();
|
|
18
|
+
}
|
|
19
|
+
handlerTypes() {
|
|
20
|
+
return immutable_1.default.List([]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.default = SubstreamsSubgraph;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const protocols_1 = __importDefault(require("../protocols"));
|
|
7
|
+
const index_1 = __importDefault(require("./index"));
|
|
8
|
+
const protocol = new protocols_1.default('cosmos');
|
|
9
|
+
const scaffoldOptions = {
|
|
10
|
+
protocol,
|
|
11
|
+
network: 'cosmoshub-4',
|
|
12
|
+
contractName: 'CosmosHub',
|
|
13
|
+
};
|
|
14
|
+
const scaffold = new index_1.default(scaffoldOptions);
|
|
15
|
+
describe('Cosmos subgraph scaffolding', () => {
|
|
16
|
+
test('Manifest', () => {
|
|
17
|
+
expect(scaffold.generateManifest()).toEqual(`\
|
|
18
|
+
specVersion: 0.0.5
|
|
19
|
+
schema:
|
|
20
|
+
file: ./schema.graphql
|
|
21
|
+
dataSources:
|
|
22
|
+
- kind: cosmos
|
|
23
|
+
name: CosmosHub
|
|
24
|
+
network: cosmoshub-4
|
|
25
|
+
source:
|
|
26
|
+
startBlock: 0
|
|
27
|
+
mapping:
|
|
28
|
+
apiVersion: 0.0.5
|
|
29
|
+
language: wasm/assemblyscript
|
|
30
|
+
entities:
|
|
31
|
+
- ExampleEntity
|
|
32
|
+
blockHandlers:
|
|
33
|
+
- handler: handleBlock
|
|
34
|
+
file: ./src/contract.ts
|
|
35
|
+
`);
|
|
36
|
+
});
|
|
37
|
+
test('Schema (default)', () => {
|
|
38
|
+
expect(scaffold.generateSchema()).toEqual(`\
|
|
39
|
+
type ExampleEntity @entity {
|
|
40
|
+
id: ID!
|
|
41
|
+
block: Bytes!
|
|
42
|
+
count: BigInt!
|
|
43
|
+
}
|
|
44
|
+
`);
|
|
45
|
+
});
|
|
46
|
+
test('Mapping (default)', () => {
|
|
47
|
+
expect(scaffold.generateMapping()).toEqual(`\
|
|
48
|
+
import { cosmos, BigInt } from "@graphprotocol/graph-ts"
|
|
49
|
+
import { ExampleEntity } from "../generated/schema"
|
|
50
|
+
|
|
51
|
+
export function handleBlock(block: cosmos.Block): void {
|
|
52
|
+
// Entities can be loaded from the store using a string ID; this ID
|
|
53
|
+
// needs to be unique across all entities of the same type
|
|
54
|
+
let entity = ExampleEntity.load(block.header.hash.toHex())
|
|
55
|
+
|
|
56
|
+
// Entities only exist after they have been saved to the store;
|
|
57
|
+
// \`null\` checks allow to create entities on demand
|
|
58
|
+
if (!entity) {
|
|
59
|
+
entity = new ExampleEntity(block.header.hash.toHex())
|
|
60
|
+
|
|
61
|
+
// Entity fields can be set using simple assignments
|
|
62
|
+
entity.count = BigInt.fromI32(0)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// BigInt and BigDecimal math are supported
|
|
66
|
+
entity.count = entity.count + BigInt.fromI32(1)
|
|
67
|
+
|
|
68
|
+
// Entity fields can be set based on receipt information
|
|
69
|
+
entity.height = block.header.height
|
|
70
|
+
|
|
71
|
+
// Entities can be written to the store with \`.save()\`
|
|
72
|
+
entity.save()
|
|
73
|
+
|
|
74
|
+
// Note: If a handler doesn't require existing field values, it is faster
|
|
75
|
+
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
76
|
+
// \`new Entity(...)\`, set the fields that should be updated and save the
|
|
77
|
+
// entity back to the store. Fields that were not set or unset remain
|
|
78
|
+
// unchanged, allowing for partial updates to be applied.
|
|
79
|
+
}
|
|
80
|
+
`);
|
|
81
|
+
});
|
|
82
|
+
});
|