graphql_starter_macros/lib.rs
1#![forbid(unsafe_code)]
2
3#[cfg(feature = "sqlx")]
4mod sqlx;
5#[cfg(feature = "subject")]
6mod subject;
7
8use proc_macro::TokenStream;
9use proc_macro_error2::proc_macro_error;
10
11#[cfg(feature = "sqlx")]
12/// Similar to `sqlx::expand_query!` but includes pagination capabilities.
13///
14/// Input parameters:
15/// - `record = Type` _(**mandatory**)_: The type of the retrieved record
16/// - `query = String` _(**mandatory**)_: The query to be executed
17/// - `args = [Expr]` _(optional)_: The arguments to `query`
18/// - `extra_row = bool` _(optional)_: Wether to return an extra row or not (useful to determine if there's a
19/// previous/next page)
20/// - `columns = [Ident]` _(**mandatory**)_: The columns to order by, each row should be uniquely identified by this
21/// combination of columns.
22/// - The ordering can also be specified and defaults to `asc`. For example `[timestamp.desc(),
23/// id.asc()]`
24/// - `first = Expr` _(optional)_: The number of rows to return for forward pagination
25/// - `last = Expr` _(optional)_: The number of rows to return for backward pagination
26/// - `after = Expr` _(optional)_: The variable for a tuple with the values of the cursor for the `columns` **in the
27/// same order** when forward paginating
28/// - `before = Expr` _(optional)_: The variable for a tuple with the values of the cursor for the `columns` **in the
29/// same order** when backward paginating
30#[proc_macro_error]
31#[proc_macro]
32pub fn sqlx_expand_paginated_query(input: TokenStream) -> TokenStream {
33 let input = syn::parse_macro_input!(input as sqlx::pagination::input::QueryInput);
34 sqlx::pagination::r#impl(input).into()
35}
36
37#[cfg(feature = "subject")]
38/// Derives the `Subject` trait.
39#[proc_macro_error]
40#[proc_macro_derive(Subject)]
41pub fn subject(input: TokenStream) -> TokenStream {
42 let input = syn::parse_macro_input!(input as syn::DeriveInput);
43 subject::r#impl(input).into()
44}