Skip to content

Commit

Permalink
[graphql] Add support for clever error resolution in graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
tzakian committed Apr 25, 2024
1 parent 96de7fd commit 515fb91
Show file tree
Hide file tree
Showing 7 changed files with 747 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

248 changes: 248 additions & 0 deletions crates/sui-graphql-e2e-tests/tests/errors/clever_errors.exp

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions crates/sui-graphql-e2e-tests/tests/errors/clever_errors.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --protocol-version 39 --addresses P0=0x0 P1=0x0 --accounts A --simulator

//# publish --upgradeable --sender A
module P0::m {
#[error]
const ImAU8: u8 = 0;

#[error]
const ImAU16: u16 = 0;

#[error]
const ImAU32: u32 = 0;

#[error]
const ImAU64: u64 = 0;

#[error]
const ImAU128: u128 = 0;

#[error]
const ImAU256: u256 = 0;

#[error]
const ImABool: bool = true;

#[error]
const ImAAddress: address = @0;

#[error]
const ImAString: vector<u8> = b"This is a string";

#[error]
const ImNotAString: vector<u8> = vector[1,2,3,4,5];

public fun callU8() {
abort ImAU8
}

public fun callU16() {
abort ImAU16
}

public fun callU32() {
abort ImAU32
}

public fun callU64() {
abort ImAU64
}

public fun callU128() {
abort ImAU128
}

public fun callU256() {
abort ImAU256
}

public fun callAddress() {
abort ImAAddress
}

public fun callString() {
abort ImAString
}

public fun callBytevec() {
abort ImNotAString
}

public fun normalAbort() {
abort 0
}

public fun assertLineNo() {
assert!(false);
}
}

//# run P0::m::callU8

//# run P0::m::callU16

//# run P0::m::callU32

//# run P0::m::callU64

//# run P0::m::callU128

//# run P0::m::callU256

//# run P0::m::callAddress

//# run P0::m::callString

//# run P0::m::callBytevec

//# run P0::m::normalAbort

//# run P0::m::assertLineNo

//# create-checkpoint

//# run-graphql
{
transactionBlocks(last: 11) {
nodes {
effects {
status
errors
}
}
}
}

//# upgrade --package P0 --upgrade-capability 1,1 --sender A
// Upgrade the module with new error values but using the same constant names
// (etc) to make sure we properly resolve the module location for clever
// errors.
module P0::m {
#[error]
const ImAU8: u8 = 1;

#[error]
const ImAU16: u16 = 1;

#[error]
const ImAU32: u32 = 1;

#[error]
const ImAU64: u64 = 1;

#[error]
const ImAU128: u128 = 1;

#[error]
const ImAU256: u256 = 1;

#[error]
const ImABool: bool = false;

#[error]
const ImAAddress: address = @1;

#[error]
const ImAString: vector<u8> = b"This is a string in v2";

#[error]
const ImNotAString: vector<u8> = vector[1,2,3,4,5, 6];

public fun callU8() {
abort ImAU8
}

public fun callU16() {
abort ImAU16
}

public fun callU32() {
abort ImAU32
}

public fun callU64() {
abort ImAU64
}

public fun callU128() {
abort ImAU128
}

public fun callU256() {
abort ImAU256
}

public fun callAddress() {
abort ImAAddress
}

public fun callString() {
abort ImAString
}

public fun callBytevec() {
abort ImNotAString
}

public fun normalAbort() {
abort 0
}

public fun assertLineNo() {
assert!(false);
}
}

//# run P0::m::callU8

//# run P0::m::callU16

//# run P0::m::callU32

//# run P0::m::callU64

//# run P0::m::callU128

//# run P0::m::callU256

//# run P0::m::callAddress

//# run P0::m::callString

//# run P0::m::callBytevec

//# run P0::m::normalAbort

//# run P0::m::assertLineNo

//# create-checkpoint

//# run-graphql
{
transactionBlocks(last: 9) {
nodes {
effects {
status
errors
}
}
}
}
Loading

0 comments on commit 515fb91

Please sign in to comment.