Skip to content

Commit

Permalink
[GraphQL] Remove reference to ID in WIP Schema (MystenLabs#14628)
Browse files Browse the repository at this point in the history
## Description

Reflecting proposed changed to draft schema in MystenLabs#14627. Cleans things up
slightly so we can design and implement the other aspects of the API
first and then add `ID`s on top, along with `Query.node` as a follow-up.

## Test Plan

```
sui-graphql-rpc$ cargo nextest run
```
  • Loading branch information
amnn authored Nov 2, 2023
1 parent e4fa2a4 commit 88d62fe
Show file tree
Hide file tree
Showing 13 changed files with 5 additions and 48 deletions.
4 changes: 0 additions & 4 deletions crates/sui-graphql-rpc/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
> }
> coinConnection {
> nodes {
> id
> asMoveObject {
> contents {
> type {
Expand Down Expand Up @@ -465,7 +464,6 @@
> ) {
> coinConnection(last: 3, before: "0x13034947") {
> nodes {
> id
> balance
> }
> pageInfo {
Expand Down Expand Up @@ -701,7 +699,6 @@
> }
> ) {
> nodes {
> id
> sendingModuleId {
> name
> package {
Expand Down Expand Up @@ -938,7 +935,6 @@
> }
> stakeConnection {
> nodes {
> id
> status
> principal
> estimatedReward
Expand Down
1 change: 0 additions & 1 deletion crates/sui-graphql-rpc/examples/address/address.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
}
coinConnection {
nodes {
id
asMoveObject {
contents {
type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
) {
coinConnection(last: 3, before: "0x13034947") {
nodes {
id
balance
}
pageInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
}
) {
nodes {
id
sendingModuleId {
name
package {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
}
stakeConnection {
nodes {
id
status
principal
estimatedReward
Expand Down
6 changes: 0 additions & 6 deletions crates/sui-graphql-rpc/schema/current_progress_schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ input CheckpointId {
}

type Coin {
id: ID!
"""
Balance of the coin object
"""
Expand Down Expand Up @@ -271,7 +270,6 @@ type Epoch {
}

type Event {
id: ID!
"""
Package id and module name of Move module that the event was emitted in
"""
Expand Down Expand Up @@ -919,10 +917,6 @@ type ServiceConfig {
}

type Stake {
"""
Stake object address
"""
id: ID!
"""
The estimated reward for this stake object, computed as the
value of multiplying the principal value with the ratio between the initial stake rate and the current rate
Expand Down
17 changes: 2 additions & 15 deletions crates/sui-graphql-rpc/src/context_data/db_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ use crate::{
validator_set::ValidatorSet,
},
};
use async_graphql::{
connection::{Connection, Edge},
ID,
};
use async_graphql::connection::{Connection, Edge};
use diesel::{
pg::Pg,
query_builder::{AstPass, BoxedSelectStatement, FromClause, QueryFragment, QueryId},
Expand Down Expand Up @@ -1381,7 +1378,7 @@ impl PgManager {
Coin::try_from(stored_obj)
.map_err(|e| eprintln!("Error converting object to coin: {:?}", e))
.ok()
.map(|coin| Edge::new(coin.id.to_string(), coin))
.map(|coin| Edge::new(coin.move_obj.native_object.id().to_string(), coin))
}));
Ok(Some(connection))
} else {
Expand Down Expand Up @@ -1627,7 +1624,6 @@ impl PgManager {
connection.edges.extend(results.into_iter().map(|e| {
let cursor = String::from(e.id);
let event = Event {
id: ID::from(cursor.clone()),
sending_module_id: Some(MoveModuleId {
package: SuiAddress::from_array(**e.package_id),
name: e.transaction_module.to_string(),
Expand Down Expand Up @@ -2047,18 +2043,10 @@ impl TryFrom<StoredObject> for Coin {
type Error = Error;

fn try_from(o: StoredObject) -> Result<Self, Self::Error> {
let object_id = SuiAddress::try_from(o.object_id.clone()).map_err(|_| {
Error::Internal(format!(
"Failed to convert object_id {:?} to SuiAddress",
o.object_id
))
})?;
let id = ID(object_id.to_string());
let balance = o.coin_balance.map(BigInt::from);
let native_object: SuiObject = o.try_into()?;

Ok(Self {
id,
balance,
move_obj: MoveObject { native_object },
})
Expand All @@ -2078,7 +2066,6 @@ impl From<SuiStake> for Stake {
};

Stake {
id: ID(value.staked_sui_id.to_string()),
active_epoch_id: Some(value.stake_active_epoch),
estimated_reward: reward,
principal: Some(value.principal.into()),
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-graphql-rpc/src/types/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ pub(crate) struct CheckpointId {
#[derive(Clone, Debug, PartialEq, Eq, SimpleObject)]
#[graphql(complex)]
pub(crate) struct Checkpoint {
// id: ID1
/// A 32-byte hash that uniquely identifies the checkpoint contents, encoded in Base58.
/// This hash can be used to verify checkpoint contents by checking signatures against the committee,
/// Hashing contents to match digest, and checking that the previous checkpoint digest matches.
/// Hashing contents to match digest, and checking that the previous checkpoint digest matches.
pub digest: String,
/// This checkpoint's position in the total order of finalised checkpoints, agreed upon by consensus.
pub sequence_number: u64,
Expand Down
8 changes: 2 additions & 6 deletions crates/sui-graphql-rpc/src/types/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ use async_graphql::*;

use sui_types::coin::Coin as NativeSuiCoin;

#[derive(Clone, SimpleObject)]
#[graphql(complex)]
#[derive(Clone)]
pub(crate) struct Coin {
pub id: ID,
#[graphql(skip)]
pub move_obj: MoveObject,
#[graphql(skip)]
pub balance: Option<BigInt>,
}

#[ComplexObject]
#[Object]
impl Coin {
/// Balance of the coin object
async fn balance(&self) -> Option<BigInt> {
Expand Down
1 change: 0 additions & 1 deletion crates/sui-graphql-rpc/src/types/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use super::{

#[derive(SimpleObject)]
pub(crate) struct Event {
pub id: ID,
/// Package id and module name of Move module that the event was emitted in
pub sending_module_id: Option<MoveModuleId>,
/// Package, module, and type of the event
Expand Down
2 changes: 0 additions & 2 deletions crates/sui-graphql-rpc/src/types/move_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ impl MoveObject {
}

Some(Coin {
id: ID::from(self.native_object.id().to_string()),
move_obj: self.clone(),
balance: None, // Defer to resolver
})
Expand Down Expand Up @@ -105,7 +104,6 @@ impl MoveObject {
};

Ok(Some(Stake {
id: ID(stake.id().to_string()),
active_epoch_id: Some(stake.activation_epoch()),
estimated_reward: None,
principal: Some(BigInt::from(stake.principal())),
Expand Down
2 changes: 0 additions & 2 deletions crates/sui-graphql-rpc/src/types/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub(crate) enum StakeStatus {
#[derive(Clone, PartialEq, Eq, SimpleObject)]
#[graphql(complex)]
pub(crate) struct Stake {
/// Stake object address
pub id: ID,
/// The epoch at which the stake became active
#[graphql(skip)]
pub active_epoch_id: Option<u64>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ input CheckpointId {
}

type Coin {
id: ID!
"""
Balance of the coin object
"""
Expand Down Expand Up @@ -275,7 +274,6 @@ type Epoch {
}

type Event {
id: ID!
"""
Package id and module name of Move module that the event was emitted in
"""
Expand Down Expand Up @@ -923,10 +921,6 @@ type ServiceConfig {
}

type Stake {
"""
Stake object address
"""
id: ID!
"""
The estimated reward for this stake object, computed as the
value of multiplying the principal value with the ratio between the initial stake rate and the current rate
Expand Down

0 comments on commit 88d62fe

Please sign in to comment.