Merge multiple Juniper object definitions into a single object type.

Overview

juniper-compose

Merge multiple Juniper object definitions into a single object type.

crates.io | docs | github

Motivation

You are building a GraphQL server using Juniper. At some point you realize that you have gigantic Query and Mutation types:

#[derive(Default)]
struct Query;

#[juniper::graphql_object]
impl Query {
    async fn user(ctx: &Context, id: Uuid) -> User {
        // ...
    }

    async fn users(ctx: &Context) -> Vec<User> {
        // ...
    }

    async fn task(ctx: &Context, id: Uuid) -> Task {
        // ...
    }

    async fn tasks(ctx: &Context) -> Vec<Task> {
        // ...
    }
    
    // ...many more
}

You would like to split it up into multiple domain-specific files, and have e.g. all User queries in one file and all Task queries in the other. With current Juniper API, it is very hard to do, but this crate can help you.

Usage

#[derive(Default)]
struct UserQueries;

#[composable_object]
#[juniper::graphql_object]
impl UserQueries {
    async fn user(ctx: &Context, id: Uuid) -> User {
        // ...
    }

    async fn users(ctx: &Context) -> Vec<User> {
        // ...
    }
}

#[derive(Default)]
struct TaskQueries;

#[composable_object]
#[juniper::graphql_object]
impl TaskQueries {
    async fn task(ctx: &Context, id: Uuid) -> Task {
        // ...
    }

    async fn tasks(ctx: &Context) -> Vec<Task> {
        // ...
    }
}

composite_object!(Query(UserQueries, TaskQueries));

Custom contexts are supported:

composite_object!(Query<Context = MyCustomContext>(UserQueries, TaskQueries));

Visibility specifier for generated type is supported:

composite_object!(pub(crate) Query<Context = MyCustomContext>(UserQueries, TaskQueries));

Custom scalars are currently not supported, but will be added if requested.

You might also like...
Deserialize (potentially nested) environment variables into your custom structs
Deserialize (potentially nested) environment variables into your custom structs

envious allows you to deserialize your serde enabled structs from environment variables. See it in action: use serde::{Deserialize, Serialize}; #[der

Merge together and efficiently time-sort compressed .pcap files stored in AWS S3 object storage (or locally) to stdout for pipelined processing.

Merge together and efficiently time-sort compressed .pcap files stored in AWS S3 object storage (or locally) to stdout for pipelined processing. High performance and parallel implementation for 10 Gbps playback throughput with large numbers of files (~4k).

Single-reader, multi-writer & single-reader, multi-verifier; broadcasts reads to multiple writeable destinations in parallel

Bus Writer This Rust crate provides a generic single-reader, multi-writer, with support for callbacks for monitoring progress. It also provides a gene

Convert Juniper configurations to 'set-style'

JCC: Juniper Config Converter Convert Juniper configurations. Takes a Juniper configuration as displayed using show configuration and transforms it to

Translate C++/Rust type into C type with the same memory layout

clayout, translate C++/Rust type into C type with the same memory layout. Generally, clayout is used together with bpftrace. clayout is developed on d

A crate that allows you to mostly-safely cast one type into another type.

A crate that allows you to mostly-safely cast one type into another type. This is mostly useful for generic functions, e.g. pub fn fooS(s: S) {

The core innovation of EinsteinDB is its merge-append-commit protocol

The core innovation of EinsteinDB is its merge-append-commit protocol. The protocol is friendly and does not require more than two parties to agree on the order of events. It is also relativistic and can tolerate clock and network lag and drag.

Parse, edit and merge Prometheus metrics exposition format

promerge Promerge provides minimalistic and easy to use API to parse and manipulate Prometheus metrics. A simple usecase could be collecting metrics f

Hitbox is an asynchronous caching framework supporting multiple backends and suitable for distributed and for single-machine applications.

Hitbox is an asynchronous caching framework supporting multiple backends and suitable for distributed and for single-machine applications.

CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" format.

Lighthouse Groupie CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" form

CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a plotable format.

Lighthouse Aggregator CLI tool that make it easier to perform multiple lighthouse runs towards a single target and output the result in a "plotable" f

A command line tool for easily generating multiple versions of a configuration file from a single template

MultiConf A command line tool for easily generating multiple versions of a configuration file from a single template. Why? I'm a big fan of the i3 win

Set Shell Environment Variables across multiple shells with a single configuration file.

Xshe – Cross-Shell Environment Vars xshe allows for setting Shell Environment Variables across multiple shells with a single TOML configuration file.

Multiplex server for rust-analyzer, allows multiple LSP clients (editor windows) to share a single rust-analyzer instance per cargo workspace

ra-multiplex   Multiplex server for rust-analyzer, allows multiple LSP clients (editor windows) to share a single rust-analyzer instance per cargo wor

A box with vtable, erasing the type of the contained object

VBox VBox is a type erased Box of trait object that stores the vtable pointer. VBox is just like a Boxdyn Trait but erases type Trait so that to use

A single-producer single-consumer Rust queue with smart batching

Batching Queue A library that implements smart batching between a producer and a consumer. In other words, a single-producer single-consumer queue tha

Handoff is an unbuffered, single-producer / single-consumer, async channel

handoff handoff is a single-producer / single-consumer, unbuffered, asynchronous channel. It's intended for cases where you want blocking communicatio

This library implements a type macro for a zero-sized type that is Serde deserializable only from one specific value.

Monostate This library implements a type macro for a zero-sized type that is Serde deserializable only from one specific value. [dependencies] monosta

Type erased vector. All elements have the same type.

Type erased vector. All elements have the same type. Designed to be type-erased as far as possible - most of the operations does not know about concre

Comments
  • fix: create Query/Mutation struct as public

    fix: create Query/Mutation struct as public

    Hey @nikis05, great job on this crate! Thanks a lot :D

    That PR is just a little update to create the root Query / Mutation as public, if you want to use it in another crate inside of your project :)

    After this update, everything is working like a charm, thanks again :D

    opened by fdaciuk 6
Owner
Kit Isaev
Lead developer @leviosa-medical. Full-stack web dev, proud Rust enjoyer 🦀 Techs: React, TS, GQL, Node, Rust, PG, Docker, K8s, and more.
Kit Isaev
A fast static site generator in a single binary with everything built-in. https://www.getzola.org

zola (né Gutenberg) A fast static site generator in a single binary with everything built-in. Documentation is available on its site or in the docs/co

Zola 10.1k Jan 10, 2023
Silkenweb - A library for writing reactive single page web apps

Silkenweb A library for building reactive single page web apps. Features Fine grained reactivity using signals to minimize DOM API calls No VDOM. Call

null 85 Dec 26, 2022
Type safe multipart/form-data handling for axum.

axum_typed_multipart Designed to seamlessly integrate with Axum, this crate simplifies the process of handling multipart/form-data requests in your we

Lorenzo Murarotto 10 Mar 28, 2023
Rust GraphQL server using simple type-only schema

SimpleGQL This library allows a simplified GraphQL schema to be given and will run a server with a backend store (currently only SQLite) and a set of

Daniel Cocks 5 May 10, 2023
Rust Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.

Rust Embed Rust Custom Derive Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev. Y

Peter 1k Jan 5, 2023
Turn GitHub into an RSS reader

NotCraft::NotFeed An RSS reader running entirely from your GitHub repo. Free hosting on GitHub Pages. No ads. No third party tracking. No need for bac

NotCraft 22 Nov 30, 2022
ditch poetry for pip. converts pyproject.toml into requirements.txt.

Say No To Poetry Did you grow up using just pip or conda? Are you being forced to use poetry everywhere at work? They try to convince you poetry just

Jaivarsan 7 Nov 6, 2022
The [cain!] macro is a macro that rewrites sequential Rust branch statements into nested branches

Note! This crate is experimental and under development. It may include bugs that alter the behavior of your code in unexpected ways. You should review

Fredrik Østrem 2 Jan 19, 2022
Tools that parsing Rust code into UML diagram (in dot format currently).

rudg Rust UML Diagram Generator Tools that parsing Rust code into UML diagram (in dot format currently). Usage $ rudg.exe --help rudg 0.1.0 USAGE:

Zhai Yao 16 Nov 13, 2022
Turn any web page into a desktop app (but, lightweight <1MB)

Intro Turn any web page into a desktop app (but, lightweight <1MB) The bundle will be less than 2MB Demo: https://i.imgur.com/BLr03oF.mp4 Install carg

null 9 Dec 27, 2022