From b4ccb41ac629cbeca7f4e3679ad497c28aba4820 Mon Sep 17 00:00:00 2001 From: tilacog Date: Mon, 21 Mar 2022 20:13:00 -0300 Subject: [PATCH 1/6] Add `Boolean` scalar for the new `EventHandler.receipt` field --- src/protocols/ethereum/manifest.graphql | 2 ++ src/validation/manifest.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/protocols/ethereum/manifest.graphql b/src/protocols/ethereum/manifest.graphql index 59a697f88..dfb06c84d 100644 --- a/src/protocols/ethereum/manifest.graphql +++ b/src/protocols/ethereum/manifest.graphql @@ -7,6 +7,7 @@ scalar String scalar File scalar BigInt +scalar Boolean type SubgraphManifest { specVersion: String! @@ -72,6 +73,7 @@ type ContractEventHandler { event: String! topic0: String handler: String! + receipt: Boolean } type Graft { diff --git a/src/validation/manifest.js b/src/validation/manifest.js index ba7f3e691..e030d06fe 100644 --- a/src/validation/manifest.js +++ b/src/validation/manifest.js @@ -204,6 +204,18 @@ const validators = immutable.fromJS({ message: `Expected filename, found ${typeName(value)}:\n${value}`, }, ]), + + Boolean: (value, ctx) => + typeof value === 'boolean' + ? List() + : immutable.fromJS([ + { + path: ctx.get('path'), + message: `Expected true or false, found ${typeName(value)}:\n${toYAML( + value, + )}`, + }, + ]), }) const validateValue = (value, ctx) => { From 8b68073d8fb3368b02b6b93e7d3f919e9dbec2f5 Mon Sep 17 00:00:00 2001 From: tilacog Date: Wed, 23 Mar 2022 12:16:57 -0300 Subject: [PATCH 2/6] Update `graph-ts` version in `package.json` and scaffold Warning: We must also update the respective lockfiles as soon as the new `graph-ts` version is avaliable on external package registries. --- examples/basic-event-handlers/package.json | 2 +- examples/example-subgraph/package.json | 2 +- src/scaffold/index.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/basic-event-handlers/package.json b/examples/basic-event-handlers/package.json index e55cfcd4b..bda65523a 100644 --- a/examples/basic-event-handlers/package.json +++ b/examples/basic-event-handlers/package.json @@ -9,7 +9,7 @@ "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" }, "devDependencies": { - "@graphprotocol/graph-ts": "0.26.0", + "@graphprotocol/graph-ts": "0.27.0", "apollo-fetch": "^0.7.0" }, "dependencies": { diff --git a/examples/example-subgraph/package.json b/examples/example-subgraph/package.json index 6ffc8834e..870e39a32 100644 --- a/examples/example-subgraph/package.json +++ b/examples/example-subgraph/package.json @@ -7,7 +7,7 @@ "build-wast": "../../bin/graph build -t wast subgraph.yaml" }, "devDependencies": { - "@graphprotocol/graph-ts": "0.26.0" + "@graphprotocol/graph-ts": "0.27.0" }, "resolutions": { "assemblyscript": "0.19.10" diff --git a/src/scaffold/index.js b/src/scaffold/index.js index 7da29248c..0bbad6958 100644 --- a/src/scaffold/index.js +++ b/src/scaffold/index.js @@ -50,7 +50,7 @@ module.exports = class Scaffold { }, dependencies: { '@graphprotocol/graph-cli': GRAPH_CLI_VERSION, - '@graphprotocol/graph-ts': `0.26.0`, + '@graphprotocol/graph-ts': `0.27.0`, }, }), { parser: 'json' }, From 6b26186a43314b96b87d4794d2714a6f8ec6889d Mon Sep 17 00:00:00 2001 From: tilacog Date: Wed, 23 Mar 2022 21:00:50 -0300 Subject: [PATCH 3/6] migrations: `apiVersion 0.0.6` and `specVersion 0.0.5` Migrations for `specVersion 0.0.4` can be found in PR #724 https://github.com/graphprotocol/graph-cli/pull/724 --- src/migrations.js | 2 + src/migrations/mapping_api_version_0_0_6.js | 74 +++++++++++++++++++++ src/migrations/spec_version_0_0_4.js | 25 +++++++ 3 files changed, 101 insertions(+) create mode 100644 src/migrations/mapping_api_version_0_0_6.js create mode 100644 src/migrations/spec_version_0_0_4.js diff --git a/src/migrations.js b/src/migrations.js index eb79638d4..a1cd45405 100644 --- a/src/migrations.js +++ b/src/migrations.js @@ -5,7 +5,9 @@ const MIGRATIONS = [ require('./migrations/mapping_api_version_0_0_2'), require('./migrations/mapping_api_version_0_0_3'), require('./migrations/mapping_api_version_0_0_4'), + require('./migrations/mapping_api_version_0_0_5'), require('./migrations/spec_version_0_0_2'), + require('./migrations/spec_version_0_0_4'), ] const applyMigrations = async options => diff --git a/src/migrations/mapping_api_version_0_0_6.js b/src/migrations/mapping_api_version_0_0_6.js new file mode 100644 index 000000000..b2a031367 --- /dev/null +++ b/src/migrations/mapping_api_version_0_0_6.js @@ -0,0 +1,74 @@ +const fs = require('fs-extra') +const semver = require('semver') +const toolbox = require('gluegun/toolbox') +const yaml = require('js-yaml') +const { loadManifest } = require('./util/load-manifest') +const { getGraphTsVersion } = require('./util/versions') + +// If any of the manifest apiVersions are 0.0.6, replace them with 0.0.7 +module.exports = { + name: 'Bump mapping apiVersion from 0.0.6 to 0.0.7', + predicate: async ({ sourceDir, manifestFile }) => { + // Obtain the graph-ts version, if possible + let graphTsVersion + try { + graphTsVersion = await getGraphTsVersion(sourceDir) + } catch (_) { + // If we cannot obtain the version, return a hint that the graph-ts + // hasn't been installed yet + return 'graph-ts dependency not installed yet' + } + + let manifest = loadManifest(manifestFile) + return ( + // Only migrate if the graph-ts version is >= 0.24.0... + // Coerce needed because we may be dealing with an alpha version + // and in the `semver` library this would not return true on equality. + semver.gte(semver.coerce(graphTsVersion), '0.27.0') && + // ...and we have a manifest with mapping > apiVersion = 0.0.6 + manifest && + typeof manifest === 'object' && + Array.isArray(manifest.dataSources) && + (manifest.dataSources.reduce( + (hasOldMappings, dataSource) => + hasOldMappings || + (typeof dataSource === 'object' && + dataSource.mapping && + typeof dataSource.mapping === 'object' && + dataSource.mapping.apiVersion === '0.0.6'), + false, + ) || + (Array.isArray(manifest.templates) && + manifest.templates.reduce( + (hasOldMappings, template) => + hasOldMappings || + (typeof template === 'object' && + template.mapping && + typeof template.mapping === 'object' && + template.mapping.apiVersion === '0.0.6'), + false, + ))) + ) + }, + apply: async ({ manifestFile }) => { + // Make sure we catch all variants; we could load the manifest + // and replace the values in the data structures here; unfortunately + // writing that back to the file messes with the formatting more than + // we'd like; that's why for now, we use a simple patching approach + await toolbox.patching.replace( + manifestFile, + new RegExp('apiVersion: 0.0.6', 'g'), + 'apiVersion: 0.0.7', + ) + await toolbox.patching.replace( + manifestFile, + new RegExp("apiVersion: '0.0.6'", 'g'), + "apiVersion: '0.0.7'", + ) + await toolbox.patching.replace( + manifestFile, + new RegExp('apiVersion: "0.0.6"', 'g'), + 'apiVersion: "0.0.7"', + ) + }, +} diff --git a/src/migrations/spec_version_0_0_4.js b/src/migrations/spec_version_0_0_4.js new file mode 100644 index 000000000..cb700e99d --- /dev/null +++ b/src/migrations/spec_version_0_0_4.js @@ -0,0 +1,25 @@ +const fs = require('fs-extra') +const toolbox = require('gluegun/toolbox') +const yaml = require('js-yaml') +const { loadManifest } = require('./util/load-manifest') + +// Spec version 0.0.5 let event handlers require transaction receipt +// data to be accessed in the runtime. +module.exports = { + name: 'Bump manifest specVersion from 0.0.4 to 0.0.5', + predicate: async ({ sourceDir, manifestFile }) => { + let manifest = await loadManifest(manifestFile) + return ( + manifest && + typeof manifest === 'object' && + manifest.specVersion && + manifest.specVersion === '0.0.4' + ) + }, + apply: async ({ manifestFile }) => { + await toolbox.patching.patch(manifestFile, { + insert: 'specVersion: 0.0.5', + replace: new RegExp(`specVersion: ['"]?0.0.4['"]?`), + }) + }, +} From 6d57b47c89b603d3057c498719dc2ce6b1b5fed3 Mon Sep 17 00:00:00 2001 From: tilacog Date: Tue, 29 Mar 2022 20:13:59 -0300 Subject: [PATCH 4/6] migrations: Fix wrong version numbers in comments --- src/migrations/mapping_api_version_0_0_5.js | 2 +- src/migrations/mapping_api_version_0_0_6.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/migrations/mapping_api_version_0_0_5.js b/src/migrations/mapping_api_version_0_0_5.js index 6b6a836c0..2ad084b31 100644 --- a/src/migrations/mapping_api_version_0_0_5.js +++ b/src/migrations/mapping_api_version_0_0_5.js @@ -21,7 +21,7 @@ module.exports = { let manifest = loadManifest(manifestFile) return ( - // Only migrate if the graph-ts version is >= 0.23.0... + // Only migrate if the graph-ts version is >= 0.24.0... // Coerce needed because we may be dealing with an alpha version // and in the `semver` library this would not return true on equality. semver.gte(semver.coerce(graphTsVersion), '0.24.0') && diff --git a/src/migrations/mapping_api_version_0_0_6.js b/src/migrations/mapping_api_version_0_0_6.js index b2a031367..76fc90142 100644 --- a/src/migrations/mapping_api_version_0_0_6.js +++ b/src/migrations/mapping_api_version_0_0_6.js @@ -21,7 +21,7 @@ module.exports = { let manifest = loadManifest(manifestFile) return ( - // Only migrate if the graph-ts version is >= 0.24.0... + // Only migrate if the graph-ts version is >= 0.27.0... // Coerce needed because we may be dealing with an alpha version // and in the `semver` library this would not return true on equality. semver.gte(semver.coerce(graphTsVersion), '0.27.0') && From 28b69f2b0496c9625afb7b2e9f225d73ee80e83c Mon Sep 17 00:00:00 2001 From: tilacog Date: Wed, 30 Mar 2022 20:34:13 -0300 Subject: [PATCH 5/6] 0.30.0-alpha.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0586c1402..109404e76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@graphprotocol/graph-cli", - "version": "0.29.0", + "version": "0.30.0-alpha.0", "license": "(Apache-2.0 OR MIT)", "description": "CLI for building for and deploying to The Graph", "dependencies": { From c9169b1ef2b91c76fc6ec1e895f5642227b4a12a Mon Sep 17 00:00:00 2001 From: tilacog Date: Thu, 31 Mar 2022 12:41:13 -0300 Subject: [PATCH 6/6] Bump `graph-ts` version to 0.27.0-alpha.0 --- examples/basic-event-handlers/package.json | 2 +- examples/basic-event-handlers/yarn.lock | 8 ++++---- examples/example-subgraph/package.json | 2 +- examples/example-subgraph/yarn.lock | 8 ++++---- src/scaffold/index.js | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/basic-event-handlers/package.json b/examples/basic-event-handlers/package.json index bda65523a..2247da9d6 100644 --- a/examples/basic-event-handlers/package.json +++ b/examples/basic-event-handlers/package.json @@ -9,7 +9,7 @@ "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" }, "devDependencies": { - "@graphprotocol/graph-ts": "0.27.0", + "@graphprotocol/graph-ts": "0.27.0-alpha.0", "apollo-fetch": "^0.7.0" }, "dependencies": { diff --git a/examples/basic-event-handlers/yarn.lock b/examples/basic-event-handlers/yarn.lock index f19421e5f..da787cc66 100644 --- a/examples/basic-event-handlers/yarn.lock +++ b/examples/basic-event-handlers/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@graphprotocol/graph-ts@0.26.0": - version "0.26.0" - resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.26.0.tgz#576f995531eebaca4374901aeaff499219e382e8" - integrity sha512-GW/emOJl+35MXgmIxTnUK7dJtPCaB9u5aAwoLVqJ8swogC794O92UrXMVrAJsherUriu+yI9bLMGmNPOIi60jw== +"@graphprotocol/graph-ts@0.27.0-alpha.0": + version "0.27.0-alpha.0" + resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.27.0-alpha.0.tgz#1d50fc3fe7e574b09f206d60a5d9889d5e95beba" + integrity sha512-aS1VQUgj3dSvodDMJSBoyYfHjBA8UsUc/JUIrz+R5DjpxFx7wq5yzzB6GGlwEhuBV93UEh4UdmRDPWT/SKD5sg== dependencies: assemblyscript "0.19.10" diff --git a/examples/example-subgraph/package.json b/examples/example-subgraph/package.json index 870e39a32..e9b857894 100644 --- a/examples/example-subgraph/package.json +++ b/examples/example-subgraph/package.json @@ -7,7 +7,7 @@ "build-wast": "../../bin/graph build -t wast subgraph.yaml" }, "devDependencies": { - "@graphprotocol/graph-ts": "0.27.0" + "@graphprotocol/graph-ts": "0.27.0-alpha.0" }, "resolutions": { "assemblyscript": "0.19.10" diff --git a/examples/example-subgraph/yarn.lock b/examples/example-subgraph/yarn.lock index 577384d0c..8dd917d3b 100644 --- a/examples/example-subgraph/yarn.lock +++ b/examples/example-subgraph/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@graphprotocol/graph-ts@0.26.0": - version "0.26.0" - resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.26.0.tgz#576f995531eebaca4374901aeaff499219e382e8" - integrity sha512-GW/emOJl+35MXgmIxTnUK7dJtPCaB9u5aAwoLVqJ8swogC794O92UrXMVrAJsherUriu+yI9bLMGmNPOIi60jw== +"@graphprotocol/graph-ts@0.27.0-alpha.0": + version "0.27.0-alpha.0" + resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.27.0-alpha.0.tgz#1d50fc3fe7e574b09f206d60a5d9889d5e95beba" + integrity sha512-aS1VQUgj3dSvodDMJSBoyYfHjBA8UsUc/JUIrz+R5DjpxFx7wq5yzzB6GGlwEhuBV93UEh4UdmRDPWT/SKD5sg== dependencies: assemblyscript "0.19.10" diff --git a/src/scaffold/index.js b/src/scaffold/index.js index 0bbad6958..6cb54d90f 100644 --- a/src/scaffold/index.js +++ b/src/scaffold/index.js @@ -50,7 +50,7 @@ module.exports = class Scaffold { }, dependencies: { '@graphprotocol/graph-cli': GRAPH_CLI_VERSION, - '@graphprotocol/graph-ts': `0.27.0`, + '@graphprotocol/graph-ts': `0.27.0-alpha.0`, }, }), { parser: 'json' },