@graphprotocol/graph-cli 0.24.0-alpha.0 → 0.25.1

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.
Files changed (52) hide show
  1. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/README.md +83 -0
  2. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +2 -0
  3. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/json.ts +2 -2
  4. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +2 -7
  5. package/examples/basic-event-handlers/package.json +1 -1
  6. package/examples/basic-event-handlers/yarn.lock +4 -4
  7. package/examples/example-subgraph/package.json +1 -1
  8. package/examples/example-subgraph/yarn.lock +4 -4
  9. package/package.json +1 -1
  10. package/src/codegen/schema.js +9 -2
  11. package/src/codegen/types/index.js +8 -1
  12. package/src/command-helpers/scaffold.js +66 -0
  13. package/src/command-helpers/version.js +1 -1
  14. package/src/command-helpers/version.test.js +1 -1
  15. package/src/commands/init.js +128 -92
  16. package/src/protocols/ethereum/contract.js +22 -0
  17. package/src/protocols/ethereum/scaffold/manifest.js +32 -0
  18. package/src/protocols/ethereum/scaffold/mapping.js +76 -0
  19. package/src/protocols/ethereum/subgraph.js +0 -14
  20. package/src/protocols/index.js +88 -8
  21. package/src/protocols/near/contract.js +46 -0
  22. package/src/protocols/near/scaffold/manifest.js +16 -0
  23. package/src/protocols/near/scaffold/mapping.js +39 -0
  24. package/src/protocols/near/subgraph.js +1 -23
  25. package/src/{scaffold.test.js → scaffold/ethereum.test.js} +27 -19
  26. package/src/scaffold/index.js +149 -0
  27. package/src/scaffold/mapping.js +49 -0
  28. package/src/scaffold/near.test.js +89 -0
  29. package/src/scaffold/schema.js +62 -0
  30. package/src/subgraph.js +8 -0
  31. package/src/validation/contract.js +56 -0
  32. package/src/validation/index.js +2 -1
  33. package/src/validation/manifest.js +0 -29
  34. package/tests/cli/init/{abis → ethereum/abis}/Marketplace.json +0 -0
  35. package/tests/cli/init/{abis → ethereum/abis}/OverloadedElements.json +0 -0
  36. package/tests/cli/init/{abis → ethereum/abis}/SoloMargin.json +0 -0
  37. package/tests/cli/init/{from-contract-with-abi-and-structs.stderr → ethereum/from-contract-with-abi-and-structs.stderr} +1 -1
  38. package/tests/cli/init/{from-contract-with-abi-and-structs.stdout → ethereum/from-contract-with-abi-and-structs.stdout} +0 -0
  39. package/tests/cli/init/{from-contract-with-abi.stderr → ethereum/from-contract-with-abi.stderr} +1 -1
  40. package/tests/cli/init/{from-contract-with-abi.stdout → ethereum/from-contract-with-abi.stdout} +0 -0
  41. package/tests/cli/init/{from-contract-with-overloaded-elements.stderr → ethereum/from-contract-with-overloaded-elements.stderr} +1 -1
  42. package/tests/cli/init/{from-contract-with-overloaded-elements.stdout → ethereum/from-contract-with-overloaded-elements.stdout} +0 -0
  43. package/tests/cli/init/{from-contract.stderr → ethereum/from-contract.stderr} +1 -1
  44. package/tests/cli/init/{from-contract.stdout → ethereum/from-contract.stdout} +0 -0
  45. package/tests/cli/init/{from-example.stderr → ethereum/from-example.stderr} +0 -0
  46. package/tests/cli/init/{from-example.stdout → ethereum/from-example.stdout} +0 -0
  47. package/tests/cli/init/near/from-contract.stderr +12 -0
  48. package/tests/cli/init/near/from-contract.stdout +12 -0
  49. package/tests/cli/init.test.js +143 -112
  50. package/tests/cli/util.js +56 -41
  51. package/tests/cli/validation/near-is-valid/subgraph.yaml +1 -0
  52. package/src/scaffold.js +0 -364
@@ -69,6 +69,89 @@ For examples of `graph-ts` in use take a look at one of the following subgraphs:
69
69
  * https://github.com/graphprotocol/aragon-subgraph
70
70
  * https://github.com/graphprotocol/dharma-subgraph
71
71
 
72
+ ## Release process
73
+
74
+ The steps to create a new version of the `graph-ts` are:
75
+
76
+ 1. Decide which version number you'll be rolling out. You can check the differences between the current `master` branch and the latest release.
77
+ 2. Create a PR with the commit generated by `npm version <VERSION> [<PREID>]`.
78
+ 3. Once that's approved and merged to `master`, you can publish it to `npm` and push the git tags as well.
79
+ 4. Last but not least, create a Github Release refering to the pushed git tag, linking to the PRs involved.
80
+
81
+ Helpful links:
82
+
83
+ - [Semver official docs](https://semver.org/)
84
+ - [`npm version` docs](https://docs.npmjs.com/cli/v7/commands/npm-version)
85
+ - [`npm publish` docs](https://docs.npmjs.com/cli/v7/commands/npm-publish)
86
+ - [`npm unpublish` docs](https://docs.npmjs.com/cli/v7/commands/npm-unpublish)
87
+ - [`npm deprecate` docs](https://docs.npmjs.com/cli/v7/commands/npm-deprecate)
88
+
89
+ ### Stable release example
90
+
91
+ Current version: `0.34.9`.
92
+ Desired release: `0.35.0`.
93
+
94
+ To create the PR:
95
+ ```
96
+ git checkout -b <BRANCH>
97
+
98
+ npm version minor
99
+
100
+ git push --set-upstream <REMOTE> <BRANCH>
101
+ ```
102
+
103
+ Once that's approved and merged, you can update your local `master` and:
104
+
105
+ ```
106
+ npm publish
107
+
108
+ npm push --tags
109
+ ```
110
+
111
+ ### Alpha release example
112
+
113
+ Current version: `0.29.2`.
114
+ Desired release: `0.30.0-alpha.0`.
115
+
116
+ To create the PR:
117
+ ```
118
+ git checkout -b <BRANCH>
119
+
120
+ npm version preminor --preid alpha
121
+
122
+ git push --set-upstream <REMOTE> <BRANCH>
123
+ ```
124
+
125
+ Once that's approved and merged, you can update your local `master` and:
126
+
127
+ ```
128
+ npm publish --tag alpha
129
+
130
+ npm push --tags
131
+ ```
132
+
133
+ ### Alpha pre-release example
134
+
135
+ Current version: `0.30.0-alpha.0`.
136
+ Desired release: `0.30.0-alpha.1`.
137
+
138
+ To create the PR:
139
+ ```
140
+ git checkout -b <BRANCH>
141
+
142
+ npm version prerelease --preid alpha
143
+
144
+ git push --set-upstream <REMOTE> <BRANCH>
145
+ ```
146
+
147
+ Once that's approved and merged, you can update your local `master` and:
148
+
149
+ ```
150
+ npm publish --tag alpha
151
+
152
+ npm push --tags
153
+ ```
154
+
72
155
  ## License
73
156
 
74
157
  Copyright &copy; 2018 Graph Protocol, Inc. and contributors.
@@ -339,6 +339,7 @@ export namespace ethereum {
339
339
  public difficulty: BigInt,
340
340
  public totalDifficulty: BigInt,
341
341
  public size: BigInt | null,
342
+ public baseFeePerGas: BigInt | null,
342
343
  ) {}
343
344
  }
344
345
 
@@ -355,6 +356,7 @@ export namespace ethereum {
355
356
  public gasLimit: BigInt,
356
357
  public gasPrice: BigInt,
357
358
  public input: Bytes,
359
+ public nonce: Bytes,
358
360
  ) {}
359
361
  }
360
362
 
@@ -14,13 +14,13 @@ export declare namespace json {
14
14
  }
15
15
 
16
16
  export namespace json {
17
- function fromString(data: string): JSONValue {
17
+ export function fromString(data: string): JSONValue {
18
18
  let bytes = Bytes.fromUTF8(data)
19
19
 
20
20
  return json.fromBytes(bytes)
21
21
  }
22
22
 
23
- function try_fromString(data: string): Result<JSONValue, boolean> {
23
+ export function try_fromString(data: string): Result<JSONValue, boolean> {
24
24
  let bytes = Bytes.fromUTF8(data)
25
25
 
26
26
  return json.try_fromBytes(bytes)
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-ts",
3
3
  "description": "TypeScript/AssemblyScript library for writing subgraph mappings for The Graph",
4
- "version": "0.23.1",
4
+ "version": "0.24.0",
5
5
  "module": "index.ts",
6
6
  "types": "index.ts",
7
7
  "main": "index.ts",
@@ -9,16 +9,11 @@
9
9
  "assemblyscript": "0.19.10"
10
10
  },
11
11
  "devDependencies": {
12
- "glob": "^7.1.2",
13
12
  "prettier": "^2.4.1"
14
13
  },
15
14
  "scripts": {
16
15
  "lint": "prettier -c **/*.{js,ts}",
17
16
  "build": "asc --explicitStart --exportRuntime --runtime stub index.ts helper-functions.ts --lib graph-ts -b index.wasm",
18
- "test": "node test/test.js",
19
- "release:patch": "npm version patch && npm publish && git push origin master && git push --tags",
20
- "release:minor": "npm version minor && npm publish && git push origin master && git push --tags",
21
- "release:alpha:minor": "npm version preminor --preid alpha && npm publish --tag alpha && git push origin master && git push --tags",
22
- "release:alpha:prerelease": "npm version prerelease --preid alpha && npm publish --tag alpha && git push origin master && git push --tags"
17
+ "test": "node test/test.js"
23
18
  }
24
19
  }
@@ -9,7 +9,7 @@
9
9
  "deploy-test": "../../bin/graph deploy test/basic-event-handlers --version-label v0.0.1 --ipfs http://localhost:15001 --node http://127.0.0.1:18020"
10
10
  },
11
11
  "devDependencies": {
12
- "@graphprotocol/graph-ts": "0.24.0-alpha.0",
12
+ "@graphprotocol/graph-ts": "0.24.1",
13
13
  "apollo-fetch": "^0.7.0"
14
14
  },
15
15
  "dependencies": {
@@ -2,10 +2,10 @@
2
2
  # yarn lockfile v1
3
3
 
4
4
 
5
- "@graphprotocol/graph-ts@0.24.0-alpha.0":
6
- version "0.24.0-alpha.0"
7
- resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.24.0-alpha.0.tgz#8fe2b09a123adc5a65c82b823a1cb2d99f3cce2b"
8
- integrity sha512-PLhTMlFMoLZpTqJlKH5f+5VRN3yWmXfssVwWk7uauVeY8IuAWjWB3RNubS574q9uf0QjPKOacekXY5EKRWOzEA==
5
+ "@graphprotocol/graph-ts@0.24.1":
6
+ version "0.24.1"
7
+ resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.24.1.tgz#50961b52b5383f9c5cf5e6e23fa039f24e729ddf"
8
+ integrity sha512-2vU4m5ZPQIqMlMce/z5vmOtGHRlRmcRhMfemS3NIwxCSxSBGVnX2zb7QBTzzdQKGwsAZdbz6V0okkOtvohELfQ==
9
9
  dependencies:
10
10
  assemblyscript "0.19.10"
11
11
 
@@ -7,7 +7,7 @@
7
7
  "build-wast": "../../bin/graph build -t wast subgraph.yaml"
8
8
  },
9
9
  "devDependencies": {
10
- "@graphprotocol/graph-ts": "0.24.0-alpha.0"
10
+ "@graphprotocol/graph-ts": "0.24.1"
11
11
  },
12
12
  "resolutions": {
13
13
  "assemblyscript": "0.19.10"
@@ -2,10 +2,10 @@
2
2
  # yarn lockfile v1
3
3
 
4
4
 
5
- "@graphprotocol/graph-ts@0.24.0-alpha.0":
6
- version "0.24.0-alpha.0"
7
- resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.24.0-alpha.0.tgz#8fe2b09a123adc5a65c82b823a1cb2d99f3cce2b"
8
- integrity sha512-PLhTMlFMoLZpTqJlKH5f+5VRN3yWmXfssVwWk7uauVeY8IuAWjWB3RNubS574q9uf0QjPKOacekXY5EKRWOzEA==
5
+ "@graphprotocol/graph-ts@0.24.1":
6
+ version "0.24.1"
7
+ resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.24.1.tgz#50961b52b5383f9c5cf5e6e23fa039f24e729ddf"
8
+ integrity sha512-2vU4m5ZPQIqMlMce/z5vmOtGHRlRmcRhMfemS3NIwxCSxSBGVnX2zb7QBTzzdQKGwsAZdbz6V0okkOtvohELfQ==
9
9
  dependencies:
10
10
  assemblyscript "0.19.10"
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.24.0-alpha.0",
3
+ "version": "0.25.1",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "dependencies": {
6
6
  "assemblyscript": "0.19.10",
@@ -80,17 +80,24 @@ module.exports = class SchemaCodeGenerator {
80
80
  .map(field => {
81
81
  const name = field.getIn(['name', 'value'])
82
82
  const type = this._typeFromGraphQl(field.get('type'))
83
+
83
84
  const isNullable = type instanceof tsCodegen.NullableType
85
+ const isPrimitive = type.isPrimitive && type.isPrimitive()
84
86
 
85
87
  const directives = field.get('directives')
86
88
  const isDerivedFrom = directives.some(directive => directive.getIn(['name', 'value']) === 'derivedFrom')
87
89
 
88
- return { name, type, isNullable, isDerivedFrom }
90
+ return { name, type, isNullable, isPrimitive, isDerivedFrom }
89
91
  })
90
92
  // We only call the setter with the default value in the constructor for fields that are:
93
+ // - Not primitive (such as Int/i32)
91
94
  // - Not nullable, so that AS doesn't break when subgraph developers try to access them before a `set`
92
95
  // - Not tagged as `derivedFrom`, because they only exist in query time
93
- .filter(({ isNullable, isDerivedFrom }) => !isNullable && !isDerivedFrom)
96
+ .filter(({
97
+ isNullable,
98
+ isPrimitive,
99
+ isDerivedFrom,
100
+ }) => !(isNullable || isPrimitive || isDerivedFrom))
94
101
  .map(({ name, type, isNullable }) => {
95
102
  const fieldTypeString = isNullable ? type.inner.toString() : type.toString()
96
103
 
@@ -89,8 +89,12 @@ const findInitializationForType = (fromTypeSystem, toTypeSystem, ascType) => {
89
89
 
90
90
  // High-level type system API
91
91
 
92
+ const ascTypeForProtocol = (protocol, protocolType) =>
93
+ findConversionFromType(protocol, 'AssemblyScript', protocolType).getIn(['to', 'type'])
94
+
95
+ // TODO: this can be removed/replaced by the function above
92
96
  const ascTypeForEthereum = ethereumType =>
93
- findConversionFromType('ethereum', 'AssemblyScript', ethereumType).getIn(['to', 'type'])
97
+ ascTypeForProtocol('ethereum', ethereumType)
94
98
 
95
99
  const ethereumTypeForAsc = ascType =>
96
100
  findConversionFromType('AssemblyScript', 'ethereum', ascType).getIn(['to', 'type'])
@@ -120,6 +124,9 @@ const initializedValueFromAsc = ascType =>
120
124
  findInitializationForType('AssemblyScript', 'Value', ascType)
121
125
 
122
126
  module.exports = {
127
+ // protocol <-> AssemblyScript
128
+ ascTypeForProtocol,
129
+
123
130
  // ethereum <-> AssemblyScript
124
131
  ascTypeForEthereum,
125
132
  ethereumTypeForAsc,
@@ -0,0 +1,66 @@
1
+ const fs = require('fs-extra')
2
+ const path = require('path')
3
+
4
+ const { step } = require('./spinner')
5
+ const Scaffold = require('../scaffold')
6
+
7
+ const generateScaffold = async (
8
+ {
9
+ protocolInstance,
10
+ abi,
11
+ contract,
12
+ network,
13
+ subgraphName,
14
+ indexEvents,
15
+ contractName = 'Contract',
16
+ node,
17
+ },
18
+ spinner,
19
+ ) => {
20
+ step(spinner, 'Generate subgraph')
21
+
22
+ const scaffold = new Scaffold({
23
+ protocol: protocolInstance,
24
+ abi,
25
+ indexEvents,
26
+ contract,
27
+ network,
28
+ contractName,
29
+ subgraphName,
30
+ node,
31
+ })
32
+
33
+ return scaffold.generate()
34
+ }
35
+
36
+ const writeScaffoldDirectory = async (scaffold, directory, spinner) => {
37
+ // Create directory itself
38
+ await fs.mkdirs(directory)
39
+
40
+ let promises = Object.keys(scaffold).map(async basename => {
41
+ let content = scaffold[basename]
42
+ let filename = path.join(directory, basename)
43
+
44
+ // Write file or recurse into subdirectory
45
+ if (typeof content === 'string') {
46
+ await fs.writeFile(filename, content, { encoding: 'utf-8' })
47
+ } else if (content == null) {
48
+ return // continue loop
49
+ } else {
50
+ writeScaffoldDirectory(content, path.join(directory, basename), spinner)
51
+ }
52
+ })
53
+
54
+ await Promise.all(promises)
55
+ }
56
+
57
+ const writeScaffold = async (scaffold, directory, spinner) => {
58
+ step(spinner, `Write subgraph to directory`)
59
+ await writeScaffoldDirectory(scaffold, directory, spinner)
60
+ }
61
+
62
+ module.exports = {
63
+ ...module.exports,
64
+ generateScaffold,
65
+ writeScaffold,
66
+ }
@@ -57,7 +57,7 @@ const assertGraphTsVersion = async (sourceDir, minimumGraphTsVersion) => {
57
57
  if (graphTsVersion && semver.lt(semver.coerce(graphTsVersion), minimumGraphTsVersion)) {
58
58
  throw new Error(
59
59
  `To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
60
- Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://gist.github.com/otaviopace/8406cb39644d2e7678570d1e7f50dac4`
60
+ Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://thegraph.com/docs/developer/assemblyscript-migration-guide`
61
61
  )
62
62
  }
63
63
  }
@@ -197,7 +197,7 @@ describe('Version Command Helpers', () => {
197
197
  .rejects
198
198
  .toThrow(new Error(
199
199
  `To use this version of the graph-cli you must upgrade the graph-ts dependency to a version greater than or equal to ${minimumGraphTsVersion}
200
- Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://gist.github.com/otaviopace/8406cb39644d2e7678570d1e7f50dac4`
200
+ Also, you'll probably need to take a look at our AssemblyScript migration guide because of language breaking changes: https://thegraph.com/docs/developer/assemblyscript-migration-guide`
201
201
  ))
202
202
  })
203
203
  test('When the installed graph-ts version is a supported one', async () => {