• Stars
    star
    337
  • Rank 121,210 (Top 3 %)
  • Language
    Rust
  • License
    Mozilla Public Li...
  • Created over 4 years ago
  • Updated about 1 month ago

Reviews

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

Repository Details

A bring your own types GraphQL client library for Rust

Cynic

A bring your own types GraphQL client for Rust

Crate Info API Docs Discord Chat

Documentation | Examples | Changelog

Overview

Cynic is a GraphQL library for Rust. It's not the first but it takes a different approach from the existing libraries.

Existing libraries take a query first approach to GQL - you write a query using GraphQL and libraries use that to generate Rust structs for you using macros. This is really easy and great for getting going quickly. However, if you want to use structs that aren't quite what the macros output you're out of luck. Some more complex use cases like sharing structs among queries are also commonly not supported.

Cynic takes a different approach - it uses Rust structs to define queries and generates GraphQL from them. This gives you freedom to control the structs you'll be working with while still enjoying type safe queries, checked against the GraphQL schema. When its built in derives don't do exactly what you want it provides lower level APIs to hook in and fetch the data you want in the format you want to work with it.

Of course writing out all the structs to represent a large GraphQL query can be quite challenging, and GraphQL has excellent tooling for building queries usually. Cynic provides querygen to help with this - you write a GraphQL query using the existing GQL tooling and it'll generate some cynic structs to make that query. You can use this as a starting point for your projects - either adding on to the rust structs directly, or re-using querygen as appropriate.

Features

Cynic is currently a work in progress, but the following features are supported:

  • Typesafe queries & mutations.
  • Defining custom scalars.
  • Building dynamic (but still type checked) queries at run time.
  • Query arguments including input objects
  • Interfaces & union types
  • GraphQL Subscriptions via graphql-ws-client. (though graphql-ws-client is fairly alpha quality)

The following features are not yet supported, though should be soon (if you want to help out with the project I'd be happy for someone else to try and implement these - if you open an issue I'd be happy to give pointers on how to go about implementing any of them)

  • Directives
  • Potentially other things (please open an issue if you find anything obviously missing)

Documentation

Cynic is documented in a few places:

  1. There's a guide to using cynic on cynic-rs.dev
  2. The reference documentation on docs.rs

Inspiration

  • graphql-client, the original Rust GraphQL client. This is a great library for using GraphQL from Rust. It wasn't quite what I wanted but it might be what you want.
  • The idea of encoding the GraphQL typesystem into a DSL was taken from elm-graphql.
  • Most of the JSON decoding APIs were taken from Json.Decode in Elm.
  • Deriving code from structs is a fairly common Rust pattern, though serde in particular provided inspiration for the derive APIs.

More Repositories

1

kazan

Kubernetes API client for Elixir
Elixir
139
star
2

graphql-ws-client

A GraphQL over Websockets implementation for Rust
Rust
32
star
3

libsysconfcpus

A github mirror of http://www.kev.pulo.com.au/libsysconfcpus/
Shell
31
star
4

erlang_port

A utility library for writing Erlang/Elixir ports in Rust
Rust
25
star
5

chunnel

A python client for phoenix channels.
Python
17
star
6

ex_unit_fixtures

A library for defining modular dependencies (fixtures) for ExUnit tests.
Elixir
13
star
7

exometer_datadog

An elixir library for pushing exometer metrics to datadog via the REST API.
Elixir
12
star
8

flask-should-dsl

A flask extension for testing with should-dsl
Python
10
star
9

serde_eetf

Erlang external term format support for serde
Rust
9
star
10

asdf-elm

Elm plugin for asdf version manager.
Shell
6
star
11

go-away

Generate go types from rust types
Rust
4
star
12

gae-logstash-http

A flask application to allow GAE apps to post to logstash using urlfetch.
Python
4
star
13

dotfiles

My dotfiles
Vim Script
4
star
14

plug_fprof

An Elixir Plug for profiling code with fprof.
Elixir
4
star
15

ractive-brunch

Adds ractive compilation support to brunch
JavaScript
4
star
16

flycheck-elixir-dogma

Elixir linting support for flycheck
Emacs Lisp
3
star
17

vassal

A task queue that emulates SQS for testing SQS based applications.
Elixir
3
star
18

git-lead-time

CLI for checking the lead time of a teams commits on GitHub
Rust
2
star
19

docker-python-web

Dockerfiles for hosting python web apps
Shell
2
star
20

elk

An elixir app for running google app engine pull queues.
Elixir
2
star
21

asdf-purescript

PureScript plugin for asdf version manager
Shell
2
star
22

cerberus_to_swagger

A hacky script for converting cerberus schemas to swagger data definitions
Python
1
star
23

synchg

Simple Mercurial Syncing
Python
1
star
24

docker-logstash-http-kibana

A docker logstash image, w/ kibana, nginx & gae-logstash-http
Shell
1
star
25

request_pot

A requestb.in clone using Elixir & Elm
Elixir
1
star
26

pypod

A simple command line podcatcher with a web interface
Python
1
star
27

docker-elixir

Shell
1
star
28

openapi-subgraph-example

Rust
1
star
29

elm-slow-test

A temporary project for demonstrating how slow elm compiles on CI
Elm
1
star
30

k8s-certbot-google-dns

Docker image & YAML for running certbot on k8s
Shell
1
star
31

growlproxy

A simple python based proxy for gntp notifications. A complete work in progress, anything may be broken at any time
JavaScript
1
star
32

syncro

An Android app & server for wireless file syncing
C++
1
star
33

action-graphql-introspect

1
star
34

resumr

A web-app for creating CVs with a git database backend
JavaScript
1
star