Response

Derive Macro Response 

Source
#[derive(Response)]
{
    // Attributes available to this derive:
    #[response]
    #[field]
}
Expand description

Derive macro for GraphQL response types with nested field extraction.

Use #[field(path = "...")] to specify the JSON path to extract each field. Paths are dot-separated (e.g., "object.address" extracts json["object"]["address"]).

§Root Type

By default, field paths are validated against the Query type. Use #[response(root_type = "...")] to validate against a different type instead.

§Generated Code

The macro generates:

  • from_value(serde_json::Value) -> Result<Self, String> method
  • Deserialize implementation that uses from_value

§Example

// Query response (default)
#[derive(Response)]
struct ChainInfo {
    #[field(path = "chainIdentifier")]
    chain_id: String,

    #[field(path = "epoch.epochId")]
    epoch_id: Option<u64>,
}

// Mutation response
#[derive(Response)]
#[response(root_type = "Mutation")]
struct ExecuteResult {
    #[field(path = "executeTransaction.effects.effectsBcs")]
    effects_bcs: Option<String>,
}