@graphprotocol/graph-cli 0.37.3 → 0.37.4-alpha-20230117095424-b5750b1

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 (352) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/bin.js +6 -0
  3. package/dist/cli.js +26 -0
  4. package/dist/codegen/schema.js +244 -0
  5. package/dist/codegen/schema.test.js +455 -0
  6. package/dist/codegen/template.js +66 -0
  7. package/dist/codegen/types/conversions.js +335 -0
  8. package/dist/codegen/types/index.js +71 -0
  9. package/dist/codegen/types/index.test.js +563 -0
  10. package/dist/codegen/typescript.js +200 -0
  11. package/dist/codegen/util.js +40 -0
  12. package/dist/codegen/util.test.js +93 -0
  13. package/dist/command-helpers/abi.js +76 -0
  14. package/dist/command-helpers/auth.js +76 -0
  15. package/dist/command-helpers/compiler.js +66 -0
  16. package/dist/command-helpers/data-sources.js +29 -0
  17. package/dist/command-helpers/fs.js +9 -0
  18. package/dist/command-helpers/gluegun.js +48 -0
  19. package/dist/command-helpers/ipfs.js +5 -0
  20. package/dist/command-helpers/jsonrpc.js +27 -0
  21. package/dist/command-helpers/network.js +90 -0
  22. package/dist/command-helpers/network.test.js +86 -0
  23. package/dist/command-helpers/node.js +40 -0
  24. package/dist/command-helpers/scaffold.js +110 -0
  25. package/dist/command-helpers/spinner.js +80 -0
  26. package/dist/command-helpers/studio.js +14 -0
  27. package/dist/command-helpers/studio.test.js +41 -0
  28. package/dist/command-helpers/subgraph.js +22 -0
  29. package/dist/command-helpers/version.js +66 -0
  30. package/dist/command-helpers/version.test.js +186 -0
  31. package/dist/commands/add.js +187 -0
  32. package/dist/commands/auth.js +122 -0
  33. package/dist/commands/build.js +136 -0
  34. package/dist/commands/codegen.js +128 -0
  35. package/dist/commands/create.js +94 -0
  36. package/dist/commands/deploy.js +335 -0
  37. package/dist/commands/init.js +800 -0
  38. package/dist/commands/local.js +380 -0
  39. package/dist/commands/remove.js +95 -0
  40. package/dist/commands/test.js +293 -0
  41. package/dist/compiler/asc.js +83 -0
  42. package/dist/compiler/index.js +466 -0
  43. package/dist/debug.js +16 -0
  44. package/dist/migrations/mapping_api_version_0_0_1.js +83 -0
  45. package/dist/migrations/mapping_api_version_0_0_2.js +83 -0
  46. package/dist/migrations/mapping_api_version_0_0_3.js +83 -0
  47. package/dist/migrations/mapping_api_version_0_0_4.js +85 -0
  48. package/dist/migrations/mapping_api_version_0_0_5.js +85 -0
  49. package/dist/migrations/spec_version_0_0_2.js +45 -0
  50. package/dist/migrations/spec_version_0_0_3.js +50 -0
  51. package/dist/migrations/util/load-manifest.js +16 -0
  52. package/dist/migrations/util/versions.js +28 -0
  53. package/dist/migrations.js +54 -0
  54. package/{src → dist}/protocols/arweave/manifest.graphql +0 -0
  55. package/{src/protocols/arweave/scaffold/manifest.ts → dist/protocols/arweave/scaffold/manifest.js} +7 -3
  56. package/{src/protocols/arweave/scaffold/mapping.ts → dist/protocols/arweave/scaffold/mapping.js} +5 -2
  57. package/dist/protocols/arweave/subgraph.js +23 -0
  58. package/dist/protocols/contract.js +2 -0
  59. package/{src → dist}/protocols/cosmos/manifest.graphql +0 -0
  60. package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
  61. package/{src/protocols/cosmos/scaffold/mapping.ts → dist/protocols/cosmos/scaffold/mapping.js} +5 -2
  62. package/dist/protocols/cosmos/subgraph.js +28 -0
  63. package/dist/protocols/ethereum/abi.js +138 -0
  64. package/dist/protocols/ethereum/codegen/abi.js +474 -0
  65. package/dist/protocols/ethereum/codegen/abi.test.js +325 -0
  66. package/dist/protocols/ethereum/codegen/template.js +52 -0
  67. package/dist/protocols/ethereum/contract.js +22 -0
  68. package/{src → dist}/protocols/ethereum/manifest.graphql +0 -0
  69. package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
  70. package/{src/protocols/ethereum/scaffold/mapping.ts → dist/protocols/ethereum/scaffold/mapping.js} +18 -29
  71. package/dist/protocols/ethereum/subgraph.js +172 -0
  72. package/dist/protocols/ethereum/type-generator.js +123 -0
  73. package/dist/protocols/index.js +266 -0
  74. package/dist/protocols/ipfs/codegen/file_template.js +53 -0
  75. package/dist/protocols/near/contract.js +41 -0
  76. package/{src → dist}/protocols/near/manifest.graphql +0 -0
  77. package/dist/protocols/near/scaffold/manifest.js +16 -0
  78. package/{src/protocols/near/scaffold/mapping.ts → dist/protocols/near/scaffold/mapping.js} +5 -2
  79. package/dist/protocols/near/subgraph.js +23 -0
  80. package/dist/protocols/subgraph.js +2 -0
  81. package/{src → dist}/protocols/substreams/manifest.graphql +0 -0
  82. package/dist/protocols/substreams/scaffold/manifest.js +12 -0
  83. package/dist/protocols/substreams/subgraph.js +23 -0
  84. package/{src/scaffold/cosmos.test.ts → dist/scaffold/cosmos.test.js} +21 -22
  85. package/{src/scaffold/ethereum.test.ts → dist/scaffold/ethereum.test.js} +85 -101
  86. package/dist/scaffold/index.js +133 -0
  87. package/dist/scaffold/mapping.js +57 -0
  88. package/{src/scaffold/near.test.ts → dist/scaffold/near.test.js} +22 -23
  89. package/dist/scaffold/schema.js +86 -0
  90. package/dist/scaffold/tests.js +179 -0
  91. package/dist/schema.js +54 -0
  92. package/dist/subgraph.js +243 -0
  93. package/dist/type-generator.js +225 -0
  94. package/dist/validation/contract.js +44 -0
  95. package/dist/validation/index.js +10 -0
  96. package/dist/validation/manifest.js +266 -0
  97. package/dist/validation/schema.js +768 -0
  98. package/dist/validation/schema.test.js +35 -0
  99. package/dist/watcher.js +79 -0
  100. package/package.json +5 -1
  101. package/babel.config.js +0 -3
  102. package/jest.config.js +0 -175
  103. package/src/bin.ts +0 -6
  104. package/src/cli.ts +0 -30
  105. package/src/codegen/schema.test.ts +0 -460
  106. package/src/codegen/schema.ts +0 -299
  107. package/src/codegen/template.ts +0 -45
  108. package/src/codegen/types/conversions.ts +0 -358
  109. package/src/codegen/types/index.test.ts +0 -715
  110. package/src/codegen/types/index.ts +0 -111
  111. package/src/codegen/typescript.ts +0 -224
  112. package/src/codegen/util.test.ts +0 -112
  113. package/src/codegen/util.ts +0 -54
  114. package/src/command-helpers/abi.ts +0 -99
  115. package/src/command-helpers/auth.ts +0 -46
  116. package/src/command-helpers/compiler.ts +0 -60
  117. package/src/command-helpers/data-sources.ts +0 -36
  118. package/src/command-helpers/fs.ts +0 -5
  119. package/src/command-helpers/gluegun.ts +0 -52
  120. package/src/command-helpers/ipfs-http-client.d.ts +0 -1
  121. package/src/command-helpers/ipfs.ts +0 -3
  122. package/src/command-helpers/jsonrpc.ts +0 -22
  123. package/src/command-helpers/network.test.ts +0 -85
  124. package/src/command-helpers/network.ts +0 -133
  125. package/src/command-helpers/node.ts +0 -46
  126. package/src/command-helpers/scaffold.ts +0 -174
  127. package/src/command-helpers/spinner.ts +0 -60
  128. package/src/command-helpers/studio.test.ts +0 -84
  129. package/src/command-helpers/studio.ts +0 -25
  130. package/src/command-helpers/subgraph.ts +0 -21
  131. package/src/command-helpers/version.test.ts +0 -241
  132. package/src/command-helpers/version.ts +0 -53
  133. package/src/commands/add.ts +0 -220
  134. package/src/commands/auth.ts +0 -138
  135. package/src/commands/binary-install-raw.d.ts +0 -1
  136. package/src/commands/build.ts +0 -147
  137. package/src/commands/codegen.ts +0 -123
  138. package/src/commands/create.ts +0 -109
  139. package/src/commands/deploy.ts +0 -388
  140. package/src/commands/init.ts +0 -1060
  141. package/src/commands/local.ts +0 -539
  142. package/src/commands/remove.ts +0 -110
  143. package/src/commands/test.ts +0 -369
  144. package/src/compiler/asc.ts +0 -77
  145. package/src/compiler/index.ts +0 -677
  146. package/src/debug.ts +0 -15
  147. package/src/migrations/mapping_api_version_0_0_1.ts +0 -75
  148. package/src/migrations/mapping_api_version_0_0_2.ts +0 -75
  149. package/src/migrations/mapping_api_version_0_0_3.ts +0 -75
  150. package/src/migrations/mapping_api_version_0_0_4.ts +0 -77
  151. package/src/migrations/mapping_api_version_0_0_5.ts +0 -77
  152. package/src/migrations/spec_version_0_0_2.ts +0 -24
  153. package/src/migrations/spec_version_0_0_3.ts +0 -29
  154. package/src/migrations/util/load-manifest.ts +0 -10
  155. package/src/migrations/util/versions.ts +0 -27
  156. package/src/migrations.ts +0 -33
  157. package/src/protocols/arweave/subgraph.ts +0 -22
  158. package/src/protocols/contract.ts +0 -9
  159. package/src/protocols/cosmos/scaffold/manifest.ts +0 -11
  160. package/src/protocols/cosmos/subgraph.ts +0 -27
  161. package/src/protocols/ethereum/abi.ts +0 -153
  162. package/src/protocols/ethereum/codegen/abi.test.ts +0 -330
  163. package/src/protocols/ethereum/codegen/abi.ts +0 -719
  164. package/src/protocols/ethereum/codegen/template.ts +0 -41
  165. package/src/protocols/ethereum/contract.ts +0 -24
  166. package/src/protocols/ethereum/scaffold/manifest.ts +0 -28
  167. package/src/protocols/ethereum/subgraph.ts +0 -189
  168. package/src/protocols/ethereum/type-generator.ts +0 -191
  169. package/src/protocols/index.ts +0 -287
  170. package/src/protocols/ipfs/codegen/file_template.ts +0 -43
  171. package/src/protocols/near/contract.ts +0 -47
  172. package/src/protocols/near/scaffold/manifest.ts +0 -13
  173. package/src/protocols/near/subgraph.ts +0 -22
  174. package/src/protocols/subgraph.ts +0 -12
  175. package/src/protocols/substreams/scaffold/manifest.ts +0 -8
  176. package/src/protocols/substreams/subgraph.ts +0 -22
  177. package/src/scaffold/index.ts +0 -172
  178. package/src/scaffold/mapping.ts +0 -44
  179. package/src/scaffold/schema.ts +0 -89
  180. package/src/scaffold/tests.ts +0 -217
  181. package/src/schema.ts +0 -26
  182. package/src/subgraph.ts +0 -302
  183. package/src/type-generator.ts +0 -266
  184. package/src/validation/contract.ts +0 -51
  185. package/src/validation/index.ts +0 -5
  186. package/src/validation/manifest.ts +0 -360
  187. package/src/validation/schema.test.ts +0 -38
  188. package/src/validation/schema.ts +0 -957
  189. package/src/watcher.ts +0 -96
  190. package/tests/cli/globalSetup.ts +0 -8
  191. package/tests/cli/globalTeardown.ts +0 -8
  192. package/tests/cli/init/ethereum/abis/Marketplace.json +0 -408
  193. package/tests/cli/init/ethereum/abis/OverloadedElements.json +0 -91
  194. package/tests/cli/init/ethereum/abis/SoloMargin.json +0 -2729
  195. package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stderr +0 -14
  196. package/tests/cli/init/ethereum/from-contract-with-abi-and-structs.stdout +0 -12
  197. package/tests/cli/init/ethereum/from-contract-with-abi.stderr +0 -14
  198. package/tests/cli/init/ethereum/from-contract-with-abi.stdout +0 -12
  199. package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stderr +0 -14
  200. package/tests/cli/init/ethereum/from-contract-with-overloaded-elements.stdout +0 -12
  201. package/tests/cli/init/ethereum/from-contract.stderr +0 -16
  202. package/tests/cli/init/ethereum/from-contract.stdout +0 -12
  203. package/tests/cli/init/ethereum/from-example.stderr +0 -12
  204. package/tests/cli/init/ethereum/from-example.stdout +0 -12
  205. package/tests/cli/init/near/from-contract.stderr +0 -14
  206. package/tests/cli/init/near/from-contract.stdout +0 -12
  207. package/tests/cli/init.test.ts +0 -157
  208. package/tests/cli/spawn-command.d.ts +0 -7
  209. package/tests/cli/util.ts +0 -132
  210. package/tests/cli/validation/abi-not-found/Abi.json +0 -7
  211. package/tests/cli/validation/abi-not-found/mapping.ts +0 -0
  212. package/tests/cli/validation/abi-not-found/schema.graphql +0 -3
  213. package/tests/cli/validation/abi-not-found/subgraph.yaml +0 -42
  214. package/tests/cli/validation/abi-not-found copy.stderr +0 -13
  215. package/tests/cli/validation/big-decimal-is-valid/Abi.json +0 -7
  216. package/tests/cli/validation/big-decimal-is-valid/mapping.ts +0 -0
  217. package/tests/cli/validation/big-decimal-is-valid/schema.graphql +0 -4
  218. package/tests/cli/validation/big-decimal-is-valid/subgraph.yaml +0 -23
  219. package/tests/cli/validation/call-function-not-found/Abi.json +0 -57
  220. package/tests/cli/validation/call-function-not-found/mapping.ts +0 -0
  221. package/tests/cli/validation/call-function-not-found/schema.graphql +0 -3
  222. package/tests/cli/validation/call-function-not-found/subgraph.yaml +0 -22
  223. package/tests/cli/validation/call-function-not-found.stderr +0 -10
  224. package/tests/cli/validation/call-handler-with-tuple/Abi.json +0 -24
  225. package/tests/cli/validation/call-handler-with-tuple/generated/schema.ts +0 -44
  226. package/tests/cli/validation/call-handler-with-tuple/mapping.ts +0 -0
  227. package/tests/cli/validation/call-handler-with-tuple/schema.graphql +0 -3
  228. package/tests/cli/validation/call-handler-with-tuple/subgraph.yaml +0 -22
  229. package/tests/cli/validation/call-handler-with-tuple.stderr +0 -24
  230. package/tests/cli/validation/conflicting-network-names/Abi.json +0 -7
  231. package/tests/cli/validation/conflicting-network-names/mapping.ts +0 -0
  232. package/tests/cli/validation/conflicting-network-names/schema.graphql +0 -3
  233. package/tests/cli/validation/conflicting-network-names/subgraph.yaml +0 -41
  234. package/tests/cli/validation/conflicting-network-names.stderr +0 -10
  235. package/tests/cli/validation/conflicting-protocol-names/Abi.json +0 -7
  236. package/tests/cli/validation/conflicting-protocol-names/mapping.ts +0 -0
  237. package/tests/cli/validation/conflicting-protocol-names/schema.graphql +0 -3
  238. package/tests/cli/validation/conflicting-protocol-names/subgraph.yaml +0 -41
  239. package/tests/cli/validation/conflicting-protocol-names.stderr +0 -10
  240. package/tests/cli/validation/derived-from-target-type-missing/Abi.json +0 -6
  241. package/tests/cli/validation/derived-from-target-type-missing/mapping.ts +0 -0
  242. package/tests/cli/validation/derived-from-target-type-missing/schema.graphql +0 -4
  243. package/tests/cli/validation/derived-from-target-type-missing/subgraph.yaml +0 -22
  244. package/tests/cli/validation/derived-from-target-type-missing.stderr +0 -5
  245. package/tests/cli/validation/derived-from-with-interface/Gravity.json +0 -1
  246. package/tests/cli/validation/derived-from-with-interface/mapping.ts +0 -22
  247. package/tests/cli/validation/derived-from-with-interface/schema.graphql +0 -19
  248. package/tests/cli/validation/derived-from-with-interface/subgraph.yaml +0 -25
  249. package/tests/cli/validation/duplicate-data-source-name/Abi.json +0 -7
  250. package/tests/cli/validation/duplicate-data-source-name/mapping.ts +0 -0
  251. package/tests/cli/validation/duplicate-data-source-name/schema.graphql +0 -4
  252. package/tests/cli/validation/duplicate-data-source-name/subgraph.yaml +0 -40
  253. package/tests/cli/validation/duplicate-data-source-name.stderr +0 -5
  254. package/tests/cli/validation/duplicate-template-name/Abi.json +0 -7
  255. package/tests/cli/validation/duplicate-template-name/mapping.ts +0 -0
  256. package/tests/cli/validation/duplicate-template-name/schema.graphql +0 -4
  257. package/tests/cli/validation/duplicate-template-name/subgraph.yaml +0 -59
  258. package/tests/cli/validation/duplicate-template-name.stderr +0 -5
  259. package/tests/cli/validation/entity-field-args/Abi.json +0 -7
  260. package/tests/cli/validation/entity-field-args/mapping.ts +0 -0
  261. package/tests/cli/validation/entity-field-args/schema.graphql +0 -4
  262. package/tests/cli/validation/entity-field-args/subgraph.yaml +0 -22
  263. package/tests/cli/validation/entity-field-args.stderr +0 -5
  264. package/tests/cli/validation/ethereum-contract-without-handlers/Abi.json +0 -7
  265. package/tests/cli/validation/ethereum-contract-without-handlers/mapping.ts +0 -0
  266. package/tests/cli/validation/ethereum-contract-without-handlers/schema.graphql +0 -3
  267. package/tests/cli/validation/ethereum-contract-without-handlers/subgraph.yaml +0 -19
  268. package/tests/cli/validation/ethereum-contract-without-handlers.stderr +0 -6
  269. package/tests/cli/validation/event-not-found/Abi.json +0 -7
  270. package/tests/cli/validation/event-not-found/mapping.ts +0 -0
  271. package/tests/cli/validation/event-not-found/schema.graphql +0 -3
  272. package/tests/cli/validation/event-not-found/subgraph.yaml +0 -40
  273. package/tests/cli/validation/event-not-found.stderr +0 -12
  274. package/tests/cli/validation/example-values-found/Abi.json +0 -7
  275. package/tests/cli/validation/example-values-found/generated/ExampleSubgraph/ExampleContract.ts +0 -35
  276. package/tests/cli/validation/example-values-found/generated/schema.ts +0 -44
  277. package/tests/cli/validation/example-values-found/mapping.ts +0 -0
  278. package/tests/cli/validation/example-values-found/schema.graphql +0 -3
  279. package/tests/cli/validation/example-values-found/subgraph.yaml +0 -24
  280. package/tests/cli/validation/example-values-found.stderr +0 -34
  281. package/tests/cli/validation/invalid-abis/InvalidAbi.json +0 -1
  282. package/tests/cli/validation/invalid-abis/mapping.ts +0 -0
  283. package/tests/cli/validation/invalid-abis/schema.graphql +0 -3
  284. package/tests/cli/validation/invalid-abis/subgraph.yaml +0 -22
  285. package/tests/cli/validation/invalid-abis.stderr +0 -5
  286. package/tests/cli/validation/invalid-contract-addresses/Abi.json +0 -7
  287. package/tests/cli/validation/invalid-contract-addresses/mapping.ts +0 -0
  288. package/tests/cli/validation/invalid-contract-addresses/schema.graphql +0 -3
  289. package/tests/cli/validation/invalid-contract-addresses/subgraph.yaml +0 -58
  290. package/tests/cli/validation/invalid-contract-addresses.stderr +0 -14
  291. package/tests/cli/validation/invalid-data-source-template/mapping.ts +0 -0
  292. package/tests/cli/validation/invalid-data-source-template/schema.graphql +0 -3
  293. package/tests/cli/validation/invalid-data-source-template/subgraph.yaml +0 -32
  294. package/tests/cli/validation/invalid-data-source-template.stderr +0 -30
  295. package/tests/cli/validation/invalid-entity-field-types/Abi.json +0 -7
  296. package/tests/cli/validation/invalid-entity-field-types/mapping.ts +0 -0
  297. package/tests/cli/validation/invalid-entity-field-types/schema.graphql +0 -157
  298. package/tests/cli/validation/invalid-entity-field-types/subgraph.yaml +0 -22
  299. package/tests/cli/validation/invalid-entity-field-types.stderr +0 -148
  300. package/tests/cli/validation/invalid-fulltext-directive/Abi.json +0 -7
  301. package/tests/cli/validation/invalid-fulltext-directive/mapping.ts +0 -0
  302. package/tests/cli/validation/invalid-fulltext-directive/schema.graphql +0 -140
  303. package/tests/cli/validation/invalid-fulltext-directive/subgraph.yaml +0 -22
  304. package/tests/cli/validation/invalid-fulltext-directive.stderr +0 -32
  305. package/tests/cli/validation/invalid-graphql-schema/Abi.json +0 -7
  306. package/tests/cli/validation/invalid-graphql-schema/mapping.ts +0 -0
  307. package/tests/cli/validation/invalid-graphql-schema/schema.graphql +0 -8
  308. package/tests/cli/validation/invalid-graphql-schema/subgraph.yaml +0 -22
  309. package/tests/cli/validation/invalid-graphql-schema.stderr +0 -25
  310. package/tests/cli/validation/invalid-manifest/subgraph.yaml +0 -13
  311. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol/subgraph.yaml +0 -12
  312. package/tests/cli/validation/invalid-manifest-cannot-infer-protocol.stderr +0 -5
  313. package/tests/cli/validation/invalid-manifest.stderr +0 -28
  314. package/tests/cli/validation/missing-entity-id/Abi.json +0 -7
  315. package/tests/cli/validation/missing-entity-id/mapping.ts +0 -0
  316. package/tests/cli/validation/missing-entity-id/schema.graphql +0 -3
  317. package/tests/cli/validation/missing-entity-id/subgraph.yaml +0 -22
  318. package/tests/cli/validation/missing-entity-id/types/ExampleSubgraph/ExampleContract.ts +0 -35
  319. package/tests/cli/validation/missing-entity-id/types/schema.ts +0 -27
  320. package/tests/cli/validation/missing-entity-id.stderr +0 -5
  321. package/tests/cli/validation/missing-or-invalid-derived-from-fields/Abi.json +0 -7
  322. package/tests/cli/validation/missing-or-invalid-derived-from-fields/mapping.ts +0 -0
  323. package/tests/cli/validation/missing-or-invalid-derived-from-fields/schema.graphql +0 -40
  324. package/tests/cli/validation/missing-or-invalid-derived-from-fields/subgraph.yaml +0 -22
  325. package/tests/cli/validation/missing-or-invalid-derived-from-fields.stderr +0 -10
  326. package/tests/cli/validation/missing-or-invalid-derived-from-fields.stdout +0 -0
  327. package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
  328. package/tests/cli/validation/near-is-valid/schema.graphql +0 -8
  329. package/tests/cli/validation/near-is-valid/subgraph.yaml +0 -30
  330. package/tests/cli/validation/nested-template-nice-error/Abi.json +0 -7
  331. package/tests/cli/validation/nested-template-nice-error/mapping.ts +0 -0
  332. package/tests/cli/validation/nested-template-nice-error/schema.graphql +0 -3
  333. package/tests/cli/validation/nested-template-nice-error/subgraph.yaml +0 -35
  334. package/tests/cli/validation/nested-template-nice-error.stderr +0 -5
  335. package/tests/cli/validation/no-network-names/Abi.json +0 -7
  336. package/tests/cli/validation/no-network-names/mapping.ts +0 -0
  337. package/tests/cli/validation/no-network-names/schema.graphql +0 -3
  338. package/tests/cli/validation/no-network-names/subgraph.yaml +0 -40
  339. package/tests/cli/validation/no-network-names.stderr +0 -34
  340. package/tests/cli/validation/source-without-address-is-valid/Abi.json +0 -7
  341. package/tests/cli/validation/source-without-address-is-valid/generated/ExampleSubgraph/ExampleContract.ts +0 -35
  342. package/tests/cli/validation/source-without-address-is-valid/mapping.ts +0 -0
  343. package/tests/cli/validation/source-without-address-is-valid/schema.graphql +0 -3
  344. package/tests/cli/validation/source-without-address-is-valid/subgraph.yaml +0 -23
  345. package/tests/cli/validation/source-without-address-is-valid.stderr +0 -24
  346. package/tests/cli/validation/topic0-is-valid/Abi.json +0 -7
  347. package/tests/cli/validation/topic0-is-valid/mapping.ts +0 -0
  348. package/tests/cli/validation/topic0-is-valid/schema.graphql +0 -4
  349. package/tests/cli/validation/topic0-is-valid/subgraph.yaml +0 -24
  350. package/tests/cli/validation.test.ts +0 -226
  351. package/tsconfig.build.json +0 -4
  352. package/tsconfig.json +0 -19
@@ -1,539 +0,0 @@
1
- import { ChildProcess, spawn } from 'child_process';
2
- import http from 'http';
3
- import net from 'net';
4
- import path from 'path';
5
- import chalk from 'chalk';
6
- import compose from 'docker-compose';
7
- import { GluegunToolbox } from 'gluegun';
8
- import stripAnsi from 'strip-ansi';
9
- import tmp from 'tmp-promise';
10
- import { fixParameters } from '../command-helpers/gluegun';
11
- import { step, withSpinner } from '../command-helpers/spinner';
12
-
13
- // Clean up temporary files even when an uncaught exception occurs
14
- tmp.setGracefulCleanup();
15
-
16
- const HELP = `
17
- ${chalk.bold('graph local')} [options] ${chalk.bold('<local-command>')}
18
-
19
- Options:
20
-
21
- -h, --help Show usage information
22
- --node-logs Print the Graph Node logs (optional)
23
- --ethereum-logs Print the Ethereum logs (optional)
24
- --compose-file <file> Custom Docker Compose file for additional services (optional)
25
- --node-image <image> Custom Graph Node image to test against (default: graphprotocol/graph-node:latest)
26
- --standalone-node <cmd> Use a standalone Graph Node outside Docker Compose (optional)
27
- --standalone-node-args Custom arguments to be passed to the standalone Graph Node (optional)
28
- --skip-wait-for-ipfs Don't wait for IPFS to be up at localhost:15001 (optional)
29
- --skip-wait-for-ethereum Don't wait for Ethereum to be up at localhost:18545 (optional)
30
- --skip-wait-for-postgres Don't wait for Postgres to be up at localhost:15432 (optional)
31
- --timeout Time to wait for service containers. (optional, defaults to 120000 milliseconds)
32
- `;
33
-
34
- export interface LocalOptions {
35
- help?: boolean;
36
- nodeLogs?: boolean;
37
- ethereumLogs?: boolean;
38
- composeFile?: string;
39
- nodeImage?: string;
40
- standaloneNode?: string;
41
- standaloneNodeArgs?: string;
42
- skipWaitForIpfs?: boolean;
43
- skipWaitForEthereum?: boolean;
44
- skipWaitForPostgres?: boolean;
45
- timeout?: number;
46
- }
47
-
48
- export default {
49
- description: 'Runs local tests against a Graph Node environment (using Ganache by default)',
50
- run: async (toolbox: GluegunToolbox) => {
51
- // Obtain tools
52
- const { filesystem, print } = toolbox;
53
-
54
- // Parse CLI parameters
55
- let {
56
- composeFile,
57
- ethereumLogs,
58
- h,
59
- help,
60
- nodeImage,
61
- nodeLogs,
62
- skipWaitForEthereum,
63
- skipWaitForIpfs,
64
- skipWaitForPostgres,
65
- standaloneNode,
66
- standaloneNodeArgs,
67
- timeout,
68
- } = toolbox.parameters.options;
69
-
70
- // Support both short and long option variants
71
- help ||= h;
72
-
73
- // Extract test command
74
- const params = fixParameters(toolbox.parameters, {
75
- ethereumLogs,
76
- h,
77
- help,
78
- nodeLogs,
79
- skipWaitForEthereum,
80
- skipWaitForIpfs,
81
- skipWaitForPostgres,
82
- });
83
-
84
- // Show help text if requested
85
- if (help) {
86
- print.info(HELP);
87
- return;
88
- }
89
-
90
- if (params.length == 0) {
91
- print.error(`Test command not provided as the last argument`);
92
- process.exitCode = 1;
93
- return;
94
- }
95
-
96
- const testCommand = params[0];
97
-
98
- // Obtain the Docker Compose file for services that the tests run against
99
- composeFile ||= path.join(
100
- __dirname,
101
- '..',
102
- '..',
103
- 'resources',
104
- 'test',
105
- standaloneNode ? 'docker-compose-standalone-node.yml' : 'docker-compose.yml',
106
- );
107
-
108
- // parse timeout. Defaults to 120 seconds
109
- timeout = Math.abs(parseInt(timeout)) || 120_000;
110
-
111
- if (!filesystem.exists(composeFile)) {
112
- print.error(`Docker Compose file \`${composeFile}\` not found`);
113
- process.exitCode = 1;
114
- return;
115
- }
116
-
117
- // Create temporary directory to operate in
118
- const { path: tempdir } = await tmp.dir({ prefix: 'graph-test', unsafeCleanup: true });
119
- try {
120
- await configureTestEnvironment(toolbox, tempdir, composeFile, nodeImage);
121
- } catch (e) {
122
- process.exitCode = 1;
123
- return;
124
- }
125
-
126
- // Bring up test environment
127
- try {
128
- await startTestEnvironment(tempdir);
129
- } catch (e) {
130
- print.error(e);
131
- process.exitCode = 1;
132
- return;
133
- }
134
-
135
- // Wait for test environment to come up
136
- try {
137
- await waitForTestEnvironment({
138
- skipWaitForEthereum,
139
- skipWaitForIpfs,
140
- skipWaitForPostgres,
141
- timeout,
142
- });
143
- } catch (e) {
144
- await stopTestEnvironment(tempdir);
145
- process.exitCode = 1;
146
- return;
147
- }
148
-
149
- // Bring up Graph Node separately, if a standalone node is used
150
- let nodeProcess;
151
- const nodeOutputChunks: Buffer[] = [];
152
- if (standaloneNode) {
153
- try {
154
- nodeProcess = await startGraphNode(standaloneNode, standaloneNodeArgs, nodeOutputChunks);
155
- } catch (e) {
156
- toolbox.print.error('');
157
- toolbox.print.error(' Graph Node');
158
- toolbox.print.error(' ----------');
159
- toolbox.print.error(indent(' ', Buffer.concat(nodeOutputChunks).toString('utf-8')));
160
- toolbox.print.error('');
161
- await stopTestEnvironment(tempdir);
162
- process.exitCode = 1;
163
- return;
164
- }
165
- }
166
-
167
- // Wait for Graph Node to come up
168
- try {
169
- await waitForGraphNode(timeout);
170
- } catch (e) {
171
- toolbox.print.error('');
172
- toolbox.print.error(' Graph Node');
173
- toolbox.print.error(' ----------');
174
- toolbox.print.error(
175
- indent(' ', await collectGraphNodeLogs(tempdir, standaloneNode, nodeOutputChunks)),
176
- );
177
- toolbox.print.error('');
178
- await stopTestEnvironment(tempdir);
179
- process.exitCode = 1;
180
- return;
181
- }
182
-
183
- // Run tests
184
- const result = await runTests(testCommand);
185
-
186
- // Bring down Graph Node, if a standalone node is used
187
- if (nodeProcess) {
188
- try {
189
- await stopGraphNode(nodeProcess);
190
- } catch (e) {
191
- // do nothing (the spinner already logs the problem)
192
- }
193
- }
194
-
195
- if (result.exitCode == 0) {
196
- toolbox.print.success('✔ Tests passed');
197
- } else {
198
- toolbox.print.error('✖ Tests failed');
199
- }
200
-
201
- // Capture logs
202
- nodeLogs =
203
- nodeLogs || result.exitCode !== 0
204
- ? await collectGraphNodeLogs(tempdir, standaloneNode, nodeOutputChunks)
205
- : undefined;
206
- ethereumLogs = ethereumLogs ? await collectEthereumLogs(tempdir) : undefined;
207
-
208
- // Bring down the test environment
209
- try {
210
- await stopTestEnvironment(tempdir);
211
- } catch (e) {
212
- // do nothing (the spinner already logs the problem)
213
- }
214
-
215
- if (nodeLogs) {
216
- toolbox.print.info('');
217
- toolbox.print.info(' Graph node');
218
- toolbox.print.info(' ----------');
219
- toolbox.print.info('');
220
- toolbox.print.info(indent(' ', nodeLogs));
221
- }
222
-
223
- if (ethereumLogs) {
224
- toolbox.print.info('');
225
- toolbox.print.info(' Ethereum');
226
- toolbox.print.info(' --------');
227
- toolbox.print.info('');
228
- toolbox.print.info(indent(' ', ethereumLogs));
229
- }
230
-
231
- // Always print the test output
232
- toolbox.print.info('');
233
- toolbox.print.info(' Output');
234
- toolbox.print.info(' ------');
235
- toolbox.print.info('');
236
- toolbox.print.info(indent(' ', result.output));
237
-
238
- // Propagate the exit code from the test run
239
- process.exitCode = result.exitCode;
240
- },
241
- };
242
-
243
- /**
244
- * Indents all lines of a string
245
- */
246
- const indent = (indentation: string, str: string) =>
247
- str
248
- .split('\n')
249
- .map(s => `${indentation}${s}`)
250
- // Remove whitespace from empty lines
251
- .map(s => s.replace(/^\s+$/g, ''))
252
- .join('\n');
253
-
254
- const configureTestEnvironment = async (
255
- toolbox: GluegunToolbox,
256
- tempdir: string,
257
- composeFile: string,
258
- nodeImage: string,
259
- ) =>
260
- await withSpinner(
261
- `Configure test environment`,
262
- `Failed to configure test environment`,
263
- `Warnings configuring test environment`,
264
- async () => {
265
- // Temporary compose file
266
- const tempComposeFile = path.join(tempdir, 'compose', 'docker-compose.yml');
267
-
268
- // Copy the compose file to the temporary directory
269
- toolbox.filesystem.copy(composeFile, tempComposeFile);
270
-
271
- // Substitute the graph-node image with the custom one, if appropriate
272
- if (nodeImage) {
273
- await toolbox.patching.replace(
274
- tempComposeFile,
275
- 'graphprotocol/graph-node:latest',
276
- nodeImage,
277
- );
278
- }
279
- },
280
- );
281
-
282
- const waitFor = async (timeout: number, testFn: () => void) => {
283
- const deadline = Date.now() + timeout;
284
- let error: Error | undefined = undefined;
285
- return new Promise((resolve, reject) => {
286
- const check = async () => {
287
- if (Date.now() > deadline) {
288
- reject(error);
289
- } else {
290
- try {
291
- const result = await testFn();
292
- resolve(result);
293
- } catch (e) {
294
- error = e;
295
- setTimeout(check, 500);
296
- }
297
- }
298
- };
299
-
300
- setTimeout(check, 0);
301
- });
302
- };
303
-
304
- const startTestEnvironment = async (tempdir: string) =>
305
- await withSpinner(
306
- `Start test environment`,
307
- `Failed to start test environment`,
308
- `Warnings starting test environment`,
309
- async _spinner => {
310
- // Bring up the test environment
311
- await compose.upAll({
312
- cwd: path.join(tempdir, 'compose'),
313
- });
314
- },
315
- );
316
-
317
- const waitForTestEnvironment = async ({
318
- skipWaitForEthereum,
319
- skipWaitForIpfs,
320
- skipWaitForPostgres,
321
- timeout,
322
- }: {
323
- skipWaitForEthereum: boolean;
324
- skipWaitForIpfs: boolean;
325
- skipWaitForPostgres: boolean;
326
- timeout: number;
327
- }) =>
328
- await withSpinner(
329
- `Wait for test environment`,
330
- `Failed to wait for test environment`,
331
- `Warnings waiting for test environment`,
332
- async spinner => {
333
- // Wait 10s for IPFS (if desired)
334
- if (skipWaitForIpfs) {
335
- step(spinner, 'Skip waiting for IPFS');
336
- } else {
337
- await waitFor(
338
- timeout,
339
- async () =>
340
- new Promise((resolve, reject) => {
341
- http
342
- .get('http://localhost:15001/api/v0/version', () => {
343
- resolve();
344
- })
345
- .on('error', e => {
346
- reject(new Error(`Could not connect to IPFS: ${e}`));
347
- });
348
- }),
349
- );
350
- step(spinner, 'IPFS is up');
351
- }
352
-
353
- // Wait 10s for Ethereum (if desired)
354
- if (skipWaitForEthereum) {
355
- step(spinner, 'Skip waiting for Ethereum');
356
- } else {
357
- await waitFor(
358
- timeout,
359
- async () =>
360
- new Promise((resolve, reject) => {
361
- http
362
- .get('http://localhost:18545', () => {
363
- resolve();
364
- })
365
- .on('error', e => {
366
- reject(new Error(`Could not connect to Ethereum: ${e}`));
367
- });
368
- }),
369
- );
370
- step(spinner, 'Ethereum is up');
371
- }
372
-
373
- // Wait 10s for Postgres (if desired)
374
- if (skipWaitForPostgres) {
375
- step(spinner, 'Skip waiting for Postgres');
376
- } else {
377
- await waitFor(
378
- timeout,
379
- async () =>
380
- new Promise((resolve, reject) => {
381
- try {
382
- const socket = net.connect(15_432, 'localhost', () => resolve());
383
- socket.on('error', e => reject(new Error(`Could not connect to Postgres: ${e}`)));
384
- socket.end();
385
- } catch (e) {
386
- reject(new Error(`Could not connect to Postgres: ${e}`));
387
- }
388
- }),
389
- );
390
- step(spinner, 'Postgres is up');
391
- }
392
- },
393
- );
394
-
395
- const stopTestEnvironment = async (tempdir: string) =>
396
- await withSpinner(
397
- `Stop test environment`,
398
- `Failed to stop test environment`,
399
- `Warnings stopping test environment`,
400
- async () => {
401
- // Our containers do not respond quickly to the SIGTERM which `down` tries before timing out
402
- // and killing them, so speed things up by sending a SIGKILL right away.
403
- try {
404
- await compose.kill({ cwd: path.join(tempdir, 'compose') });
405
- } catch (e) {
406
- // Do nothing, we will just try to run 'down'
407
- // to bring down the environment
408
- }
409
- await compose.down({ cwd: path.join(tempdir, 'compose') });
410
- },
411
- );
412
-
413
- const startGraphNode = async (
414
- standaloneNode: string,
415
- standaloneNodeArgs: string,
416
- nodeOutputChunks: Buffer[],
417
- ): Promise<ChildProcess> =>
418
- await withSpinner(
419
- `Start Graph node`,
420
- `Failed to start Graph node`,
421
- `Warnings starting Graph node`,
422
- async spinner => {
423
- const defaultArgs = [
424
- '--ipfs',
425
- 'localhost:15001',
426
- '--postgres-url',
427
- 'postgresql://graph:let-me-in@localhost:15432/graph',
428
- '--ethereum-rpc',
429
- 'test:http://localhost:18545',
430
- '--http-port',
431
- '18000',
432
- '--ws-port',
433
- '18001',
434
- '--admin-port',
435
- '18020',
436
- '--index-node-port',
437
- '18030',
438
- '--metrics-port',
439
- '18040',
440
- ];
441
-
442
- const defaultEnv = {
443
- GRAPH_LOG: 'debug',
444
- GRAPH_MAX_API_VERSION: '0.0.5',
445
- };
446
-
447
- const args = standaloneNodeArgs ? standaloneNodeArgs.split(' ') : defaultArgs;
448
- const env = { ...defaultEnv, ...process.env };
449
-
450
- const nodeProcess = spawn(standaloneNode, args, {
451
- cwd: process.cwd(),
452
- env,
453
- });
454
-
455
- step(spinner, 'Graph node:', String(nodeProcess.spawnargs.join(' ')));
456
-
457
- nodeProcess.stdout.on('data', data => nodeOutputChunks.push(Buffer.from(data)));
458
- nodeProcess.stderr.on('data', data => nodeOutputChunks.push(Buffer.from(data)));
459
- nodeProcess.on('error', e => {
460
- nodeOutputChunks.push(Buffer.from(String(e), 'utf-8'));
461
- });
462
-
463
- // Return the node child process
464
- return nodeProcess;
465
- },
466
- );
467
-
468
- const waitForGraphNode = async (timeout: number) =>
469
- await withSpinner(
470
- `Wait for Graph node`,
471
- `Failed to wait for Graph node`,
472
- `Warnings waiting for Graph node`,
473
- async () => {
474
- await waitFor(
475
- timeout,
476
- async () =>
477
- new Promise<void>((resolve, reject) => {
478
- http
479
- .get('http://localhost:18000', { timeout }, () => resolve())
480
- .on('error', e => reject(e));
481
- }),
482
- );
483
- },
484
- );
485
-
486
- const stopGraphNode = async (nodeProcess: ChildProcess) =>
487
- await withSpinner(
488
- `Stop Graph node`,
489
- `Failed to stop Graph node`,
490
- `Warnings stopping Graph node`,
491
- async () => {
492
- nodeProcess.kill(9);
493
- },
494
- );
495
-
496
- const collectGraphNodeLogs = async (
497
- tempdir: string,
498
- standaloneNode: string,
499
- nodeOutputChunks: Buffer[],
500
- ) => {
501
- if (standaloneNode) {
502
- // Pull the logs from the captured output
503
- return stripAnsi(Buffer.concat(nodeOutputChunks).toString('utf-8'));
504
- }
505
- // Pull the logs from docker compose
506
- const logs = await compose.logs('graph-node', {
507
- follow: false,
508
- cwd: path.join(tempdir, 'compose'),
509
- });
510
- return stripAnsi(logs.out.trim()).replace(/graph-node_1 {2}\| /g, '');
511
- };
512
-
513
- const collectEthereumLogs = async (tempdir: string) => {
514
- const logs = await compose.logs('ethereum', {
515
- follow: false,
516
- cwd: path.join(tempdir, 'compose'),
517
- });
518
- return stripAnsi(logs.out.trim()).replace(/ethereum_1 {2}\| /g, '');
519
- };
520
-
521
- const runTests = async (testCommand: string) =>
522
- await withSpinner(
523
- `Run tests`,
524
- `Failed to run tests`,
525
- `Warnings running tests`,
526
- async () =>
527
- new Promise(resolve => {
528
- const output: Buffer[] = [];
529
- const testProcess = spawn(String(testCommand), { shell: true });
530
- testProcess.stdout.on('data', data => output.push(Buffer.from(data)));
531
- testProcess.stderr.on('data', data => output.push(Buffer.from(data)));
532
- testProcess.on('close', code => {
533
- resolve({
534
- exitCode: code,
535
- output: Buffer.concat(output).toString('utf-8'),
536
- });
537
- });
538
- }),
539
- );
@@ -1,110 +0,0 @@
1
- import { URL } from 'url';
2
- import chalk from 'chalk';
3
- import { GluegunToolbox } from 'gluegun';
4
- import { identifyDeployKey as identifyAccessToken } from '../command-helpers/auth';
5
- import { createJsonRpcClient } from '../command-helpers/jsonrpc';
6
- import { validateNodeUrl } from '../command-helpers/node';
7
-
8
- const HELP = `
9
- ${chalk.bold('graph remove')} ${chalk.dim('[options]')} ${chalk.bold('<subgraph-name>')}
10
-
11
- ${chalk.dim('Options:')}
12
-
13
- --access-token <token> Graph access token
14
- -h, --help Show usage information
15
- -g, --node <url> Graph node to create the subgraph in
16
- `;
17
-
18
- export interface RemoveOptions {
19
- accessToken?: string;
20
- help?: boolean;
21
- node?: string;
22
- }
23
-
24
- export default {
25
- description: 'Unregisters a subgraph name',
26
- run: async (toolbox: GluegunToolbox) => {
27
- // Obtain tools
28
- const { print } = toolbox;
29
-
30
- // Read CLI parameters
31
- let { accessToken, g, h, help, node } = toolbox.parameters.options;
32
- const subgraphName = toolbox.parameters.first;
33
-
34
- // Support both long and short option variants
35
- help ||= h;
36
- node ||= g;
37
-
38
- // Show help text if requested
39
- if (help) {
40
- print.info(HELP);
41
- return;
42
- }
43
-
44
- // Validate the subgraph name
45
- if (!subgraphName) {
46
- print.error('No subgraph name provided');
47
- print.info(HELP);
48
- process.exitCode = 1;
49
- return;
50
- }
51
-
52
- // Validate node
53
- if (!node) {
54
- print.error(`No Graph node provided`);
55
- print.info(HELP);
56
- process.exitCode = 1;
57
- return;
58
- }
59
- try {
60
- validateNodeUrl(node);
61
- } catch (e) {
62
- print.error(`Graph node "${node}" is invalid: ${e.message}`);
63
- process.exitCode = 1;
64
- return;
65
- }
66
-
67
- const requestUrl = new URL(node);
68
- const client = createJsonRpcClient(requestUrl);
69
-
70
- // Exit with an error code if the client couldn't be created
71
- if (!client) {
72
- process.exitCode = 1;
73
- return;
74
- }
75
-
76
- // Use the access token, if one is set
77
- accessToken = await identifyAccessToken(node, accessToken);
78
- if (accessToken !== undefined && accessToken !== null) {
79
- // @ts-expect-error options property seems to exist
80
- client.options.headers = { Authorization: `Bearer ${accessToken}` };
81
- }
82
-
83
- const spinner = print.spin(`Creating subgraph in Graph node: ${requestUrl}`);
84
- client.request(
85
- 'subgraph_remove',
86
- { name: subgraphName },
87
- (
88
- // @ts-expect-error TODO: why are the arguments not typed?
89
- requestError,
90
- // @ts-expect-error TODO: why are the arguments not typed?
91
- jsonRpcError,
92
- // TODO: this argument is unused, but removing it from the commands/create.ts fails the basic-event-handlers tests.
93
- // I'll therefore leave it in here too until we figure out the weirdness
94
- // @ts-expect-error TODO: why are the arguments not typed?
95
- _res,
96
- ) => {
97
- if (jsonRpcError) {
98
- spinner.fail(`Error removing the subgraph: ${jsonRpcError.message}`);
99
- process.exitCode = 1;
100
- } else if (requestError) {
101
- spinner.fail(`HTTP error removing the subgraph: ${requestError.code}`);
102
- process.exitCode = 1;
103
- } else {
104
- spinner.stop();
105
- print.success(`Removed subgraph: ${subgraphName}`);
106
- }
107
- },
108
- );
109
- },
110
- };