Crate juniper_relay_connection
source · [−]Expand description
Relay style pagination for Juniper.
To return a connection from your resolver, just call
RelayConnection::new
providing a closure
to load the connection nodes.
Example
#[derive(GraphQLObject)]
struct Foo {
id: i32,
}
impl RelayConnectionNode for Foo {
type Cursor = i32;
fn cursor(&self) -> Self::Cursor {
self.id
}
fn connection_type_name() -> &'static str {
"FooConnection"
}
fn edge_type_name() -> &'static str {
"FooConnectionEdge"
}
}
RelayConnection::new(first, after, last, before, |after, before, limit| {
let sql = format!(
"SELECT (id) FROM foo WHERE id > {after:?} AND id < {before:?} LIMIT {limit:?}"
);
let edges: Vec<Foo> = run_query(sql);
Ok(edges)
})
Structs
Implements the relay connection specification, and allows to
easily paginate over any given list of GraphQL objects.
Traits
To return objects inside a connection, they must
implement this trait.