pub struct NodePreExecutionArguments { /* private fields */ }
Expand description
Arguments passed to the authorize_node_pre_execution
hook.
Implementations§
Source§impl NodePreExecutionArguments
impl NodePreExecutionArguments
Sourcepub fn type_name(&self) -> &str
pub fn type_name(&self) -> &str
The name of the node type.
For the following GraphQL schema:
type User @authorized {
id: Int!
name: String!
}
type Query {
user(id: ID!): User
}
The node type name is User
.
Sourcepub fn metadata<'a, T>(&'a self) -> Result<T, Error>where
T: Deserialize<'a>,
pub fn metadata<'a, T>(&'a self) -> Result<T, Error>where
T: Deserialize<'a>,
The metadata passed to the @authorized
directive. The metadata is
serialized as a JSON object. This method will deserialize the metadata
into either serde_json::Value
or a custom struct.
For the following GraphQL schema:
type User @authorized(metadata: { role: "admin" }) {
id: Int!
name: String!
}
type Query {
user(id: ID!): User
}
When executing a query like:
query {
user(id: "123") { id }
}
The metadata is {"role": "admin"}
.
The metadata can be deserialized into a custom struct:
#[derive(serde::Deserialize)]
#[serde(untagged, rename = "snake_case")]
enum Role {
Admin,
User,
}
#[derive(serde::Deserialize)]
struct Metadata {
role: Role,
}
let arguments: Metadata = arguments.metadata()?;
Auto Trait Implementations§
impl Freeze for NodePreExecutionArguments
impl RefUnwindSafe for NodePreExecutionArguments
impl Send for NodePreExecutionArguments
impl Sync for NodePreExecutionArguments
impl Unpin for NodePreExecutionArguments
impl UnwindSafe for NodePreExecutionArguments
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