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

Breaking up creating subgraph flow #811

Merged
merged 11 commits into from
Dec 4, 2024
Merged

Conversation

idalithb
Copy link
Contributor

@idalithb idalithb commented Nov 5, 2024

  • Creating a Subgraph page is now a folder containing: install-the-cli; subgraph-manifest; ql-schema; assemblyscript-mappings; advanced
  • install-the-cli & ql-schema have content with some feedback implemented
  • ALL pages need detailed edits moving forward

Copy link
Contributor

@lutter lutter left a comment

Choose a reason for hiding this comment

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

Splitting up the 'create subgraph' docs this way makes a lot of sense to me. I left a lot of comments on two of the files for places that need more work; I think the other files also need an in-depth review, but those two have already taken quite a bit of time, and we should schedule that one file at a time, but that shouldn't hold up these changes.


The [Graph CLI](https://github.com/graphprotocol/graph-tooling/tree/main/packages/cli) is a command-line interface that facilitates developers' commands for The Graph. It processes a [subgraph manifest](/creating-a-subgraph/subgraph-manifest/) and compiles the [mappings](/creating-a-subgraph/assemblyscript-mappings/) to create a ready-to-use version of the subgraph.

You need The Graph CLI to build and deploy a subgraph.
Copy link
Contributor

Choose a reason for hiding this comment

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

If you go with my suggestion, this becomes redundant


### Install the Graph CLI

The Graph CLI is written in TypeScript, and you must have `node` and either `npm` or `yarn` installed to use it. Check for the [most recent](https://github.com/graphprotocol/graph-tooling/releases?q=%40graphprotocol%2Fgraph-cli&expanded=true) CLI version.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is something that devs with more Javascript experience should weigh in on: we should tell people how to install these things, incuding actual commands to run, for popular platforms, or link to the instructions upstream. As somebody who has little JS experience, I always found these steps very annoying and intimidating.

I've also been using pnpm instead of yarn lately, and it seems nicer/faster. We should have a set of tools that we recommend and where we have good instructions for how to install them, and just mention the other ones.

But all this needs input from people who actually know what they are doing with JavaScript (not me)


- This `graph init` command can also create a subgraph in Subgraph Studio by passing in `--product subgraph-studio`.

- If you already have a smart contract deployed to your preferred network, you can bootstrap a new subgraph from that contract to get started.
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of a bulleted list, I would just make this a paragraph. I would just say that users can create a new subgraph from an existing contract or an example subgraph, and the the following subsections explain the details. I am not sure what the --product subgraph-studio flag is trying to tell me here, and it raises the question of what happens when I don't include that.

Not sure who's best equipped to answer that, either studio folks or Graph CLI devs?


- The [example subgraph](https://github.com/graphprotocol/example-subgraph) is based on the Gravity contract by Dani Grant, which manages user avatars and emits `NewGravatar` or `UpdateGravatar` events whenever avatars are created or updated.

- The subgraph handles these events by writing `Gravatar` entities to the Graph Node store and ensuring these are updated according to the events.
Copy link
Contributor

Choose a reason for hiding this comment

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

That's more for devrel: we should have a better example subgraph than the Gravatar. The example should show off some best practices, and be heavily commented and explain what the various constructs do and in what situation they are needed.

- All queries will be made against the data model defined in the subgraph schema and the entities indexed by the subgraph. As a result, it is good to define the subgraph schema in a way that matches the needs of your dapp.
- It may be useful to imagine entities as "objects containing data", rather than as events or functions.
- You define entity types in `schema.graphql`, and Graph Node will generate top-level fields for querying single instances and collections of that entity type.
- Each type that should be an entity is required to be annotated with an `@entity` directive.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since spec version 1.1.0, types can also have a @aggregation annotation instead of @entity. This section needs to be rewritten to better reflect what kinds of types can be defined and how they work.

Feel free to hound me to provide something there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lutter Will do when I start detailed edits 😃

- Mutability comes at a price, so for entity types that will never be modified, such as those containing data extracted verbatim from the chain, it is recommended to mark them as immutable with `@entity(immutable: true)`.
- If changes happen in the same block in which the entity was created, then mappings can make changes to immutable entities. Immutable entities are much faster to write and to query so they should be used whenever possible.

#### Good Example
Copy link
Contributor

Choose a reason for hiding this comment

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

This section was written as a bit of a knee-jerk reaction to people creating lots of subgraphs that just stored events. I am not sure we need to give this example that much room.


Each entity must have an `id` field, which must be of type `Bytes!` or `String!`. It is generally recommended to use `Bytes!`, unless the `id` contains human-readable text, since entities with `Bytes!` id's will be faster to write and query as those with a `String!` `id`. The `id` field serves as the primary key, and needs to be unique among all entities of the same type. For historical reasons, the type `ID!` is also accepted and is a synonym for `String!`.

For some entity types the `id` is constructed from the id's of two other entities; that is possible using `concat`, e.g., `let id = left.id.concat(right.id) ` to form the id from the id's of `left` and `right`. Similarly, to construct an id from the id of an existing entity and a counter `count`, `let id = left.id.concatI32(count)` can be used. The concatenation is guaranteed to produce unique id's as long as the length of `left` is the same for all such entities, for example, because `left.id` is an `Address`.
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to make it clearer that we are talking about id's of type Bytes here.

@idalithb idalithb marked this pull request as ready for review November 27, 2024 19:19
@idalithb idalithb requested a review from a team as a code owner November 27, 2024 19:19
Copy link
Contributor

@MichaelMacaulay MichaelMacaulay left a comment

Choose a reason for hiding this comment

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

LGTM - amazing work!

@idalithb idalithb merged commit d4e3588 into main Dec 4, 2024
4 checks passed
@idalithb idalithb deleted the breaking-up-creating-subgraph-flow branch December 4, 2024 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants