Skip to content

Commit

Permalink
[GraphQL] [indexer] split type field into different components (Myste…
Browse files Browse the repository at this point in the history
…nLabs#16851)

For event and object types stored in the indexer tables, this PR stores
the `package`, `module` and `name` of the `StructTag` in addition to the
full type information. With this change all the queries we do to filter
by type in graphql will be exact match instead of using `LIKE`.

I chose to go with still keeping the full type field for backward
compatibility (since indexer and gql are on different release
schedules), testability (so we can easily test performance difference
using the old and new way against the same db) and simplicity (so we
don't need to worry too much about type params).

Existing graphql tests and added indexer ingestion tests.

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration
  • Loading branch information
emmazzz authored and gegaowp committed May 2, 2024
1 parent 7915d84 commit 2035c58
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 120 deletions.
18 changes: 14 additions & 4 deletions crates/sui-graphql-e2e-tests/tests/objects/filter_by_type.exp
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,19 @@ Response: {

task 16 'run-graphql'. lines 180-196:
Response: {
"data": {
"objects": {
"edges": []
"data": null,
"errors": [
{
"message": "Failed to parse \"String\": Invalid filter, expected: package[::module[::type[<type_params>]]] or primitive type (occurred while parsing \"ObjectFilter\")",
"locations": [
{
"line": 3,
"column": 19
}
],
"path": [
"objects"
]
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
}

//# run-graphql
# Should run successfully but return an empty result
# Primitive types are invalid type filters for objects
{
objects(filter: {type: "u64"}) {
edges {
Expand Down
11 changes: 10 additions & 1 deletion crates/sui-graphql-rpc/src/types/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ impl Event {
}

if let Some(type_) = &filter.event_type {
query = type_.apply(query, events::dsl::event_type);
query = type_.apply(
query,
events::dsl::event_type,
events::dsl::event_type_package,
events::dsl::event_type_module,
events::dsl::event_type_name,
);
}

query
Expand Down Expand Up @@ -259,6 +265,9 @@ impl Event {
event_type: native_event
.type_
.to_canonical_string(/* with_prefix */ true),
event_type_package: native_event.type_.address.to_vec(),
event_type_module: native_event.type_.module.to_string(),
event_type_name: native_event.type_.name.to_string(),
bcs: native_event.contents.clone(),
timestamp_ms: stored_tx.timestamp_ms,
};
Expand Down
8 changes: 7 additions & 1 deletion crates/sui-graphql-rpc/src/types/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,13 @@ impl ObjectFilter {
}

if let Some(type_) = &self.type_ {
return type_.apply_raw(query, "object_type");
return type_.apply_raw(
query,
"object_type",
"object_type_package",
"object_type_module",
"object_type_name",
);
}

query
Expand Down
Loading

0 comments on commit 2035c58

Please sign in to comment.