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

Queries for aggregations #5184

Merged
merged 30 commits into from
Feb 14, 2024
Merged

Queries for aggregations #5184

merged 30 commits into from
Feb 14, 2024

Conversation

lutter
Copy link
Collaborator

@lutter lutter commented Feb 1, 2024

This PR enables querying of aggregations through the GraphQL interface. It required a major rework of the GraphQL query infrastructure as prefetch now needs to translate from types in the API schema to types in the InputSchema as the concrete types for the aggregations do not exist in the API schema.

Before, we relied a lot on the fact that the API schema contained the same types as the input schema with the exact same names and structure. But conceptually, prefetch and query building deals with types from the input schema as that describes how data is ultimately stored in the database.

To try this out, deploy the aggregation-example subgraph that builds aggregations over ethereum block numbers as those are easy to check.

}

/// Return an `EntityType` that either references the object type `name`
/// or, if `name` refernces an aggregation, return the object type of
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// or, if `name` refernces an aggregation, return the object type of
/// or, if `name` references an aggregation, return the object type of

Small typo

@@ -2,5 +2,5 @@ mod prefetch;
mod query;
mod resolver;

pub use self::query::parse_subgraph_id;
//pub use self::query::parse_subgraph_id;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//pub use self::query::parse_subgraph_id;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Woops .. forgot to remove that. Done

@incrypto32
Copy link
Member

@lutter i was unable to test the aggregation-example subgraph, im getting graph-cli error, how did you get over it?

Error: Error in schema.graphql:

  Block:
  - Field 'id': Entity ids must be of type Bytes! or String!

  BlockTime:
  - Field 'id': Entity ids must be of type Bytes! or String!

  Group1:
  - Defined without @entity directive
  - Field 'id': Entity ids must be of type Bytes! or String!

@lutter
Copy link
Collaborator Author

lutter commented Feb 8, 2024

@lutter i was unable to test the aggregation-example subgraph, im getting graph-cli error, how did you get over it?

I totally forgot that I have this PR against graph-cli open and that I linked that in my local checkout. I just asked to have that merged and released to save people from that extra hoop. Would love to hear if you can get things working once that's out (or if you want to go through the whole trouble of linking a local checkout in)

Copy link
Member

@incrypto32 incrypto32 left a comment

Choose a reason for hiding this comment

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

Was able to test it out with the example subgraph with the CLI alpha version
0.68.0-alpha-20240208230340-9ea4027 LGTM

@lutter lutter force-pushed the lutter/agg-schema branch 2 times, most recently from f018c57 to a8d204f Compare February 13, 2024 23:57
We use 'order by timestamp' on the raw data to make sure that first and
last work correctly. But the name 'timestamp' was ambiguous as we select a
timestamp and the data table has one. The selected timestamp is the same
for all data points in the interval, whereas the timestamp from the data
table is the block's timestamp, which is what we need to sort by. This
change makes sure we sort by the timestamp from the data table as intended.
Change the block time for test blocks to 45 minutes so that block 2 is in a
different hour from block 0. In addition, make the query tests process
block 2 with no changes.

There's no other changes to the tests other than adapting them to the
additional processed block.
Previously, we missed adding the filters etc. to query fields that were
collections of aggregations
This required a major rework of the GraphQL query infrastructure as
prefetch now needs to translate from types in the API schema to types in
the InputSchema as the concrete types for the aggregations do not exist in
the API schema.

Before, we relied a lot on the fact that the API schema contained the same
types as the input schema with the exact same names and structure. But
conceptually, prefetch and query building deals with types from the input
schema as that describes how data is ultimately stored in the database.
The meaning of that is very murky, but it changes API schema and has been
there for a long time
@lutter
Copy link
Collaborator Author

lutter commented Feb 14, 2024

I just finished testing queries against the hosted service. The biggest changes this introduces for existing queries are:

  • In some subgraphs, the names of collections have changed because of the fix described in this issue AFAICT, that affects three subgraphs on the hosted service.
  • Some constructs that we used to copy from the subgraph schema to the API schema are now removed. Those are the schema directive, type extensions, and definition of scalar and union types. I also wanted to drop input object definitions, but there's one subgraph that uses that to pass a where filter in as a variable. Instead of dropping them, I wanted to make that a validation error, but that turned out trickier than I thought
  • There's a change in the response for one query that uses the nonsensical ordering described in issue [Bug] Disallow sorting by child fields that are arrays #5207

@lutter lutter merged commit 9c154cc into master Feb 14, 2024
7 checks passed
@lutter lutter deleted the lutter/agg-schema branch February 14, 2024 00:54
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.

2 participants