graphprotocol / graph-tooling

Monorepo for various tools used by subgraph developers.
https://thegraph.com/docs
Apache License 2.0
392 stars 210 forks source link

Support subgraph datasources #1754

Closed incrypto32 closed 6 hours ago

incrypto32 commented 3 weeks ago

This PR adds new types for subgraph datasources to graph-ts and codegen functionality to generate schema code for the source subgraphs. Detailed docs about subgraph datasources here.

This PR

  1. Adds support to parse the new type of datasource in the manifest
  2. Adds the new EntityTrigger type to graph-ts which is the Assemblyscript represenation of entity triggers.
  3. Adds an enum EntityOp which represents the entity operations done on the source subgraph
  4. Runs codegen for the schema of source subgraphs so that dependant subgraph also has access to entity types from source subgraphs
changeset-bot[bot] commented 3 weeks ago

🦋 Changeset detected

Latest commit: b75cda90f8fd1bb83f513f92b71f85888170fa6c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | ------------------------ | ----- | | @graphprotocol/graph-cli | Minor | | @graphprotocol/graph-ts | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

github-actions[bot] commented 3 weeks ago

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets): Package Version Info
@graphprotocol/graph-cli 0.91.0-alpha-20241129215038-b75cda9 npm ↗︎ unpkg ↗︎
@graphprotocol/graph-ts 0.36.0-alpha-20241129215038-b75cda9 npm ↗︎ unpkg ↗︎
cloudflare-workers-and-pages[bot] commented 3 weeks ago

Deploying graph-tooling with  Cloudflare Pages  Cloudflare Pages

Latest commit: b75cda9
Status: ✅  Deploy successful!
Preview URL: https://f66a91d8.graph-tooling.pages.dev
Branch Preview URL: https://feat-subgraph-composition.graph-tooling.pages.dev

View logs

0237h commented 3 weeks ago

Hey @incrypto32, thanks for the PR !

Gonna take a bit of time to review. In the meantime if you can provide some more context/information as to what these feature would bring to developers, would be very much appreciated thanks :+1:

0237h commented 3 weeks ago

Given the context, we'll also wait for some of the related PRs in graph-node to be merged before merging this one as well.

incrypto32 commented 3 weeks ago

Hey @0237h , i'll write up the required context soon. TL;DR is this will support the code generation and the new type of datasource thats being added as part of the subgraph composition feature. As you mentioned. Yes those graph-node PR's need to be merge before getting this out. I'll write a detailed comment on the changes later.

incrypto32 commented 2 weeks ago

@0237h I just added a description to the PR. let me know if more info is needed

YaroShkvorets commented 1 week ago

Doesn't seem to work for me. After running graph init and selecting "subgraph" as a protocol it tries to download ABI for I don't know what. I assume it shouldn't, since I never specified the contract address? What's the flow here @incrypto32 ?

image
incrypto32 commented 1 week ago

Oops, i think i didn't check the graph init support just the codegen and build. I tested with an existing subgraph that i modified to use the new datasource. Thanks for testing it out @YaroShkvorets, i'll add the init support too.

incrypto32 commented 1 day ago

@YaroShkvorets just added the init command. Please re review

YaroShkvorets commented 6 hours ago
❯ ./bin/run init --skip-install --skip-git
 ›   Warning: @graphprotocol/graph-cli update available from 0.87.0 to 0.90.1.
 ›   Warning: In next major version, this flag will be removed. By default we will stop initializing a Git repository.
✔ Protocol · subgraph
✔ Subgraph slug · asdf
✔ Directory to create the subgraph in · asdf
? Subgraph network …
? Subgraph network …
? Subgraph network …
✔ Subgraph network · mainnet
✔ Source subgraph identifier · QmTZ8ejXJxRo7vDBS4uwqBeGoxLSWbhaA7oXa1RvxunLy7
✔ IPFS node to use for fetching subgraph manifest · https://api.thegraph.com/ipfs/api/v0
✔ Start Block · 0
  Generate subgraph
✖ Failed to create subgraph scaffold: Cannot read properties of undefined (reading 'length')
    TypeError: Cannot read properties of undefined (reading 'length')
YaroShkvorets commented 6 hours ago

Let's merge it @0237h , then let @incrypto32 polish out any bugs. There is a lot of overlap with what I'm doing so I don't want to keep this PR open much longer to avoid merge hell.