• Stars
    star
    236
  • Rank 170,480 (Top 4 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Rust GraphQL server framework

GraphQL server framework in Rust

This framework lets you write type-safe, efficient GraphQL servers in Rust. We make heavy use of macros to cut down on boilerplate and the trait system to allow maximum flexibility.

This project is at 'proof of concept' stage. It can only handle minimal examples and some key components are missing. However, I believe the results are already promising - Rust and GraphQL are a great match!

In the future we should use Rusts emerging async IO systems to make extremely performant servers.

Example

Use the schema macro to specify the schema for your server (using IDL):

schema! {
    schema {
        query: Query,
    }

    type Query {
        hero(episode: Episode): Character,
        human(id : ID!): Human,
    }

    enum Episode {
        NEWHOPE,
        EMPIRE,
        JEDI,
    }

    interface Character {
        id: ID!,
        name: String!,
        friends: [Character],
        appearsIn: [Episode]!,
    }

    type Human implements Character {
        id: ID!,
        name: String!,
        friends: [Character],
        appearsIn: [Episode]!,
        homePlanet: String,
    }
}

You can see the output for this example use of the schema macro at schema.out.

The macro generates concrete and abstract versions of each item. The library user must specify implementations for functions (e.g., hero in the above schema). You can then use the generated types - enums are Rust enums, types are Rust structs, etc.:

TODO these are equivalent to resolvers in the JS frameworks

struct MyServer;

impl Root for MyServer {
    type Query = DbQuery;

    fn query(&self) -> QlResult<DbQuery> {
        Ok(DbQuery)
    }
}

ImplRoot!(MyServer);


struct DbQuery;

impl AbstractQuery for DbQuery {
    fn hero(&self, episode: Option<Episode>) -> QlResult<Option<Character>> {
        match episode {
            Some(Episode::JEDI) => {
                // In real life, this would query the DB or execute business logic.
                Ok(Some(Character {
                    id: Id("0".to_owned()),
                    name: "Luke".to_owned(),
                    friends: Some(vec![]),
                    appearsIn: vec![],
                }))
            }
            _ => unimplemented!(),
        }
    }

    fn human(&self, _id: Id) -> QlResult<Option<Human>> {
        ...
    }
}

If you don't want to use the generated representation for a certain item, you can provide your own (perhaps using a HashMap of data, rather than fields). You then implement the abstract view of the item (e.g., AbstractHuman for Human) and override the relevant associated type (e.g., type Human = MyHuman; in the implementations of Root and AbstractQuery, and anywhere else the type is used):

struct MyHuman {
    id: usize,
    db_table: DbTablePtr,
}

ImplHuman!(MyHuman);

impl AbstractHuman for MyHuman {
    fn resolve_field(&self, field: &query::Field) -> QlResult<result::Value> {
        ...
    }
}

TODO show main

More Repositories

1

r4cppp

Rust for C++ programmers
Rust
3,348
star
2

derive-new

derive simple constructor functions for Rust structs
Rust
525
star
3

libhoare

Design by contract style assertions for Rust
Rust
247
star
4

xmas-elf

elf parser and navigation tool, pure Rust
Rust
157
star
5

rustaceans.org

Backing data for
150
star
6

ezio

Easy IO for Rust
Rust
104
star
7

portable-interoperable

Async fundamentals initiative: portable and interoperable
75
star
8

apr-intro

An alternate introdcution to the APR book
60
star
9

talks

Slides and artifacts for talks
58
star
10

stupid-stats

Tutorial and demo of rust compiler replacement tooling
Rust
54
star
11

proc-macro-rules

Macro-rules-style syntax matching for procedural macros
Rust
51
star
12

error-docs

Documentation of Rust error handling
48
star
13

zero

A Rust library for zero-allocation parsing of binary data.
Rust
47
star
14

darkly

Rust
40
star
15

callgraph.rs

Callgraphs for Rust programs
Rust
32
star
16

rfc-index

A curated index of Rust RFCs
Rust
27
star
17

find-work

find something Rusty to work on
Rust
20
star
18

big-book-ffi

The Big Book of Rust Interop
20
star
19

provide-any

Proposed API for type-driven member access
Rust
12
star
20

leb128

Implementation of LEB128 encoding in Rust
Rust
9
star
21

mentor-rfcs

A place to improve your RFC writing skills and collaborate on writing RFCs
9
star
22

async-io-traits

Async versions of io traits
Rust
8
star
23

tikv-bench

Rust
7
star
24

rust-dxr

Rust indexing in DXR
7
star
25

rustdoc-highlight

A Rust syntax highlighting library
Rust
5
star
26

box-error

A library for error handling using boxed errors
Rust
4
star
27

clyde

wip
Rust
3
star
28

grpc-snoop

A tool to capture TiKV gRPC messages
Go
3
star
29

gh-velocity

measure the velocity of PRs landing in GitHub
Rust
3
star
30

survey-processing

Utility code for processing Rust's annual survey
Rust
3
star
31

N

PL Semantics Tool
Python
3
star
32

parcom

Rust
2
star
33

tmit

This Month in TiKV
2
star
34

owned-buf

An owned buffer type for reading into possibly uninitialized memory
Rust
2
star
35

github-issues-import

Fork of IQAndreas/github-issues-import
Python
2
star
36

triage

Scripts for helping with Rust issue triage
JavaScript
2
star
37

rustc-perf-data

1
star
38

grpc-benchmark

Shell
1
star
39

macro-libs

Design a proc macro library for Rust
1
star
40

collections

having some fun implementing basic data structures in Rust
Rust
1
star
41

fmtfmt

very WIP ideas for a generic formatting tool
Rust
1
star
42

read-buf

Very sketchy experimentation with ReadBuf things
Rust
1
star
43

raft-proto

Rust
1
star
44

ios-apnea

experiments in ios apps (an apnea timer)
Swift
1
star
45

ray

Rust and JS ray tracers
Rust
1
star
46

derive-display-rfc

repo for collaborating on an RFC for derive display
1
star
47

grpc-rs-squashed

grpc-rs without any Git history
Rust
1
star