juniper_relay_connection

Crates.iojuniper_relay_connection
lib.rsjuniper_relay_connection
version0.1.1
sourcesrc
created_at2022-10-15 11:52:29.968005
updated_at2022-10-15 11:56:19.675376
descriptionRelay style pagination for Juniper.
homepage
repositoryhttps://github.com/dyedgreen/juniper-relay
max_upload_size
id688922
size18,124
Tilman Roeder (dyedgreen)

documentation

README

Juniper Relay Connections

crates.io Released API docs CI MIT licensed

Relay style pagination for Juniper.

This library provides the a RelayConnection struct, which can be returned in a Juniper GraphQL schema and implements the relay connection interface.

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)
})
Commit count: 5

cargo fmt