Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add graph init with --from-example and --from-contract modes #224

Merged
merged 26 commits into from
Mar 14, 2019

Conversation

Jannis
Copy link
Contributor

@Jannis Jannis commented Mar 7, 2019

This supersedes #216 by supporting both the old and the new graph init via

  • --from-example and
  • --from-contract <address>

mode flags.

TODO

Example usage

If all arguments are provided for either mode, graph init will run in non-interactive mode:

# From the example subgraph:
graph init --from-example user/subgraph-name output-dir
graph init --from-example --allow-simple-name subgraph-name output-dir

# From an existing contract:
graph init \
  --from-contract 0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d \
  --network mainnet \
  user/subgraph-name \
  output-dir

If one or more arguments are not provided, graph init will run the user through an interactive form to create a subgraph from an existing contract, pre-populating fields with the provided values:

$ graph init --from-contract 0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d jannis/decentraland-land
✔ Subgraph name · jannis/decentraland-land
✔ Directory to create the subgraph in · land
✔ Ethereum network · mainnet
✔ Contract address · 0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d
✔ Fetching ABI from Etherscan
———
  Generate subgraph from ABI
  Write subgraph to directory
✔ Create subgraph scaffold
✔ Initialize subgraph repository
✔ Install dependencies with yarn
✔ Generate ABI and schema types with yarn codegen

Subgraph jannis/decentraland-land created in land

Next steps:

  1. Run `graph auth https://api.thegraph.com/deploy/ <access-token>`
     to authenticate with the hosted service. You can get the access token from
     https://thegraph.com/explorer/dashboard/.

  2. Type `cd land` to enter the subgraph.

  3. Run `yarn deploy` to deploy the subgraph to
     https://thegraph.com/explorer/subgraph/jannis/decentraland-land.

Make sure to visit the documentation on https://thegraph.com/docs/ for further information.

If an ABI cannot be found on Etherscan, this form asks for a local ABI file path:

$ graph init --from-contract 0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4f jannis/decentraland-land
✔ Subgraph name · jannis/decentraland-land
✔ Directory to create the subgraph in · land-2
✔ Ethereum network · mainnet
✔ Contract address · 0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4f
✖ Failed to fetch ABI from Etherscan: Unexpected token C in JSON at position 0
✔ ABI file (path) · /Users/jannis/Work/graphprotocol/subgraphs/decentraland/abis/LANDRegistry.json
———
  Generate subgraph from ABI
  Write subgraph to directory
✔ Create subgraph scaffold
✔ Initialize subgraph repository
⠋ Install dependencies with yarn
...

@Jannis Jannis added this to the Q1 2019 milestone Mar 7, 2019
@Jannis Jannis self-assigned this Mar 7, 2019
@Jannis Jannis requested a review from a team March 7, 2019 12:19
@ghost ghost added the pending review label Mar 7, 2019
@Jannis Jannis added the area/cli label Mar 7, 2019
@Jannis Jannis changed the title Add graph init with --from-example and --from-contract modes Add graph init with --from-example and --from-contract modes Mar 7, 2019
@leoyvens
Copy link
Collaborator

leoyvens commented Mar 8, 2019

The "Next steps:" instructions don't instruct me to run codegen, which is necessary before deploy.

@Jannis
Copy link
Contributor Author

Jannis commented Mar 8, 2019

@leodasvacas That's because graph init runs it for you 😉

@leoyvens
Copy link
Collaborator

leoyvens commented Mar 8, 2019

@Jannis ah nice, I got confused because of the /generated issue.

Copy link
Collaborator

@leoyvens leoyvens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of small comments. Nice tests! It would be cool to also have a test for the generated contents.

src/commands/init.js Outdated Show resolved Hide resolved
src/commands/init.js Show resolved Hide resolved
})

if (inputs === undefined) {
process.exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does inputs === undefined have a particular meaning? Should we print something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inputs are undefined if the form is cancelled. I've added a comment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/commands/init.js Show resolved Hide resolved
src/commands/init.js Show resolved Hide resolved
src/commands/init.js Show resolved Hide resolved
src/commands/init.js Show resolved Hide resolved
src/commands/init.js Show resolved Hide resolved
src/scaffold.js Outdated Show resolved Hide resolved
@Jannis
Copy link
Contributor Author

Jannis commented Mar 12, 2019

Thanks @leodasvacas, I'll address the comments in the morning!

@Jannis
Copy link
Contributor Author

Jannis commented Mar 14, 2019

@leodasvacas I've fixed a few things, added a few comments and tried to address with comments with replies. Let me know what you think.

src/scaffold.js Outdated
subgraphName,
},
dependencies: {
'@graphprotocol/graph-cli': '0.7.2',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to be careful to remember to update this, at least on breaking changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I have an idea: How about we take the package version and put it in here? Then we're always up to date.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's possible that would be great.

leoyvens
leoyvens previously approved these changes Mar 14, 2019
@Jannis Jannis merged commit 3e6d2e0 into master Mar 14, 2019
@ghost ghost removed the pending review label Mar 14, 2019
@saihaj saihaj deleted the jannis/graph-init-with-two-modes branch May 12, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants