graph-tooling icon indicating copy to clipboard operation
graph-tooling copied to clipboard

`graph add` should not modify `subgraph.yaml` on error

Open 0237h opened this issue 1 year ago • 0 comments

Which packages are impacted by your issue?

@graphprotocol/graph-cli

Describe the issue

If incorrect parameters are passed to the graph add command it will write these first to the subgraph.yaml before calling the codegen subcommand which will fail.

The subgraph.yaml is then left in an incorrect state and is not able to be loaded (with a second call to graph add for example) as the validate function fails.

Reproduction

cli

Steps to Reproduce the Bug or Issue

  1. init a subgraph
  2. Run graph add <address> --start-block=invalid
  3. Output should be similar to Failed to run codegen: Command failed: yarn codegen
  4. The subgraph.yaml has been updated with the new contract and startBlock value is set to invalid.
  5. Running the command again should lead to this error
Error: Error in subgraph.yaml:

      Path: dataSources > X > source > startBlock
      Expected BigInt, found string:
      invalid

Expected behavior

The command should not modify the original subgraph.yaml if it leaves it in a invalid state.

Screenshots or Videos

No response

Platform

  • @graphprotocol/* version(s): 0.90.1

Subgraph Manifest

No response

Subgraph GraphQL Schema

No response

Additional context

Possible solutions

  • Validate all parameters to make sure the values are valid.
  • Backup the original manifest and restore in case of errors.

0237h avatar Nov 29 '24 18:11 0237h