#relay #juniper #graphql

juniper_relay_connection

Relay style pagination for Juniper

2 releases

0.1.1 Oct 15, 2022
0.1.0 Oct 15, 2022

#17 in #juniper

Download history 1/week @ 2024-02-15 17/week @ 2024-02-22 12/week @ 2024-02-29 18/week @ 2024-03-07 4/week @ 2024-03-14

51 downloads per month

MIT license

18KB
348 lines

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)
})

Dependencies

~10MB
~229K SLoC