Skip to content

Commit 0fe7662

Browse files
authored
Float subgraph uncrashable integration as a package (#987)
* Float subgraph uncrashable integration as a package * review changes * Update to latest package * final latest version for integration
1 parent b16fa66 commit 0fe7662

File tree

4 files changed

+105
-9
lines changed

4 files changed

+105
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"debug": "4.3.1",
1212
"docker-compose": "0.23.4",
1313
"dockerode": "2.5.8",
14+
"@float-capital/float-subgraph-uncrashable": "^0.0.0-alpha.4",
1415
"fs-extra": "9.0.0",
1516
"glob": "7.1.6",
1617
"gluegun": "https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep",

src/commands/codegen.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ const TypeGenerator = require('../type-generator')
55
const Protocol = require('../protocols')
66
const { fixParameters } = require('../command-helpers/gluegun')
77
const DataSourcesExtractor = require('../command-helpers/data-sources')
8-
const { assertManifestApiVersion, assertGraphTsVersion } = require('../command-helpers/version')
8+
const {
9+
assertManifestApiVersion,
10+
assertGraphTsVersion,
11+
} = require('../command-helpers/version')
912

1013
const HELP = `
1114
${chalk.bold('graph codegen')} [options] ${chalk.bold('[<subgraph-manifest>]')}
12-
1315
Options:
14-
1516
-h, --help Show usage information
1617
-o, --output-dir <path> Output directory for generated types (default: generated/)
17-
--skip-migrations Skip subgraph migrations (default: false)
18+
--skip-migrations Skip subgraph migrations (default: false)
1819
-w, --watch Regenerate types when subgraph files change (default: false)
19-
`
20+
-u, --uncrashable Generate Float Subgraph Uncrashable helper file
21+
-uc, --uncrashable-config <path> Directory for uncrashable config (default: ./uncrashable-config.yaml)
22+
`
2023

2124
module.exports = {
2225
description: 'Generates AssemblyScript types for a subgraph',
@@ -25,12 +28,26 @@ module.exports = {
2528
let { filesystem, print, system } = toolbox
2629

2730
// Read CLI parameters
28-
let { h, help, o, outputDir, skipMigrations, w, watch } = toolbox.parameters.options
31+
let {
32+
h,
33+
help,
34+
o,
35+
outputDir,
36+
skipMigrations,
37+
w,
38+
watch,
39+
u,
40+
uncrashable,
41+
uc,
42+
uncrashableConfig,
43+
} = toolbox.parameters.options
2944

3045
// Support both long and short option variants
3146
help = help || h
3247
outputDir = outputDir || o
3348
watch = watch || w
49+
uncrashable = uncrashable || u
50+
uncrashable_config = uncrashableConfig || uc
3451

3552
let manifest
3653
try {
@@ -39,6 +56,8 @@ module.exports = {
3956
help,
4057
w,
4158
watch,
59+
u,
60+
uncrashable,
4261
})
4362
} catch (e) {
4463
print.error(e.message)
@@ -56,6 +75,11 @@ module.exports = {
5675
? manifest
5776
: filesystem.resolve('subgraph.yaml')
5877

78+
uncrashable_config =
79+
uncrashable_config !== undefined && uncrashable_config !== ''
80+
? uncrashable_config
81+
: filesystem.resolve('uncrashable-config.yaml')
82+
5983
// Show help text if requested
6084
if (help) {
6185
print.info(HELP)
@@ -87,6 +111,8 @@ module.exports = {
87111
outputDir: outputDir,
88112
skipMigrations,
89113
protocol,
114+
uncrashable,
115+
uncrashableConfig: uncrashable_config,
90116
})
91117

92118
// Watch working directory for file updates or additions, trigger

src/type-generator.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const { step, withSpinner } = require('./command-helpers/spinner')
1414
const { applyMigrations } = require('./migrations')
1515
const { GENERATED_FILE_NOTE } = require('./codegen/typescript')
1616
const { displayPath } = require('./command-helpers/fs')
17+
const uncrashable = require('../node_modules/@float-capital/float-subgraph-uncrashable/src/Index.bs.js')
1718

1819
module.exports = class TypeGenerator {
1920
constructor(options) {
@@ -53,20 +54,48 @@ module.exports = class TypeGenerator {
5354

5455
// Not all protocols support/have ABIs.
5556
if (this.protocol.hasABIs()) {
56-
const templateAbis = await this.protocolTypeGenerator.loadDataSourceTemplateABIs(subgraph)
57-
await this.protocolTypeGenerator.generateTypesForDataSourceTemplateABIs(templateAbis)
57+
const templateAbis = await this.protocolTypeGenerator.loadDataSourceTemplateABIs(
58+
subgraph,
59+
)
60+
await this.protocolTypeGenerator.generateTypesForDataSourceTemplateABIs(
61+
templateAbis,
62+
)
5863
}
5964

6065
let schema = await this.loadSchema(subgraph)
6166
await this.generateTypesForSchema(schema)
6267

6368
toolbox.print.success('\nTypes generated successfully\n')
69+
70+
if (this.options.uncrashable && this.options.uncrashableConfig) {
71+
await this.generateUncrashableEntities(schema)
72+
toolbox.print.success('\nUncrashable Helpers generated successfully\n')
73+
}
6474
return true
6575
} catch (e) {
6676
return false
6777
}
6878
}
6979

80+
async generateUncrashableEntities(graphSchema) {
81+
let ast = graphql.parse(graphSchema.document)
82+
let entityDefinitions = ast['definitions']
83+
return await withSpinner(
84+
`Generate Uncrashable Entity Helpers`,
85+
`Failed to generate Uncrashable Entity Helpers`,
86+
`Warnings while generating Uncrashable Entity Helpers`,
87+
async spinner => {
88+
uncrashable.run(
89+
entityDefinitions,
90+
this.options.uncrashableConfig,
91+
this.options.outputDir,
92+
)
93+
let outputFile = path.join(this.options.outputDir, 'UncrashableEntityHelpers.ts')
94+
step(spinner, 'Save uncrashable entities to', displayPath(outputFile))
95+
},
96+
)
97+
}
98+
7099
async loadSubgraph({ quiet } = { quiet: false }) {
71100
const subgraphLoadOptions = { protocol: this.protocol, skipValidation: false }
72101

@@ -148,7 +177,10 @@ module.exports = class TypeGenerator {
148177
`${template.get('name')}`,
149178
)
150179

151-
let codeGenerator = new DataSourceTemplateCodeGenerator(template, this.protocol)
180+
let codeGenerator = new DataSourceTemplateCodeGenerator(
181+
template,
182+
this.protocol,
183+
)
152184

153185
// Only generate module imports once, because they are identical for
154186
// all types generated for data source templates.

yarn.lock

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,16 @@
478478
"@ethersproject/properties" "^5.5.0"
479479
"@ethersproject/strings" "^5.5.0"
480480

481+
"@float-capital/float-subgraph-uncrashable@^0.0.0-alpha.4":
482+
version "0.0.0-alpha.4"
483+
resolved "https://registry.yarnpkg.com/@float-capital/float-subgraph-uncrashable/-/float-subgraph-uncrashable-0.0.0-alpha.4.tgz#0605d10aa97e1ba7d26cc095afb23eda9ffdfb37"
484+
integrity sha512-3DPy66rMvGAFDDv7craf/Vgz1fLfuU0QSJ16HB1CRZyFQFqICFHbDL7h04zqG8i255z8cfBcgYq+zSxVzeEyLw==
485+
dependencies:
486+
graphql "^16.6.0"
487+
graphql-import-node "^0.0.5"
488+
js-yaml "^4.1.0"
489+
rescript "^9.1.4"
490+
481491
"@istanbuljs/load-nyc-config@^1.0.0":
482492
version "1.0.0"
483493
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.0.0.tgz#10602de5570baea82f8afbfa2630b24e7a8cfe5b"
@@ -1024,6 +1034,11 @@ argparse@^1.0.7:
10241034
dependencies:
10251035
sprintf-js "~1.0.2"
10261036

1037+
argparse@^2.0.1:
1038+
version "2.0.1"
1039+
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
1040+
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
1041+
10271042
arr-diff@^4.0.0:
10281043
version "4.0.0"
10291044
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520"
@@ -2746,11 +2761,21 @@ graceful-fs@^4.2.4:
27462761
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
27472762
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
27482763

2764+
graphql-import-node@^0.0.5:
2765+
version "0.0.5"
2766+
resolved "https://registry.yarnpkg.com/graphql-import-node/-/graphql-import-node-0.0.5.tgz#caf76a6cece10858b14f27cce935655398fc1bf0"
2767+
integrity sha512-OXbou9fqh9/Lm7vwXT0XoRN9J5+WCYKnbiTalgFDvkQERITRmcfncZs6aVABedd5B85yQU5EULS4a5pnbpuI0Q==
2768+
27492769
27502770
version "15.5.0"
27512771
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.5.0.tgz#39d19494dbe69d1ea719915b578bf920344a69d5"
27522772
integrity sha512-OmaM7y0kaK31NKG31q4YbD2beNYa6jBBKtMFT6gLYJljHLJr42IqJ8KX08u3Li/0ifzTU5HjmoOOrwa5BRLeDA==
27532773

2774+
graphql@^16.6.0:
2775+
version "16.6.0"
2776+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.6.0.tgz#c2dcffa4649db149f6282af726c8c83f1c7c5fdb"
2777+
integrity sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw==
2778+
27542779
growly@^1.3.0:
27552780
version "1.3.0"
27562781
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
@@ -3833,6 +3858,13 @@ [email protected], js-yaml@^3.13.1:
38333858
argparse "^1.0.7"
38343859
esprima "^4.0.0"
38353860

3861+
js-yaml@^4.1.0:
3862+
version "4.1.0"
3863+
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
3864+
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
3865+
dependencies:
3866+
argparse "^2.0.1"
3867+
38363868
jsbn@~0.1.0:
38373869
version "0.1.1"
38383870
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
@@ -5218,6 +5250,11 @@ require-main-filename@^2.0.0:
52185250
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
52195251
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
52205252

5253+
rescript@^9.1.4:
5254+
version "9.1.4"
5255+
resolved "https://registry.yarnpkg.com/rescript/-/rescript-9.1.4.tgz#1eb126f98d6c16942c0bf0df67c050198e580515"
5256+
integrity sha512-aXANK4IqecJzdnDpJUsU6pxMViCR5ogAxzuqS0mOr8TloMnzAjJFu63fjD6LCkWrKAhlMkFFzQvVQYaAaVkFXw==
5257+
52215258
resolve-cwd@^3.0.0:
52225259
version "3.0.0"
52235260
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d"

0 commit comments

Comments
 (0)