Skip to content

Commit

Permalink
[GraphQL/Cursor] Refactor Events Pagination (MystenLabs#15528)
Browse files Browse the repository at this point in the history
## Descriptions

This PR applies the various preceding abstractions (cursor and
pagination frameworks) to `Query.eventConnection`, and renames it to
`Query.events`.

Events also support more expressive filters than previous types that we
applied these frameworks to, in particular, they support filtering by
modules and types, so we introduce `TypeFilter` and `ModuleFilter`
(string) scalars as a new abstraction responsible for:

- Parsing cascading filters of this kind.
- Applying them as filters onto existing queries.

The parsing implementation has also been made to uniformly rely on
Move's parser for types and identifiers (previously it used Move's
parser for types, but string manipulation for package and module based
filters), which required exposing some more endpoints to Move's parser.

## Test Plan

Existing E2E tests for events pagination:

```

sui-graphql-e2e-tests$ cargo nextest run \
  -j 1 --features pg_integration         \
  -- event_connection/
```

Plus new unit tests for `type_filter` module:

```
sui-graphql-rpc$ cargo nextest run -- type_filter
```

## Stack
- MystenLabs#15467 
- MystenLabs#15470 
- MystenLabs#15471 
- MystenLabs#15472 
- MystenLabs#15473
- MystenLabs#15474 
- MystenLabs#15475 
- MystenLabs#15484 
- MystenLabs#15485
- MystenLabs#15519
- MystenLabs#15520
- MystenLabs#15521
- MystenLabs#15522
- MystenLabs#15523
- MystenLabs#15524
- MystenLabs#15525
- MystenLabs#15526
- MystenLabs#15527
- MystenLabs#15625
  • Loading branch information
amnn committed Jan 12, 2024
1 parent 985b8ca commit 37c3e47
Show file tree
Hide file tree
Showing 24 changed files with 961 additions and 684 deletions.
417 changes: 222 additions & 195 deletions crates/sui-graphql-e2e-tests/tests/event_connection/event_connection.exp

Large diffs are not rendered by default.

248 changes: 128 additions & 120 deletions crates/sui-graphql-e2e-tests/tests/event_connection/event_connection.move
Original file line number Diff line number Diff line change
Expand Up @@ -100,170 +100,178 @@ module Test::M2 {

//# create-checkpoint

//# run-graphql --variables A
//# run-graphql
{
eventConnection(
filter: {sender: $A}
) {
nodes {
sendingModule {
name
events(filter: {sender: "@{A}"}) {
edges {
cursor
node {
sendingModule {
name
}
type {
repr
}
sender {
address
}
json
bcs
}
type {
repr
}
sender {
address
}
json
bcs
}
}
}

//# run-graphql --variables A Test
//# run-graphql
{
eventConnection(
filter: {sender: $A, eventType: $Test}
) {
nodes {
sendingModule {
name
}
type {
repr
}
sender {
address
events(filter: {sender: "@{A}", eventType: "@{Test}"}) {
edges {
cursor
node {
sendingModule {
name
}
type {
repr
}
sender {
address
}
json
bcs
}
json
bcs
}
}
}

//# run-graphql --variables A
//# run-graphql
{
eventConnection(
filter: {sender: $A, eventType: "@{Test}::M1"}
) {
nodes {
sendingModule {
name
events(filter: {sender: "@{A}", eventType: "@{Test}::M1"}) {
edges {
cursor
node {
sendingModule {
name
}
type {
repr
}
sender {
address
}
json
bcs
}
type {
repr
}
sender {
address
}
json
bcs
}
}
}

//# run-graphql --variables A
//# run-graphql
{
eventConnection(
filter: {sender: $A, eventType: "@{Test}::M1::EventA"}
) {
nodes {
sendingModule {
name
}
type {
repr
}
sender {
address
events(filter: {sender: "@{A}", eventType: "@{Test}::M1::EventA"}) {
edges {
cursor
node {
sendingModule {
name
}
type {
repr
}
sender {
address
}
json
bcs
}
json
bcs
}
}
}

//# run-graphql --variables A
//# run-graphql
{
eventConnection(
filter: {sender: $A, eventType: "@{Test}::M1::EventB"}
) {
nodes {
sendingModule {
name
events(filter: {sender: "@{A}", eventType: "@{Test}::M1::EventB"}) {
edges {
cursor
node {
sendingModule {
name
}
type {
repr
}
sender {
address
}
json
bcs
}
type {
repr
}
sender {
address
}
json
bcs
}
}
}

//# run-graphql --variables A
//# run-graphql
{
eventConnection(
filter: {sender: $A, eventType: "@{Test}::M1::EventB<"}
) {
nodes {
sendingModule {
name
}
type {
repr
}
sender {
address
events(filter: {sender: "@{A}", eventType: "@{Test}::M1::EventB<"}) {
edges {
cursor
node {
sendingModule {
name
}
type {
repr
}
sender {
address
}
json
bcs
}
json
bcs
}
}
}

//# run-graphql --variables A
//# run-graphql
{
eventConnection(
filter: {sender: $A, eventType: "::M1"}
) {
nodes {
sendingModule {
name
events(filter: {sender: "@{A}", eventType: "::M1"}) {
edges {
cursor
node {
sendingModule {
name
}
type {
repr
}
sender {
address
}
json
bcs
}
type {
repr
}
sender {
address
}
json
bcs
}
}
}

//# run-graphql --variables A
//# run-graphql
{
eventConnection(
filter: {sender: $A, eventType: "@{Test}::"}
) {
nodes {
sendingModule {
name
}
type {
repr
}
sender {
address
events(filter: {sender: "@{A}", eventType: "@{Test}::"}) {
edges {
cursor
node {
sendingModule {
name
}
type {
repr
}
sender {
address
}
json
bcs
}
json
bcs
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 0
task 3 'create-checkpoint'. lines 41-41:
Checkpoint created: 1

task 4 'run-graphql'. lines 43-62:
task 4 'run-graphql'. lines 43-60:
Response: {
"data": {
"eventConnection": {
"events": {
"nodes": [
{
"sendingModule": {
Expand All @@ -41,10 +41,10 @@ Response: {
}
}

task 5 'run-graphql'. lines 64-83:
task 5 'run-graphql'. lines 62-79:
Response: {
"data": {
"eventConnection": {
"events": {
"nodes": [
{
"sendingModule": {
Expand All @@ -66,28 +66,28 @@ Response: {
}
}

task 6 'run-graphql'. lines 85-104:
task 6 'run-graphql'. lines 81-98:
Response: {
"data": {
"eventConnection": {
"events": {
"nodes": []
}
}
}

task 7 'run-graphql'. lines 106-125:
task 7 'run-graphql'. lines 100-117:
Response: {
"data": {
"eventConnection": {
"events": {
"nodes": []
}
}
}

task 8 'run-graphql'. lines 127-146:
task 8 'run-graphql'. lines 119-136:
Response: {
"data": {
"eventConnection": {
"events": {
"nodes": [
{
"sendingModule": {
Expand Down
Loading

0 comments on commit 37c3e47

Please sign in to comment.