@graphprotocol/graph-cli 0.37.3 → 0.37.4

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 (267) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +5 -1
  3. package/babel.config.js +0 -3
  4. package/jest.config.js +0 -175
  5. package/src/bin.ts +0 -6
  6. package/src/cli.ts +0 -30
  7. package/src/codegen/schema.test.ts +0 -460
  8. package/src/codegen/schema.ts +0 -299
  9. package/src/codegen/template.ts +0 -45
  10. package/src/codegen/types/conversions.ts +0 -358
  11. package/src/codegen/types/index.test.ts +0 -715
  12. package/src/codegen/types/index.ts +0 -111
  13. package/src/codegen/typescript.ts +0 -224
  14. package/src/codegen/util.test.ts +0 -112
  15. package/src/codegen/util.ts +0 -54
  16. package/src/command-helpers/abi.ts +0 -99
  17. package/src/command-helpers/auth.ts +0 -46
  18. package/src/command-helpers/compiler.ts +0 -60
  19. package/src/command-helpers/data-sources.ts +0 -36
  20. package/src/command-helpers/fs.ts +0 -5
  21. package/src/command-helpers/gluegun.ts +0 -52
  22. package/src/command-helpers/ipfs-http-client.d.ts +0 -1
  23. package/src/command-helpers/ipfs.ts +0 -3
  24. package/src/command-helpers/jsonrpc.ts +0 -22
  25. package/src/command-helpers/network.test.ts +0 -85
  26. package/src/command-helpers/network.ts +0 -133
  27. package/src/command-helpers/node.ts +0 -46
  28. package/src/command-helpers/scaffold.ts +0 -174
  29. package/src/command-helpers/spinner.ts +0 -60
  30. package/src/command-helpers/studio.test.ts +0 -84
  31. package/src/command-helpers/studio.ts +0 -25
  32. package/src/command-helpers/subgraph.ts +0 -21
  33. package/src/command-helpers/version.test.ts +0 -241
  34. package/src/command-helpers/version.ts +0 -53
  35. package/src/commands/add.ts +0 -220
  36. package/src/commands/auth.ts +0 -138
  37. package/src/commands/binary-install-raw.d.ts +0 -1
  38. package/src/commands/build.ts +0 -147
  39. package/src/commands/codegen.ts +0 -123
  40. package/src/commands/create.ts +0 -109
  41. package/src/commands/deploy.ts +0 -388
  42. package/src/commands/init.ts +0 -1060
  43. package/src/commands/local.ts +0 -539
  44. package/src/commands/remove.ts +0 -110
  45. package/src/commands/test.ts +0 -369
  46. package/src/compiler/asc.ts +0 -77
  47. package/src/compiler/index.ts +0 -677
  48. package/src/debug.ts +0 -15
  49. package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
  50. package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
  51. package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
  52. package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
  53. package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
  54. package/src/migrations/spec_version_0_0_2.ts +0 -24
  55. package/src/migrations/spec_version_0_0_3.ts +0 -29
  56. package/src/migrations/util/load-manifest.ts +0 -10
  57. package/src/migrations/util/versions.ts +0 -27
  58. package/src/migrations.ts +0 -33
  59. package/src/protocols/arweave/manifest.graphql +0 -57
  60. package/src/protocols/arweave/scaffold/manifest.ts +0 -14
  61. package/src/protocols/arweave/scaffold/mapping.ts +0 -49
  62. package/src/protocols/arweave/subgraph.ts +0 -22
  63. package/src/protocols/contract.ts +0 -9
  64. package/src/protocols/cosmos/manifest.graphql +0 -76
  65. package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
  66. package/src/protocols/cosmos/scaffold/mapping.ts +0 -35
  67. package/src/protocols/cosmos/subgraph.ts +0 -27
  68. package/src/protocols/ethereum/abi.ts +0 -153
  69. package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
  70. package/src/protocols/ethereum/codegen/abi.ts +0 -719
  71. package/src/protocols/ethereum/codegen/template.ts +0 -41
  72. package/src/protocols/ethereum/contract.ts +0 -24
  73. package/src/protocols/ethereum/manifest.graphql +0 -94
  74. package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
  75. package/src/protocols/ethereum/scaffold/mapping.ts +0 -76
  76. package/src/protocols/ethereum/subgraph.ts +0 -189
  77. package/src/protocols/ethereum/type-generator.ts +0 -191
  78. package/src/protocols/index.ts +0 -287
  79. package/src/protocols/ipfs/codegen/file_template.ts +0 -43
  80. package/src/protocols/near/contract.ts +0 -47
  81. package/src/protocols/near/manifest.graphql +0 -64
  82. package/src/protocols/near/scaffold/manifest.ts +0 -13
  83. package/src/protocols/near/scaffold/mapping.ts +0 -35
  84. package/src/protocols/near/subgraph.ts +0 -22
  85. package/src/protocols/subgraph.ts +0 -12
  86. package/src/protocols/substreams/manifest.graphql +0 -45
  87. package/src/protocols/substreams/scaffold/manifest.ts +0 -8
  88. package/src/protocols/substreams/subgraph.ts +0 -22
  89. package/src/scaffold/cosmos.test.ts +0 -83
  90. package/src/scaffold/ethereum.test.ts +0 -512
  91. package/src/scaffold/index.ts +0 -172
  92. package/src/scaffold/mapping.ts +0 -44
  93. package/src/scaffold/near.test.ts +0 -86
  94. package/src/scaffold/schema.ts +0 -89
  95. package/src/scaffold/tests.ts +0 -217
  96. package/src/schema.ts +0 -26
  97. package/src/subgraph.ts +0 -302
  98. package/src/type-generator.ts +0 -266
  99. package/src/validation/contract.ts +0 -51
  100. package/src/validation/index.ts +0 -5
  101. package/src/validation/manifest.ts +0 -360
  102. package/src/validation/schema.test.ts +0 -38
  103. package/src/validation/schema.ts +0 -957
  104. package/src/watcher.ts +0 -96
  105. package/tests/cli/globalSetup.ts +0 -8
  106. package/tests/cli/globalTeardown.ts +0 -8
  107. package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
  108. package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
  109. package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
  110. package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
  111. package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
  112. package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
  113. package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
  114. package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
  115. package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
  116. package/tests/cli/init/ethereum/from-contract.stderr +0 -16
  117. package/tests/cli/init/ethereum/from-contract.stdout +0 -12
  118. package/tests/cli/init/ethereum/from-example.stderr +0 -12
  119. package/tests/cli/init/ethereum/from-example.stdout +0 -12
  120. package/tests/cli/init/near/from-contract.stderr +0 -14
  121. package/tests/cli/init/near/from-contract.stdout +0 -12
  122. package/tests/cli/init.test.ts +0 -157
  123. package/tests/cli/spawn-command.d.ts +0 -7
  124. package/tests/cli/util.ts +0 -132
  125. package/tests/cli/validation/abi-not-found/Abi.json +0 -7
  126. package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
  127. package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
  128. package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
  129. package/tests/cli/validation/abi-not-found copy.stderr +0 -13
  130. package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
  131. package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
  132. package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
  133. package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
  134. package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
  135. package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
  136. package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
  137. package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
  138. package/tests/cli/validation/call-function-not-found.stderr +0 -10
  139. package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
  140. package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
  141. package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
  142. package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
  143. package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
  144. package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
  145. package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
  146. package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
  147. package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
  148. package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
  149. package/tests/cli/validation/conflicting-network-names.stderr +0 -10
  150. package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
  151. package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
  152. package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
  153. package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
  154. package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
  155. package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
  156. package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
  157. package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
  158. package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
  159. package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
  160. package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
  161. package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
  162. package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
  163. package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
  164. package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
  165. package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
  166. package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
  167. package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
  168. package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
  169. package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
  170. package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
  171. package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
  172. package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
  173. package/tests/cli/validation/duplicate-template-name.stderr +0 -5
  174. package/tests/cli/validation/entity-field-args/Abi.json +0 -7
  175. package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
  176. package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
  177. package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
  178. package/tests/cli/validation/entity-field-args.stderr +0 -5
  179. package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
  180. package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
  181. package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
  182. package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
  183. package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
  184. package/tests/cli/validation/event-not-found/Abi.json +0 -7
  185. package/tests/cli/validation/event-not-found/mapping.ts +0 -0
  186. package/tests/cli/validation/event-not-found/schema.graphql +0 -3
  187. package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
  188. package/tests/cli/validation/event-not-found.stderr +0 -12
  189. package/tests/cli/validation/example-values-found/Abi.json +0 -7
  190. package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
  191. package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
  192. package/tests/cli/validation/example-values-found/mapping.ts +0 -0
  193. package/tests/cli/validation/example-values-found/schema.graphql +0 -3
  194. package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
  195. package/tests/cli/validation/example-values-found.stderr +0 -34
  196. package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
  197. package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
  198. package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
  199. package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
  200. package/tests/cli/validation/invalid-abis.stderr +0 -5
  201. package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
  202. package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
  203. package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
  204. package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
  205. package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
  206. package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
  207. package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
  208. package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
  209. package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
  210. package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
  211. package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
  212. package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
  213. package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
  214. package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
  215. package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
  216. package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
  217. package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
  218. package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
  219. package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
  220. package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
  221. package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
  222. package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
  223. package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
  224. package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
  225. package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
  226. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
  227. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
  228. package/tests/cli/validation/invalid-manifest.stderr +0 -28
  229. package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
  230. package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
  231. package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
  232. package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
  233. package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
  234. package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
  235. package/tests/cli/validation/missing-entity-id.stderr +0 -5
  236. package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
  237. package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
  238. package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
  239. package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
  240. package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
  241. package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
  242. package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
  243. package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
  244. package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
  245. package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
  246. package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
  247. package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
  248. package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
  249. package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
  250. package/tests/cli/validation/no-network-names/Abi.json +0 -7
  251. package/tests/cli/validation/no-network-names/mapping.ts +0 -0
  252. package/tests/cli/validation/no-network-names/schema.graphql +0 -3
  253. package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
  254. package/tests/cli/validation/no-network-names.stderr +0 -34
  255. package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
  256. package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
  257. package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
  258. package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
  259. package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
  260. package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
  261. package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
  262. package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
  263. package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
  264. package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
  265. package/tests/cli/validation.test.ts +0 -226
  266. package/tsconfig.build.json +0 -4
  267. package/tsconfig.json +0 -19
@@ -1,36 +0,0 @@
1
- import immutable from 'immutable';
2
- import { loadManifest } from '../migrations/util/load-manifest';
3
- import Protocol from '../protocols';
4
-
5
- // Loads manifest from file path and returns all:
6
- // - data sources
7
- // - templates
8
- // In a single list.
9
- export const fromFilePath = async (manifestPath: string) => {
10
- const { dataSources = [], templates = [] } = await loadManifest(manifestPath);
11
-
12
- return dataSources.concat(templates);
13
- };
14
-
15
- const extractDataSourceByType = (
16
- manifest: immutable.Map<any, any>,
17
- dataSourceType: string,
18
- protocol: Protocol,
19
- ) =>
20
- manifest
21
- .get(dataSourceType, immutable.List())
22
- .reduce(
23
- (dataSources: any[], dataSource: any, dataSourceIndex: number) =>
24
- protocol.isValidKindName(dataSource.get('kind'))
25
- ? dataSources.push(immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }))
26
- : dataSources,
27
- immutable.List(),
28
- );
29
-
30
- // Extracts data sources and templates from a immutable manifest data structure
31
- export const fromManifest = (manifest: immutable.Map<any, any>, protocol: Protocol) => {
32
- const dataSources = extractDataSourceByType(manifest, 'dataSources', protocol);
33
- const templates = extractDataSourceByType(manifest, 'templates', protocol);
34
-
35
- return dataSources.concat(templates);
36
- };
@@ -1,5 +0,0 @@
1
- import path from 'path';
2
-
3
- const displayPath = (p: string) => path.relative(process.cwd(), p);
4
-
5
- export { displayPath };
@@ -1,52 +0,0 @@
1
- // Workaround for https://github.com/infinitered/gluegun/pull/464.
2
- //
3
- // There is currently no way in Gluegun to define command-line options
4
- // that take no arguments (like `--watch`). As a consequence, boolean
5
- // options like `--watch` will consume the immediately following argument,
6
- // leading to confusing behavior.
7
- //
8
- // E.g. `graph deploy --watch subgraph/name
9
- //
10
- // Will result in
11
- // ```
12
- // toolbox.parameters.options === { watch: 'subgraph/name' }
13
- // toolbox.parameters.first === undefined
14
- // toolbox.parameters.array === []
15
- // ```
16
- // where what we really want is
17
- // ```
18
- // toolbox.parameters.options === { watch: true }
19
- // toolbox.parameters.first = 'subgraph/name'
20
- // toolbox.parameters.array = ['subgraph/name']
21
- // ```
22
- //
23
- // The `fixParameters` function checks if any of the provided boolean
24
- // options has a string value; if so, it pushes it to the front of the
25
- // parameters array and returns the result of that.
26
-
27
- import { GluegunParameters } from 'gluegun';
28
-
29
- export const fixParameters = (
30
- parameters: GluegunParameters,
31
- booleanOptions: Record<string, string>,
32
- ) => {
33
- const unexpectedStringOptions = Object.keys(booleanOptions)
34
- .filter(key => typeof booleanOptions[key] === 'string')
35
- .map(key => ({ key, value: booleanOptions[key] }));
36
-
37
- const optionNames = unexpectedStringOptions
38
- .map(({ key }) => `--` + key.replace(/([A-Z])/, '-$1').toLowerCase())
39
- .join(', ');
40
-
41
- if (unexpectedStringOptions.length > 1) {
42
- throw new Error(
43
- `Unexpected value provided for one or more of ${optionNames}. See --help for more information.`,
44
- );
45
- } else if (unexpectedStringOptions.length == 1) {
46
- const params = parameters.array;
47
- params!.unshift(unexpectedStringOptions[0].value);
48
- return params!;
49
- } else {
50
- return parameters.array!;
51
- }
52
- };
@@ -1 +0,0 @@
1
- declare module 'ipfs-http-client';
@@ -1,3 +0,0 @@
1
- const DEFAULT_IPFS_URL = 'https://api.thegraph.com/ipfs/' as const;
2
-
3
- export { DEFAULT_IPFS_URL };
@@ -1,22 +0,0 @@
1
- import { print } from 'gluegun';
2
- import jayson from 'jayson';
3
-
4
- export function createJsonRpcClient(url: URL): jayson.Client | null {
5
- const params = {
6
- host: url.hostname,
7
- port: url.port,
8
- path: url.pathname,
9
- // username may be empty
10
- auth: url.password ? `${url.username}:${url.password}` : undefined,
11
- };
12
-
13
- if (url.protocol === 'https:') {
14
- return jayson.Client.https(params);
15
- }
16
- if (url.protocol === 'http:') {
17
- return jayson.Client.http(params);
18
- }
19
- print.error(`Unsupported protocol: ${url.protocol.substring(0, url.protocol.length - 1)}`);
20
- print.error('The Graph Node URL must be of the following format: http(s)://host[:port]/[path]');
21
- return null;
22
- }
@@ -1,85 +0,0 @@
1
- import path from 'path';
2
- import * as toolbox from 'gluegun';
3
- import yaml from 'yaml';
4
- import { initNetworksConfig, updateSubgraphNetwork } from './network';
5
-
6
- const SUBGRAPH_PATH_BASE = path.join(
7
- __dirname,
8
- '..',
9
- '..',
10
- '..',
11
- '..',
12
- 'examples',
13
- 'example-subgraph',
14
- );
15
-
16
- describe('initNetworksConfig', () => {
17
- beforeAll(async () => {
18
- await initNetworksConfig(toolbox, SUBGRAPH_PATH_BASE, 'address');
19
- });
20
- afterAll(async () => {
21
- toolbox.filesystem.remove(`${SUBGRAPH_PATH_BASE}/networks.json`);
22
- });
23
-
24
- test('generates networks.json from subgraph.yaml', () => {
25
- expect(toolbox.filesystem.exists(`${SUBGRAPH_PATH_BASE}/networks.json`)).toBe('file');
26
- });
27
-
28
- test('Populates the networks.json file with the data from subgraph.yaml', async () => {
29
- const networksStr = toolbox.filesystem.read(`${SUBGRAPH_PATH_BASE}/networks.json`);
30
- const networks = JSON.parse(networksStr!);
31
-
32
- const expected = {
33
- mainnet: {
34
- ExampleSubgraph: { address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835' },
35
- },
36
- };
37
-
38
- expect(networks).toStrictEqual(expected);
39
- });
40
- });
41
-
42
- describe('updateSubgraphNetwork', () => {
43
- beforeAll(async () => {
44
- const content = {
45
- optimism: {
46
- ExampleSubgraph: { address: '0x12345...' },
47
- },
48
- };
49
-
50
- toolbox.filesystem.write(`${SUBGRAPH_PATH_BASE}/networks.json`, content);
51
- toolbox.filesystem.copy(
52
- `${SUBGRAPH_PATH_BASE}/subgraph.yaml`,
53
- `${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`,
54
- );
55
- });
56
-
57
- afterAll(async () => {
58
- toolbox.filesystem.remove(`${SUBGRAPH_PATH_BASE}/networks.json`);
59
- toolbox.filesystem.remove(`${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`);
60
- });
61
-
62
- test('Updates subgraph.yaml', async () => {
63
- const manifest = `${SUBGRAPH_PATH_BASE}/subgraph_copy.yaml`;
64
- const networksFie = `${SUBGRAPH_PATH_BASE}/networks.json`;
65
- let subgraph = toolbox.filesystem.read(manifest);
66
- let subgraphObj = yaml.parse(subgraph!);
67
-
68
- let network = subgraphObj.dataSources[0].network;
69
- let address = subgraphObj.dataSources[0].source.address;
70
-
71
- expect(network).toBe('mainnet');
72
- expect(address).toBe('0x22843e74c59580b3eaf6c233fa67d8b7c561a835');
73
-
74
- await updateSubgraphNetwork(toolbox, manifest, 'optimism', networksFie, 'address');
75
-
76
- subgraph = toolbox.filesystem.read(manifest);
77
- subgraphObj = yaml.parse(subgraph!);
78
-
79
- network = subgraphObj.dataSources[0].network;
80
- address = subgraphObj.dataSources[0].source.address;
81
-
82
- expect(network).toBe('optimism');
83
- expect(address).toBe('0x12345...');
84
- });
85
- });
@@ -1,133 +0,0 @@
1
- import path from 'path';
2
- import { GluegunFilesystem, GluegunPatching } from 'gluegun';
3
- import yaml from 'yaml';
4
- import { step, withSpinner } from './spinner';
5
-
6
- export const updateSubgraphNetwork = async (
7
- toolbox: { filesystem: GluegunFilesystem; patching: GluegunPatching },
8
- manifest: any,
9
- network: string,
10
- networksFile: string,
11
- identifierName: string,
12
- ) =>
13
- await withSpinner(
14
- `Update sources network`,
15
- `Failed to update sources network`,
16
- `Warnings while updating sources network`,
17
- async spinner => {
18
- step(spinner, `Reading networks config`);
19
- const allNetworks = await toolbox.filesystem.read(networksFile, 'json');
20
- const networkConfig = allNetworks[network];
21
-
22
- // Exit if the network passed with --network does not exits in networks.json
23
- if (!networkConfig) {
24
- throw new Error(`Network '${network}' was not found in '${networksFile}'`);
25
- }
26
-
27
- await toolbox.patching.update(manifest, content => {
28
- const subgraph = yaml.parse(content);
29
- const networkSources = Object.keys(networkConfig);
30
- const subgraphSources = subgraph.dataSources.map((value: any) => value.name);
31
-
32
- // Update the dataSources network config
33
- subgraph.dataSources = subgraph.dataSources.map((source: any) => {
34
- if (!networkSources.includes(source.name)) {
35
- throw new Error(
36
- `'${source.name}' was not found in the '${network}' configuration, please update!`,
37
- );
38
- }
39
-
40
- if (hasChanges(identifierName, network, networkConfig[source.name], source)) {
41
- step(spinner, `Update '${source.name}' network configuration`);
42
- source.network = network;
43
- source.source = source.source.abi ? { abi: source.source.abi } : {};
44
- Object.assign(source.source, networkConfig[source.name]);
45
- } else {
46
- step(spinner, `Skip '${source.name}': No changes to network configuration`);
47
- }
48
-
49
- return source;
50
- });
51
-
52
- // All data sources shoud be on the same network,
53
- // so we have to update the network of all templates too.
54
- subgraph.templates &&= subgraph.templates.map((template: any) => ({
55
- ...template,
56
- network,
57
- }));
58
-
59
- const unsusedSources = networkSources.filter(x => !subgraphSources.includes(x));
60
-
61
- unsusedSources.forEach(source => {
62
- step(spinner, `dataSource '${source}' from '${networksFile}' not found in ${manifest}`);
63
- });
64
-
65
- const yaml_doc = new yaml.Document();
66
- yaml_doc.contents = subgraph;
67
- return yaml_doc.toString();
68
- });
69
- },
70
- );
71
-
72
- export const initNetworksConfig = async (
73
- toolbox: { filesystem: GluegunFilesystem },
74
- directory: string,
75
- identifierName: string,
76
- ) =>
77
- await withSpinner(
78
- `Initialize networks config`,
79
- `Failed to initialize networks config`,
80
- `Warnings while initializing networks config`,
81
- async () => {
82
- const subgraphStr = toolbox.filesystem.read(path.join(directory, 'subgraph.yaml'));
83
- const subgraph = yaml.parse(subgraphStr!);
84
-
85
- const networks = subgraph.dataSources.reduce(
86
- (acc: any, source: any) =>
87
- Object.assign(acc, {
88
- [source.network]: {
89
- [source.name]: {
90
- [identifierName]: source.source.address,
91
- startBlock: source.source.startBlock,
92
- },
93
- },
94
- }),
95
- {},
96
- );
97
-
98
- toolbox.filesystem.write(`${directory}/networks.json`, networks);
99
-
100
- return true;
101
- },
102
- );
103
-
104
- // Checks if any network attribute has been changed
105
- function hasChanges(identifierName: string, network: string, networkConfig: any, dataSource: any) {
106
- const networkChanged = dataSource.network !== network;
107
-
108
- // Return directly if the network is different
109
- if (networkChanged) return networkChanged;
110
-
111
- const addressChanged = networkConfig[identifierName] !== dataSource.source[identifierName];
112
-
113
- const startBlockChanged = networkConfig.startBlock !== dataSource.source.startBlock;
114
-
115
- return networkChanged || addressChanged || startBlockChanged;
116
- }
117
-
118
- export const updateNetworksFile = async (
119
- toolbox: { patching: GluegunPatching },
120
- network: string,
121
- dataSource: any,
122
- address: string,
123
- networksFile: string,
124
- ) => {
125
- await toolbox.patching.update(networksFile, config => {
126
- if (Object.keys(config).includes(network)) {
127
- Object.assign(config[network], { [dataSource]: { address } });
128
- } else {
129
- Object.assign(config, { [network]: { [dataSource]: { address } } });
130
- }
131
- return config;
132
- });
133
- };
@@ -1,46 +0,0 @@
1
- import { URL } from 'url';
2
- import { print } from 'gluegun';
3
-
4
- const SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/';
5
- const HOSTED_SERVICE_URL = 'https://api.thegraph.com/deploy/';
6
-
7
- export const validateNodeUrl = (node: string) => new URL(node);
8
-
9
- export const normalizeNodeUrl = (node: string) => new URL(node).toString();
10
-
11
- export function chooseNodeUrl({
12
- product,
13
- studio,
14
- node,
15
- allowSimpleName,
16
- }: {
17
- product: string;
18
- studio: string;
19
- node?: string;
20
- allowSimpleName?: boolean;
21
- }) {
22
- if (node) {
23
- try {
24
- validateNodeUrl(node);
25
- } catch (e) {
26
- print.error(`Graph node "${node}" is invalid: ${e.message}`);
27
- process.exit(1);
28
- }
29
- } else {
30
- if (studio) {
31
- product = 'subgraph-studio';
32
- }
33
- switch (product) {
34
- case 'subgraph-studio':
35
- node = SUBGRAPH_STUDIO_URL;
36
- break;
37
- case 'hosted-service':
38
- node = HOSTED_SERVICE_URL;
39
- break;
40
- }
41
- }
42
- if (node?.match(/studio/) || product === 'subgraph-studio') {
43
- allowSimpleName = true;
44
- }
45
- return { node, allowSimpleName };
46
- }
@@ -1,174 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs-extra';
3
- import { strings } from 'gluegun';
4
- import { Map } from 'immutable';
5
- import prettier from 'prettier';
6
- import yaml from 'yaml';
7
- import Protocol from '../protocols';
8
- import ABI from '../protocols/ethereum/abi';
9
- import Scaffold from '../scaffold';
10
- import { generateEventIndexingHandlers } from '../scaffold/mapping';
11
- import { abiEvents, generateEventType } from '../scaffold/schema';
12
- import { generateTestsFiles } from '../scaffold/tests';
13
- import { Spinner, step } from './spinner';
14
-
15
- export const generateDataSource = async (
16
- protocol: Protocol,
17
- contractName: string,
18
- network: string,
19
- contractAddress: string,
20
- abi: ABI,
21
- ) => {
22
- const protocolManifest = protocol.getManifestScaffold();
23
-
24
- return Map.of(
25
- 'kind',
26
- protocol.name,
27
- 'name',
28
- contractName,
29
- 'network',
30
- network,
31
- 'source',
32
- yaml.parse(
33
- prettier.format(protocolManifest.source({ contract: contractAddress, contractName }), {
34
- parser: 'yaml',
35
- }),
36
- ),
37
- 'mapping',
38
- yaml.parse(
39
- prettier.format(protocolManifest.mapping({ abi, contractName }), {
40
- parser: 'yaml',
41
- }),
42
- ),
43
- ).asMutable();
44
- };
45
-
46
- export const generateScaffold = async (
47
- {
48
- protocolInstance,
49
- abi,
50
- contract,
51
- network,
52
- subgraphName,
53
- indexEvents,
54
- contractName = 'Contract',
55
- node,
56
- }: {
57
- protocolInstance: Protocol;
58
- abi: ABI;
59
- contract: string;
60
- network: string;
61
- subgraphName: string;
62
- indexEvents: boolean;
63
- contractName?: string;
64
- node: string;
65
- },
66
- spinner: Spinner,
67
- ) => {
68
- step(spinner, 'Generate subgraph');
69
-
70
- const scaffold = new Scaffold({
71
- protocol: protocolInstance,
72
- abi,
73
- indexEvents,
74
- contract,
75
- network,
76
- contractName,
77
- subgraphName,
78
- node,
79
- });
80
-
81
- return scaffold.generate();
82
- };
83
-
84
- const writeScaffoldDirectory = async (scaffold: any, directory: string, spinner: Spinner) => {
85
- // Create directory itself
86
- await fs.mkdirs(directory);
87
-
88
- const promises = Object.keys(scaffold).map(async basename => {
89
- const content = scaffold[basename];
90
- const filename = path.join(directory, basename);
91
-
92
- // Write file or recurse into subdirectory
93
- if (typeof content === 'string') {
94
- await fs.writeFile(filename, content, 'utf-8');
95
- } else if (content == null) {
96
- return; // continue loop
97
- } else {
98
- writeScaffoldDirectory(content, path.join(directory, basename), spinner);
99
- }
100
- });
101
-
102
- await Promise.all(promises);
103
- };
104
-
105
- export const writeScaffold = async (scaffold: any, directory: string, spinner: Spinner) => {
106
- step(spinner, `Write subgraph to directory`);
107
- await writeScaffoldDirectory(scaffold, directory, spinner);
108
- };
109
-
110
- export const writeABI = async (abi: ABI, contractName: string) => {
111
- const data = prettier.format(JSON.stringify(abi.data), {
112
- parser: 'json',
113
- });
114
-
115
- await fs.writeFile(`./abis/${contractName}.json`, data, 'utf-8');
116
- };
117
-
118
- export const writeSchema = async (
119
- abi: ABI,
120
- protocol: Protocol,
121
- schemaPath: string,
122
- entities: any,
123
- ) => {
124
- const events = protocol.hasEvents()
125
- ? abiEvents(abi)
126
- .filter(event => !entities.includes(event.get('name')))
127
- .toJS()
128
- : [];
129
-
130
- const data = prettier.format(
131
- events.map(event => generateEventType(event, protocol.name)).join('\n\n'),
132
- {
133
- parser: 'graphql',
134
- },
135
- );
136
-
137
- await fs.appendFile(schemaPath, data, { encoding: 'utf-8' });
138
- };
139
-
140
- export const writeMapping = async (
141
- abi: ABI,
142
- protocol: Protocol,
143
- contractName: string,
144
- entities: any,
145
- ) => {
146
- const events = protocol.hasEvents()
147
- ? abiEvents(abi)
148
- .filter(event => !entities.includes(event.get('name')))
149
- .toJS()
150
- : [];
151
-
152
- const mapping = prettier.format(generateEventIndexingHandlers(events, contractName), {
153
- parser: 'typescript',
154
- semi: false,
155
- });
156
-
157
- await fs.writeFile(`./src/${strings.kebabCase(contractName)}.ts`, mapping, 'utf-8');
158
- };
159
-
160
- export const writeTestsFiles = async (abi: ABI, protocol: Protocol, contractName: string) => {
161
- const hasEvents = protocol.hasEvents();
162
- const events = hasEvents ? abiEvents(abi).toJS() : [];
163
-
164
- if (events.length > 0) {
165
- // If a contract is added to a subgraph that has no tests folder
166
- await fs.ensureDir('./tests/');
167
-
168
- const testsFiles = generateTestsFiles(contractName, events, true);
169
-
170
- for (const [fileName, content] of Object.entries(testsFiles)) {
171
- await fs.writeFile(`./tests/${fileName}`, content, 'utf-8');
172
- }
173
- }
174
- };
@@ -1,60 +0,0 @@
1
- import * as toolbox from 'gluegun';
2
-
3
- export type Spinner = ReturnType<toolbox.GluegunPrint['spin']>;
4
-
5
- export const step = (spinner: Spinner, subject: string, text?: string) => {
6
- if (text) {
7
- spinner.stopAndPersist({
8
- text: toolbox.print.colors.muted(`${subject} ${text}`),
9
- });
10
- } else {
11
- spinner.stopAndPersist({ text: toolbox.print.colors.muted(subject) });
12
- }
13
- spinner.start();
14
- return spinner;
15
- };
16
-
17
- // Executes the function `f` in a command-line spinner, using the
18
- // provided captions for in-progress, error and failed messages.
19
- //
20
- // If `f` throws an error, the spinner stops with the failure message
21
- // and rethrows the error.
22
- // If `f` returns an object with a `warning` and a `result` key, the
23
- // spinner stops with the warning message and returns the `result` value.
24
- // Otherwise the spinner prints the in-progress message with a check mark
25
- // and simply returns the value returned by `f`.
26
- export const withSpinner = async (
27
- text: string,
28
- errorText: string,
29
- warningText: string,
30
- f: (spinner: Spinner) => Promise<any> | any, // TODO: type result
31
- ) => {
32
- const spinner = toolbox.print.spin(text);
33
- try {
34
- const result = await f(spinner);
35
- if (typeof result === 'object') {
36
- const hasError = Object.keys(result).includes('error');
37
- const hasWarning = Object.keys(result).includes('warning');
38
- const hasResult = Object.keys(result).includes('result');
39
-
40
- if (hasError) {
41
- spinner.fail(`${errorText}: ${result.error}`);
42
- return hasResult ? result.result : result;
43
- }
44
- if (hasWarning && hasResult) {
45
- if (result.warning !== null) {
46
- spinner.warn(`${warningText}: ${result.warning}`);
47
- }
48
- spinner.succeed(text);
49
- return result.result;
50
- }
51
- spinner.succeed(text);
52
- return result;
53
- }
54
- spinner.succeed(text);
55
- return result;
56
- } catch (e) {
57
- spinner.fail(`${errorText}: ${e.message}`);
58
- throw e;
59
- }
60
- };