Skip to main content

SendHostContext

Trait SendHostContext 

Source
pub trait SendHostContext:
    Send
    + Sync
    + Send {
    // Required methods
    fn query(
        &self,
        graphql: &str,
        variables: Value,
    ) -> impl Future<Output = Result<Value>> + Send;
    fn sql_query(
        &self,
        sql: &str,
        params: &[Value],
    ) -> impl Future<Output = Result<Vec<Value>>> + Send;
    fn http_request(
        &self,
        method: &str,
        url: &str,
        headers: &[(String, String)],
        body: Option<&[u8]>,
    ) -> impl Future<Output = Result<HttpResponse>> + Send;
    fn storage_get(
        &self,
        bucket: &str,
        key: &str,
    ) -> impl Future<Output = Result<Vec<u8>>> + Send;
    fn storage_put(
        &self,
        bucket: &str,
        key: &str,
        body: &[u8],
        content_type: &str,
    ) -> impl Future<Output = Result<()>> + Send;
    fn auth_context(&self) -> Result<Value>;
    fn env_var(&self, name: &str) -> Result<Option<String>>;
    fn event_payload(&self) -> &EventPayload;
    fn log(&self, level: LogLevel, message: &str);
}
Expand description

Trait for providing host services to functions (queries, storage, HTTP, etc.).

This trait is implemented by the FraiseQL server to allow functions to call back into the server’s services during execution.

The #[trait_variant::make] macro generates SendHostContext which is object-safe for Box<dyn SendHostContext> dynamic dispatch.

Required Methods§

Source

fn query( &self, graphql: &str, variables: Value, ) -> impl Future<Output = Result<Value>> + Send

Execute a GraphQL query.

§Errors

Returns Err if the query fails to execute.

Source

fn sql_query( &self, sql: &str, params: &[Value], ) -> impl Future<Output = Result<Vec<Value>>> + Send

Execute a raw SQL query.

§Errors

Returns Err if the query fails to execute or is classified as insecure.

Source

fn http_request( &self, method: &str, url: &str, headers: &[(String, String)], body: Option<&[u8]>, ) -> impl Future<Output = Result<HttpResponse>> + Send

Make an HTTP request.

§Errors

Returns Err if the request fails or is blocked (e.g., SSRF check).

Source

fn storage_get( &self, bucket: &str, key: &str, ) -> impl Future<Output = Result<Vec<u8>>> + Send

Retrieve an object from storage.

§Errors

Returns Err if the object does not exist or access is denied.

Source

fn storage_put( &self, bucket: &str, key: &str, body: &[u8], content_type: &str, ) -> impl Future<Output = Result<()>> + Send

Store an object to storage.

§Errors

Returns Err if the write fails or access is denied.

Source

fn auth_context(&self) -> Result<Value>

Get the current authenticated user’s context.

§Errors

Returns Err if authentication information is unavailable.

Source

fn env_var(&self, name: &str) -> Result<Option<String>>

Get an environment variable.

Returns Ok(None) if the variable is not set.

§Errors

Returns Err if the variable is blocked from access.

Source

fn event_payload(&self) -> &EventPayload

Get the current event payload (for reference).

Source

fn log(&self, level: LogLevel, message: &str)

Log a message to the tracing subscriber.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§