pub struct ParentEdgePostExecutionArguments { /* private fields */ }
Expand description
Arguments passed to the authorize_parent_edge_post_execution
hook.
Implementations§
Source§impl ParentEdgePostExecutionArguments
impl ParentEdgePostExecutionArguments
Sourcepub fn parent_type_name(&self) -> &str
pub fn parent_type_name(&self) -> &str
The name of the parent type of the edge.
For the following GraphQL schema:
type User {
id: Int!
name: String! @authorized(fields: "id")
}
type Query {
users: [User!]!
}
And the query:
query {
users { name }
}
The parent type name is User
.
Sourcepub fn field_name(&self) -> &str
pub fn field_name(&self) -> &str
The name of the authorized edge.
For the following GraphQL schema:
type User {
id: Int!
name: String! @authorized(fields: "id")
}
type Query {
users: [User!]!
}
And the query:
query {
users { name }
}
The field name is name
.
Sourcepub fn parents<'a, T>(&'a self) -> Result<Vec<T>, Error>where
T: Deserialize<'a>,
pub fn parents<'a, T>(&'a self) -> Result<Vec<T>, Error>where
T: Deserialize<'a>,
The parent nodes of the edge. The parent nodes are serialized as a JSON objects.
This method will deserialize the parent nodes into either serde_json::Value
or a custom struct.
For the following GraphQL schema:
type User {
id: Int!
name: String! @authorized(fields: "id")
}
type Query {
users: [User!]!
}
And the query:
query {
users { name }
}
The query returns two entities:
[
{
"id": 1,
"name": "Alice"
},
{
"id": 2,
"name": "Bob"
}
]
The arguments can be deserialized into a custom struct like:
#[derive(serde::Deserialize)]
struct Parent {
id: u64,
}
let parents: Vec<Parent> = arguments.parents()?;
The directive defines the fields
argument as id
, so the hook gets an object of all
ids of the returned users.
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 {
id: Int!
name: String! @authorized(fields: "id", metadata: { role: "admin" })
}
type Query {
users: [User!]!
}
When executing a query like:
query {
users { name }
}
The metadata is {"role": "admin"}
.
The metadata can be deserialized into a custom struct like:
#[derive(serde::Deserialize)]
#[serde(untagged, rename = "snake_case")]
enum Role {
Admin,
User,
}
#[derive(serde::Deserialize)]
struct Metadata {
role: Role,
}
let arguments: Metadata = arguments.metadata()?;