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

Added sorting cookbook page #365

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

marcusrein
Copy link
Member

Sorting cookbook draft PR added as per Simon.

@marcusrein marcusrein added the documentation Improvements or additions to documentation label May 1, 2023
Copy link
Member

@schmidsi schmidsi left a comment

Choose a reason for hiding this comment

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

Generally it is a very good cook-book topic. Although I think we should be very specific about the details and not only talk about the numerical value use-case.

title: GraphQL Sorting Strategies
---

## Sorting Entity IDs
Copy link
Member

Choose a reason for hiding this comment

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

I think the title is misleading. I suggest to use "Sort by IDs"


## Sorting Entity IDs

When creating subgraphs in The Graph, it's important to consider the type of ID used for your entities. This choice can have a significant impact on the performance and ease of use of your subgraph.
Copy link
Member

Choose a reason for hiding this comment

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

This is actually no a big consideration. As of now, IDs should always be Bytes.

Copy link
Member

Choose a reason for hiding this comment

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

Unless there is a good reason to use ID which translates to string. Examples might be traits or unique names.


When creating subgraphs in The Graph, it's important to consider the type of ID used for your entities. This choice can have a significant impact on the performance and ease of use of your subgraph.

If accurate sorting is desired, both Strings and Bytes for IDs are not optimal as the sorting is done non-sequentially which can lead to unexpected results. If attempting to sort by id of type "ID" (which is a string), the ordered sequence might look like this:
Copy link
Member

Choose a reason for hiding this comment

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

What is accurate? Only for numerical values, sorting by Bytes and String feels off. If the ID is a transactionHash or a string, that sorting is fine.

So I suggest to be clear here.

}
```

## Ideal Sorting Strategy of IDs
Copy link
Member

Choose a reason for hiding this comment

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

Again, this really depends on the use-case. So ideal for numerical values is not ideal for strings or bytes.

@azf20
Copy link
Contributor

azf20 commented May 2, 2024

@marcusrein @schmidsi checking on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants