graphprotocol / graphprotocol/graph-node

Allow where clause in subgraph queries to reference another field in type

Open
#4,332 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area/graphql area/subgraphs new feature Stale
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.