pub struct GraphqlClient<'a> { /* private fields */ }Expand description
A client for executing GraphQL operations (queries and mutations).
This client handles constructing the HTTP request, sending it to the specified GraphQL endpoint, and processing the response.
Implementations§
Source§impl<'a> GraphqlClient<'a>
impl<'a> GraphqlClient<'a>
Sourcepub fn new(
base_url: &str,
user_agent: &'a str,
payload_compression: Option<GraphQLPayloadCompression>,
) -> Self
pub fn new( base_url: &str, user_agent: &'a str, payload_compression: Option<GraphQLPayloadCompression>, ) -> Self
Creates a new GraphqlClient instance.
§Arguments
base_url- The base URL of the GraphQL API endpoint (e.g., “https://api.example.com/graphql”).user_agent- The User-Agent string to identify this client.payload_compression- An optional compression strategy. Defaults toGraphQLPayloadCompression::ZstdifNone.
§Panics
Panics if the provided base_url is invalid.
Sourcepub async fn execute_graphql_request<T: DeserializeOwned>(
&self,
query: &str,
variables: &HashMap<String, Value>,
identity_public_key: &[u8],
session_token: Option<&str>,
) -> Result<T>
pub async fn execute_graphql_request<T: DeserializeOwned>( &self, query: &str, variables: &HashMap<String, Value>, identity_public_key: &[u8], session_token: Option<&str>, ) -> Result<T>
Executes a GraphQL query or mutation.
This method builds the request payload, applies compression if configured,
sends the request, handles potential response compression, and deserializes
the data field of the response into the specified type T.
§Arguments
query- The GraphQL query or mutation string. This should be a raw string literal (e.g.,r#"query { ... }"#) containing the full text of the operation. This client does not use pre-generated query types.variables- A map of variables to be included in the request.identity_public_key- The public key identifying the client/user.session_token- An optional session token for authentication.
§Type Parameters
T- The type to deserialize thedatafield of the GraphQL response into. It must implementserde::de::DeserializeOwned.
§Returns
Returns a Result containing the deserialized data T on success, or an eyre::Report
detailing the error on failure (e.g., network issues, non-200 status code,
deserialization errors, missing data field).
Trait Implementations§
Source§impl<'a> Clone for GraphqlClient<'a>
impl<'a> Clone for GraphqlClient<'a>
Source§fn clone(&self) -> GraphqlClient<'a>
fn clone(&self) -> GraphqlClient<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for GraphqlClient<'a>
impl<'a> !RefUnwindSafe for GraphqlClient<'a>
impl<'a> Send for GraphqlClient<'a>
impl<'a> Sync for GraphqlClient<'a>
impl<'a> Unpin for GraphqlClient<'a>
impl<'a> !UnwindSafe for GraphqlClient<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more