Struct EdgePostExecutionArguments

Source
pub struct EdgePostExecutionArguments { /* private fields */ }
Expand description

Arguments passed to the authorize_edge_post_execution hook.

Implementations§

Source§

impl EdgePostExecutionArguments

Source

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.

Source

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.

Source

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.

Source

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()?;

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.