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

feat: blob exists query #2300

Merged
merged 17 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,12 @@ type Query {
"""
id: BlobId!
): Blob
blobExists(
Copy link
Member

Choose a reason for hiding this comment

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

this shouldn't require any changes to the schema

you can just add a method to fuel-core-client that does the same kind of existence query as the ts-sdk

Copy link
Member

Choose a reason for hiding this comment

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

Screenshot 2024-10-05 at 11 01 20 AM

When you query a blob by id and ask for the id back, it will return null if it doesn't exist

"""
ID of the Blob
"""
id: BlobId!
): Boolean!
block(
"""
ID of the block
Expand Down
12 changes: 11 additions & 1 deletion crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ use pagination::{
};
use schema::{
balance::BalanceArgs,
blob::BlobByIdArgs,
blob::{
BlobByIdArgs,
BlobExistsArgs,
},
block::BlockByIdArgs,
coins::CoinByIdArgs,
contract::ContractByIdArgs,
Expand Down Expand Up @@ -887,6 +890,13 @@ impl FuelClient {
Ok(blob)
}

/// Check whether a blob with ID exists
pub async fn blob_exists(&self, id: BlobId) -> io::Result<bool> {
let query =
schema::blob::BlobExistsQuery::build(BlobExistsArgs { id: id.into() });
Ok(self.query(query).await?.blob_exists)
}

/// Retrieve multiple blocks
pub async fn blocks(
&self,
Expand Down
17 changes: 17 additions & 0 deletions crates/client/src/client/schema/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,20 @@ pub struct Blob {
pub id: BlobId,
pub bytecode: HexString,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct BlobExistsArgs {
pub id: BlobId,
}

/// GraphQL query to check if a Blob exists by its ID
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
schema_path = "./assets/schema.sdl",
graphql_type = "Query",
variables = "BlobExistsArgs"
)]
pub struct BlobExistsQuery {
#[arguments(id: $id)]
pub blob_exists: bool,
}
9 changes: 9 additions & 0 deletions crates/fuel-core/src/schema/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@ impl BlobQuery {
})
.into_api_result()
}

async fn blob_exists(
&self,
ctx: &Context<'_>,
#[graphql(desc = "ID of the Blob")] id: BlobId,
) -> async_graphql::Result<bool> {
let query = ctx.read_view()?;
query.blob_exists(id.0).map_err(|e| e.into())
}
}
Loading