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§
Sourcefn query(
&self,
graphql: &str,
variables: Value,
) -> impl Future<Output = Result<Value>> + Send
fn query( &self, graphql: &str, variables: Value, ) -> impl Future<Output = Result<Value>> + Send
Sourcefn sql_query(
&self,
sql: &str,
params: &[Value],
) -> impl Future<Output = Result<Vec<Value>>> + Send
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.
Sourcefn http_request(
&self,
method: &str,
url: &str,
headers: &[(String, String)],
body: Option<&[u8]>,
) -> impl Future<Output = Result<HttpResponse>> + Send
fn http_request( &self, method: &str, url: &str, headers: &[(String, String)], body: Option<&[u8]>, ) -> impl Future<Output = Result<HttpResponse>> + Send
Sourcefn storage_get(
&self,
bucket: &str,
key: &str,
) -> impl Future<Output = Result<Vec<u8>>> + Send
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.
Sourcefn storage_put(
&self,
bucket: &str,
key: &str,
body: &[u8],
content_type: &str,
) -> impl Future<Output = Result<()>> + Send
fn storage_put( &self, bucket: &str, key: &str, body: &[u8], content_type: &str, ) -> impl Future<Output = Result<()>> + Send
Sourcefn auth_context(&self) -> Result<Value>
fn auth_context(&self) -> Result<Value>
Get the current authenticated user’s context.
§Errors
Returns Err if authentication information is unavailable.
Sourcefn env_var(&self, name: &str) -> Result<Option<String>>
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.
Sourcefn event_payload(&self) -> &EventPayload
fn event_payload(&self) -> &EventPayload
Get the current event payload (for reference).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".