pub struct EdgePostExecutionArguments { /* private fields */ }Expand description
Arguments passed to the authorize_edge_post_execution hook.
Implementations§
Source§impl EdgePostExecutionArguments
impl EdgePostExecutionArguments
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 Address {
street: String!
}
type User {
id: Int!
addresses: [Address!]! @authorized(fields: "id", node: "street")
}
type Query {
users: [User!]!
}And the query:
query {
users { addresses { street } }
}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 Address {
street: String!
}
type User {
id: Int!
addresses: [Address!]! @authorized(fields: "id", node: "street")
}
type Query {
users: [User!]!
}And the query:
query {
users { addresses { street } }
}The field name is addresses.
Sourcepub fn edges<'a, T, K>(&'a self) -> Result<Vec<(T, Vec<K>)>, Error>where
T: Deserialize<'a>,
K: Deserialize<'a>,
pub fn edges<'a, T, K>(&'a self) -> Result<Vec<(T, Vec<K>)>, Error>where
T: Deserialize<'a>,
K: Deserialize<'a>,
The returned edges, serialized as a JSON objects. The first item of the tuple
is a serialization of the fields defined in the fields argument and the second
one is a serialization of the fields defined in the node argument.
This method will deserialize the parent nodes into either serde_json::Value or a custom struct.
For the following GraphQL schema:
type Address {
street: String!
}
type User {
id: Int!
addresses: [Address!]! @authorized(fields: "id", node: "street")
}
type Query {
users: [User!]!
}And the query:
query {
users { addresses { street } }
}The query returns two entities:
[
{
"id": 1,
"addresses": [{ "street": "Elm Street" }]
},
{
"id": 2,
"addresses": [{ "street": "Maple Street" }]
}
]The arguments can be deserialized into a custom struct like:
#[derive(serde::Deserialize)]
struct Parent {
id: u64,
}
#[derive(serde::Deserialize)]
struct Node {
street: String,
}
let edges: Vec<(Parent, Vec<Node>)> = arguments.edges()?;The directive defines the fields argument as id and node argument as
street, so the hook gets a vector of tuples where the first item is the
parent fields with the fields defined in fields and the second one is
the nodes with the fields defined in node.
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 Address {
street: String!
}
type User {
id: Int!
addresses: [Address!]! @authorized(
fields: "id",
node: "street",
metadata: { role: "admin" }
)
}
type Query {
users: [User!]!
}When executing a query like:
query {
users { addresses { street } }
}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()?;