mas_handlers/graphql/model/
cursor.rs1use async_graphql::connection::OpaqueCursor;
8use serde::{Deserialize, Serialize};
9use ulid::Ulid;
10
11pub use super::NodeType;
12
13#[derive(Serialize, Deserialize, PartialEq, Eq)]
14pub struct NodeCursor(pub NodeType, pub Ulid);
15
16impl NodeCursor {
17 pub fn extract_for_types(&self, node_types: &[NodeType]) -> Result<Ulid, async_graphql::Error> {
18 if node_types.contains(&self.0) {
19 Ok(self.1)
20 } else {
21 Err(async_graphql::Error::new("invalid cursor"))
22 }
23 }
24
25 pub fn extract_for_type(&self, node_type: NodeType) -> Result<Ulid, async_graphql::Error> {
26 if self.0 == node_type {
27 Ok(self.1)
28 } else {
29 Err(async_graphql::Error::new("invalid cursor"))
30 }
31 }
32}
33
34pub type Cursor = OpaqueCursor<NodeCursor>;