Skip to content

Commit 4940329

Browse files
committed
GraphQL: improve documentation
1 parent 0837a0a commit 4940329

File tree

2 files changed

+138
-8
lines changed

2 files changed

+138
-8
lines changed

node/native/src/graphql/mod.rs

Lines changed: 136 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ impl From<ConversionError> for Error {
104104
///
105105
/// This is used to share state between the GraphQL queries and mutations.
106106
///
107-
/// The caching used here is only valid for the lifetime of the context
108-
/// i.e. for one request which is the goal as we can have multiple sources for one request.
107+
/// The caching used here is only valid for the lifetime of the context i.e. for
108+
/// one request which is the goal as we can have multiple sources for one
109+
/// request.
109110
/// This optimizes the number of request to the state machine
110-
pub(crate) struct Context {
111+
pub struct Context {
111112
rpc_sender: RpcSender,
112113
account_loader: AccountLoader,
113114
// Caches
@@ -257,10 +258,48 @@ impl BestChain {
257258
}
258259

259260
#[derive(Clone, Copy, Debug)]
260-
struct Query;
261+
pub struct Query;
261262

263+
/// GraphQL Query endpoints exposed by the Mina node
264+
///
265+
/// # Available Queries:
266+
///
267+
/// ## Account Management
268+
/// - `account` - Retrieve account information for a public key
269+
/// - `current_snark_worker` - Get information about the current SNARK worker
270+
///
271+
/// ## Blockchain State
272+
/// - `sync_status` - Get the synchronization status of the node
273+
/// - `best_chain` - Retrieve the best chain of blocks
274+
/// - `block` - Get a specific block by hash or height
275+
/// - `genesis_block` - Retrieve the genesis block
276+
/// - `genesis_constants` - Get genesis configuration constants
277+
/// - `daemon_status` - Get the daemon status information
278+
///
279+
/// ## Transaction Pool
280+
/// - `pooled_user_commands` - Query pending user commands in the transaction
281+
/// pool
282+
/// - `pooled_zkapp_commands` - Query pending zkApp commands in the transaction
283+
/// pool
284+
/// - `transaction_status` - Check the status of a transaction
285+
///
286+
/// ## SNARK Pool
287+
/// - `snark_pool` - Get completed SNARK jobs
288+
/// - `pending_snark_work` - Get pending SNARK work items
289+
///
290+
/// ## Network Information
291+
/// - `network_id` - Get the chain-agnostic network identifier
292+
/// - `version` - Get the node version (git commit hash)
262293
#[juniper::graphql_object(context = Context)]
263294
impl Query {
295+
/// Retrieve account information for a given public key
296+
///
297+
/// # Arguments
298+
/// - `public_key`: Base58-encoded public key
299+
/// - `token`: Optional token ID (defaults to MINA token if not provided)
300+
///
301+
/// # Returns
302+
/// Account information including balance, nonce, delegate, and other fields
264303
async fn account(
265304
public_key: String,
266305
token: Option<String>,
@@ -287,6 +326,10 @@ impl Query {
287326
.try_into()?)
288327
}
289328

329+
/// Get the current synchronization status of the node
330+
///
331+
/// # Returns
332+
/// One of: CONNECTING, LISTENING, OFFLINE, BOOTSTRAP, SYNCED, CATCHUP
290333
async fn sync_status(context: &Context) -> juniper::FieldResult<SyncStatus> {
291334
let state: RpcSyncStatsGetResponse = context
292335
.rpc_sender
@@ -308,6 +351,13 @@ impl Query {
308351
}
309352
}
310353

354+
/// Retrieve the best chain of blocks from the transition frontier
355+
///
356+
/// # Arguments
357+
/// - `max_length`: Maximum number of blocks to return
358+
///
359+
/// # Returns
360+
/// List of blocks in the best chain, ordered from newest to oldest
311361
async fn best_chain(
312362
max_length: i32,
313363
context: &Context,
@@ -324,12 +374,20 @@ impl Query {
324374
.collect::<Result<Vec<_>, _>>()?)
325375
}
326376

377+
/// Get daemon status information including chain ID and configuration
378+
///
379+
/// # Returns
380+
/// Daemon status with chain ID, configuration, and other metadata
327381
async fn daemon_status(
328382
_context: &Context,
329383
) -> juniper::FieldResult<constants::GraphQLDaemonStatus> {
330384
Ok(constants::GraphQLDaemonStatus)
331385
}
332386

387+
/// Retrieve genesis configuration constants
388+
///
389+
/// # Returns
390+
/// Genesis constants including protocol parameters and constraints
333391
async fn genesis_constants(
334392
context: &Context,
335393
) -> juniper::FieldResult<constants::GraphQLGenesisConstants> {
@@ -346,6 +404,15 @@ impl Query {
346404
)?)
347405
}
348406

407+
/// Check the status of a transaction
408+
///
409+
/// # Arguments
410+
/// - `payment`: Base64-encoded signed command (mutually exclusive with
411+
/// zkapp_transaction)
412+
/// - `zkapp_transaction`: Base64-encoded zkApp command (mutually exclusive with payment)
413+
///
414+
/// # Returns
415+
/// Transaction status (PENDING, INCLUDED, or UNKNOWN)
349416
async fn transaction_status(
350417
payment: Option<String>,
351418
zkapp_transaction: Option<String>,
@@ -381,7 +448,14 @@ impl Query {
381448
Ok(GraphQLTransactionStatus::from(res))
382449
}
383450

384-
/// Retrieve a block with the given state hash or height, if contained in the transition frontier
451+
/// Retrieve a block with the given state hash or height from the transition frontier
452+
///
453+
/// # Arguments
454+
/// - `height`: Block height (mutually exclusive with state_hash)
455+
/// - `state_hash`: Block state hash (mutually exclusive with height)
456+
///
457+
/// # Returns
458+
/// Block data including transactions, SNARK jobs, and metadata
385459
async fn block(
386460
height: Option<i32>,
387461
state_hash: Option<String>,
@@ -488,6 +562,10 @@ impl Query {
488562
.collect::<Result<Vec<_>, _>>()?)
489563
}
490564

565+
/// Retrieve the genesis block
566+
///
567+
/// # Returns
568+
/// The genesis block data
491569
async fn genesis_block(context: &Context) -> juniper::FieldResult<GraphQLBlock> {
492570
let block = context
493571
.rpc_sender
@@ -502,6 +580,10 @@ impl Query {
502580
})?)
503581
}
504582

583+
/// Get completed SNARK jobs from the SNARK pool
584+
///
585+
/// # Returns
586+
/// List of completed SNARK jobs with proofs and fees
505587
async fn snark_pool(context: &Context) -> juniper::FieldResult<Vec<GraphQLSnarkJob>> {
506588
let jobs: RpcSnarkPoolCompletedJobsResponse = context
507589
.rpc_sender
@@ -512,6 +594,10 @@ impl Query {
512594
Ok(jobs.iter().map(GraphQLSnarkJob::from).collect())
513595
}
514596

597+
/// Get pending SNARK work items that need to be completed
598+
///
599+
/// # Returns
600+
/// List of pending SNARK work items with job specifications
515601
async fn pending_snark_work(
516602
context: &Context,
517603
) -> juniper::FieldResult<Vec<GraphQLPendingSnarkWork>> {
@@ -528,18 +614,28 @@ impl Query {
528614
}
529615

530616
/// The chain-agnostic identifier of the network
617+
///
618+
/// # Returns
619+
/// Network identifier in the format "mina:<network_name>"
531620
#[graphql(name = "networkID")]
532621
async fn network_id(_context: &Context) -> juniper::FieldResult<String> {
533622
let res = format!("mina:{}", NetworkConfig::global().name);
534623
Ok(res)
535624
}
536625

537626
/// The version of the node (git commit hash)
627+
///
628+
/// # Returns
629+
/// Git commit hash of the current node build
538630
async fn version(_context: &Context) -> juniper::FieldResult<String> {
539631
let res = BuildEnv::get().git.commit_hash;
540632
Ok(res)
541633
}
542634

635+
/// Get information about the current SNARK worker if configured
636+
///
637+
/// # Returns
638+
/// SNARK worker configuration including public key, account, and fee
543639
async fn current_snark_worker(
544640
&self,
545641
context: &Context,
@@ -621,17 +717,40 @@ where
621717
}
622718

623719
#[derive(Clone, Debug)]
624-
struct Mutation;
720+
pub struct Mutation;
625721

722+
/// GraphQL Mutation endpoints exposed by the Mina node
723+
///
724+
/// # Available Mutations:
725+
///
726+
/// ## Transaction Submission
727+
/// - `send_zkapp` - Submit a zkApp transaction to the network
728+
/// - `send_payment` - Send a payment transaction
729+
/// - `send_delegation` - Send a delegation transaction
626730
#[juniper::graphql_object(context = Context)]
627731
impl Mutation {
732+
/// Submit a zkApp transaction to the network
733+
///
734+
/// # Arguments
735+
/// - `input`: zkApp command with account updates and fee payer information
736+
///
737+
/// # Returns
738+
/// Transaction response with hash and zkApp command details
628739
async fn send_zkapp(
629740
input: zkapp::SendZkappInput,
630741
context: &Context,
631742
) -> juniper::FieldResult<zkapp::GraphQLSendZkappResponse> {
632743
inject_tx(input.try_into()?, context).await
633744
}
634745

746+
/// Send a payment transaction
747+
///
748+
/// # Arguments
749+
/// - `input`: Payment details including sender, receiver, amount, fee, and memo
750+
/// - `signature`: Transaction signature
751+
///
752+
/// # Returns
753+
/// Payment response with transaction hash and details
635754
async fn send_payment(
636755
input: user_command::InputGraphQLPayment,
637756
signature: user_command::UserCommandSignature,
@@ -662,6 +781,14 @@ impl Mutation {
662781
inject_tx(command, context).await
663782
}
664783

784+
/// Send a delegation transaction
785+
///
786+
/// # Arguments
787+
/// - `input`: Delegation details including delegator, delegate, fee, and memo
788+
/// - `signature`: Transaction signature
789+
///
790+
/// # Returns
791+
/// Delegation response with transaction hash and details
665792
async fn send_delegation(
666793
input: user_command::InputGraphQLDelegation,
667794
signature: user_command::UserCommandSignature,
@@ -706,7 +833,9 @@ pub fn routes(
706833
.or(warp::get().and(warp::path("graphiql")).and(graphiql_filter))
707834
}
708835

709-
/// Helper function used by [`Query::pooled_user_commands`] and [`Query::pooled_zkapp_commands`] to parse public key, transaction hashes and command ids
836+
/// Helper function used by [`Query::pooled_user_commands`] and
837+
/// [`Query::pooled_zkapp_commands`] to parse public key, transaction hashes and
838+
/// command ids
710839
fn parse_pooled_commands_query<ID, F>(
711840
public_key: Option<String>,
712841
hashes: Option<Vec<String>>,

node/native/src/graphql/snark.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ pub struct GraphQLWorkDescription {
2525
pub source_second_pass_ledger_hash: String,
2626
/// Base58Check-encoded hash of the target second-pass ledger
2727
pub target_second_pass_ledger_hash: String,
28-
/// Total transaction fee that is not accounted for in the transition from source ledger to target ledger
28+
/// Total transaction fee that is not accounted for in the transition from
29+
/// source ledger to target ledger
2930
pub fee_excess: GraphQLFeeExcesses,
3031
/// Increase/Decrease in total supply
3132
pub supply_change: GraphQLSupplyChange,

0 commit comments

Comments
 (0)