# Proposal: Additional query support

**URL:** <https://forum.thegraph.com/t/proposal-additional-query-support/2049>\
**Category:** Questions & Feedback\
**Created:** [June 2, 2021, 8:59pm UTC](https://forum.thegraph.com/t/proposal-additional-query-support/2049 "2021-06-02T20:59:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![huangkuan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/huangkuan/32/973_2.png) [@huangkuan](https://forum.thegraph.com/u/huangkuan)\
**Post date:** [June 2, 2021, 8:59pm UTC](https://forum.thegraph.com/t/proposal-additional-query-support/2049/1 "2021-06-02T20:59:04Z")

</div>

Hi @adamfuller

As we are going through different use cases for building analytics applications on The Graph, we are running into some limitations on the queries currently provided. We’d like to be able to do something like:

1. Filtering data by nested field

```auto
{
  deposits( where: {reserve:{symbol:"DAI"}}) {
    reserve {
      symbol
    }
    amount
    timestamp
  }
}

```

1. Sorting data by nested field

```auto
{
  deposits(
    orderBy:reserve.symbol
  ) {
    reserve {
      symbol
    }
    amount
    timestamp
  }
}

```

1. Sorting data by multiple fields

```auto
{
  deposits(
    orderBy:timestamp
    orderDirection:asc
    orderBy:amount
    orderDirection:desc
  ) {
    reserve {
      symbol
    }
    amount
    timestamp
  }
}

```

1. Grouping data by different fields.
2. Math, string and array operators

---

<div class="post-metadata">

**Author:** ![adamfuller](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@adamfuller](https://forum.thegraph.com/u/adamfuller)\
**Post date:** [June 7, 2021, 10:09am UTC](https://forum.thegraph.com/t/proposal-additional-query-support/2049/2 "2021-06-07T10:09:35Z")

</div>

Hi @huangkuan! Thanks, these are great ideas - we are hoping to improve the query planner (1,2,3), and Grouping data is definitely important for analytics use cases.  
Can you give a bit more detail on what you mean by Math, string and array operators?

---

<div class="post-metadata">

**Author:** ![huangkuan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/huangkuan/32/973_2.png) [@huangkuan](https://forum.thegraph.com/u/huangkuan)\
**Post date:** [June 7, 2021, 3:36pm UTC](https://forum.thegraph.com/t/proposal-additional-query-support/2049/3 "2021-06-07T15:36:38Z")

</div>

1,2,3 are definitely more important. The sooner this can be solved, the sooner we can rely less on an intermediate data layer.

Using the below data structure as an example:

```auto
{
  deposits( where: {reserve:{symbol:"DAI"}}) {
    reserve {
      symbol
    }
    amount
    timestamp
  }
}

```

A. `amount` stores the amount of tokens in 18 decimals. When I am displaying this value in a table, I want to get rid of the decimals. That would require a “divide” operator.

B. I want to be able to display `amount` and `symbol` in one field. That would require a string appending operator that connects both strings.

---

<div class="post-metadata">

**Author:** ![That3Percent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/that3percent/32/62_2.png) [@That3Percent](https://forum.thegraph.com/u/That3Percent)\
**Post date:** [June 14, 2021, 9:56pm UTC](https://forum.thegraph.com/t/proposal-additional-query-support/2049/4 "2021-06-14T21:56:34Z")

</div>

1, 2, and 3 seem like great additions.

For 4 and 5 I think a client-side solution is preferable. There is almost no end to the kinds of data formatting and pre-processing that one would like to be able to do and pushing all of those to the server is an exercise in futility. The turnaround for a new formatting option to be pushed through the protocol would very high (months?), and there are established patterns for displaying formatted data on the client which can be tested in minutes instead.

It’s been a while since I used WPF or React, but the way that one would normally achieve this would be to have a custom component that rendered the data binding in a particular way. Here are some examples: [Formatting dates and numbers in React | Building SPAs](https://www.carlrippon.com/formatting-dates-and-numbers-in-react/)

---

<div class="post-metadata">

**Author:** ![pandichef](https://avatars.discourse-cdn.com/v4/letter/p/f05b48/32.png) [@pandichef](https://forum.thegraph.com/u/pandichef)\
**Post date:** [August 13, 2021, 11:03pm UTC](https://forum.thegraph.com/t/proposal-additional-query-support/2049/6 "2021-08-13T23:03:56Z")

</div>

I’m not sure I agree in general. Any kind of aggregation should be done server-side. For example, say I have this entity:

```auto
type Price @entity {
  id: ID!
  timestamp: BigInt!
  priceReturnA: BigDecimal!
  priceReturnB: BigDecimal!
}

```

and say this entity has 10GB worth of data. Now, say I want the correlation between `priceReturnA` and `priceReturnB`. The only sensible approach would be to compute the correlation on the server and send the result to the client.

See: [Postgres](https://www.postgresql.org/docs/9.4/functions-aggregate.html)

---

<div class="post-metadata">

**Author:** ![That3Percent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.thegraph.com/that3percent/32/62_2.png) [@That3Percent](https://forum.thegraph.com/u/That3Percent)\
**Post date:** [August 13, 2021, 11:22pm UTC](https://forum.thegraph.com/t/proposal-additional-query-support/2049/7 "2021-08-13T23:22:09Z")

</div>

That sounds pretty contrived.
