graphprotocol / graphprotocol/graph-node
Allow where clause in subgraph queries to reference another field in type
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.2k
- Forks
- 1.1k
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 1
Description
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Currently, the where clause in a subgraph query only allows you to pass values to it that are of the type of the field being filtered against.
ex:
query Indexers {
indexers(where: { stakedTokens: 0 }) {
id
stakedTokens
lockedTokens
}
}
Where: stakedTokens is of type BigInt and the value passed (0 in the example) must also be a BigInt.
What is the expected behavior?
It would be very helpful if the where clause was able to compare two fields against each other to filter results.
ex:
query Indexers {
indexers(where: { stakedTokens: {indexer? me? this?}.lockedTokens }) {
id
stakedTokens
lockedTokens
}
}
Mapping down to sql, this would look (something like):
SELECT id, staked_tokens, locked_tokens FROM indexer WHERE staked_tokens = locked_tokens;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how GraphQL subgraph where clauses are parsed and translated to SQL; the issue names no implementation files or tests. Define the field-to-field comparison syntax and identify the query and database layers that would need support, then add coverage for comparing stakedTokens with lockedTokens.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, rust, sql
- Domain
- api, backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100