All Projects → sikanhe → Reason Graphql

sikanhe / Reason Graphql

Licence: mit
GraphQL server in pure Reason (Bucklescript)

Programming Languages

reason
219 projects

Projects that are alternatives of or similar to Reason Graphql

Reason Urql
Reason bindings for Formidable's Universal React Query Library, urql.
Stars: ✭ 203 (+48.18%)
Mutual labels:  graphql, reasonml
Reason Apollo Hooks
Deprecated in favor of https://github.com/reasonml-community/graphql-ppx
Stars: ✭ 140 (+2.19%)
Mutual labels:  graphql, reasonml
Graphql ppx
GraphQL PPX rewriter for Bucklescript/ReasonML
Stars: ✭ 325 (+137.23%)
Mutual labels:  graphql, reasonml
Graphql Ppx
GraphQL language primitives for ReScript/ReasonML written in ReasonML
Stars: ✭ 185 (+35.04%)
Mutual labels:  graphql, reasonml
Rescript Relay
Use Relay with ReasonML.
Stars: ✭ 214 (+56.2%)
Mutual labels:  graphql, reasonml
Reason Graphql Fullstack
Fullstack Reason + GraphQL Todo List App
Stars: ✭ 246 (+79.56%)
Mutual labels:  graphql, reasonml
Learn Graphql
Real world GraphQL tutorials for frontend developers with deadlines!
Stars: ✭ 586 (+327.74%)
Mutual labels:  graphql, reasonml
Frontend
🌏 The front-end application code for https://buildkite.com
Stars: ✭ 132 (-3.65%)
Mutual labels:  graphql
Pure
React in pure Reason that targets native platforms.
Stars: ✭ 135 (-1.46%)
Mutual labels:  reasonml
Pesy
Project configuration for esy
Stars: ✭ 132 (-3.65%)
Mutual labels:  reasonml
Next Advanced Apollo Starter
Advanced, but minimalistic Next.js pre-configured starter with focus on DX
Stars: ✭ 131 (-4.38%)
Mutual labels:  graphql
Graphql Postgres Subscriptions
A graphql subscriptions implementation using postgres and apollo's graphql-subscriptions
Stars: ✭ 133 (-2.92%)
Mutual labels:  graphql
Saleor
A modular, high performance, headless e-commerce platform built with Python, GraphQL, Django, and React.
Stars: ✭ 14,720 (+10644.53%)
Mutual labels:  graphql
Serene
Generate clojure.spec with GraphQL and extend GraphQL with clojure.spec
Stars: ✭ 132 (-3.65%)
Mutual labels:  graphql
Graphql Go Example
Example GraphQL API implemented in Go and backed by Postgresql
Stars: ✭ 135 (-1.46%)
Mutual labels:  graphql
Gatsby Blog Starter Kit
A simple starter kit for a static blog created with Gatsby
Stars: ✭ 131 (-4.38%)
Mutual labels:  graphql
Schema Stitching Handbook
Guided examples exploring GraphQL Tools v6+ Schema Stitching
Stars: ✭ 137 (+0%)
Mutual labels:  graphql
Graphql Cli
📟 Command line tool for common GraphQL development workflows
Stars: ✭ 1,814 (+1224.09%)
Mutual labels:  graphql
Graphql Compose Examples
Live examples of schemas builded with graphql-compose
Stars: ✭ 134 (-2.19%)
Mutual labels:  graphql
Graphql Mqtt Subscriptions
graphql-subscriptions implementation for MQTT protocol
Stars: ✭ 133 (-2.92%)
Mutual labels:  graphql

CircleCI

Type safe GraphQL server in pure reason. Compiles to nodejs. A direct port from https://github.com/andreas/ocaml-graphql-server to make it work with Javascript backend.

Motivation

Bucklescript is an amazing alternative to other compie-to-js languages. But it's a tragedy that we have such few libraries and bindings written for the server-side.

In the browser, we can get away with just one great binding for React. However, for the server side, people want major building blocks - a solid database abstractions, a fast http server and a Graphql layer are usually must haves for non-trivial projects.

For these type of frameworks, I believe we should do more than just writing simple bindings to existing npm libraries, because then we are not taking advantage of the expressive type system and rich features of OCaml/Reason. We also lose the chance to show what a language like Reason can do for developer happiness and why its worth it to use it over existing alternatives.

What we get over the traditional JS/TS/Flow + graphql-js combination

Type safety without manual work

Like the ReasonReact implementation, GraphQL schemas defined by this library can express more things and place more constraint on the graphql schema than the vanilla javascript or typescript counterparts.

With Typescript (or Flow), you are required to manually write out the types for all your fields, or use a type generation cli tool like https://graphql-code-generator.com - on top of a lot of manual typecasting, because its typesystem cannot express advanced concepts like heterogenous lists (essentially what arguments and fields are, in GraphQL).

To give you a taste of what this means - if we define a field argument called id with type string with graphql-js, even with typescript or flow, it cannot infer the type of args inside the resolver to be {id: string}. We have to manually type it, which makes it very error-prone. Forget about tracking the nullability of the fields - I have seen many production errors where the manually casted types are out of sync with the schema definition, and vice versa, when the schema gets out of sync with the underlying database models.

  type PersonByIdArgs = {
    id: string
  }
  
  personById: {
    type: Person,
    args: { id: GraphqlNonNull(GraphqQLString) },
    resolve: (ctx, parent, args: PersonByIdArgs) => {
                           ^^^^ this is inferred as `Any`, so we need to manually cast it to `PersonByIdArgs`
    }
  }

In Reason, we can use a more advanced feature of the type system called GADT (Generalized Algebriac Data Types) to express our schema types.

What GADT allows us to do is to have type-safe definitions without needing to manually write types for field arguments and resolver. It can "unfold" the types for resolver as you write out field args! (https://drup.github.io/2016/08/02/difflists/)

 field("PersonById", 
  ~typ=person, 
  ~args=Args.[arg("id", nonnull(string))] 
  ~resolve=(_ctx, _parent, id) => {
//                         ^^ Unfolds args into resolver arguments and correctly types it as a string!
  }

This works for as many arguments as you like, it infers nullability for you as well and give you an option('a) if its nullable!

 field("PersonById", 
  ~typ=person, 
  ~args=Args.[arg("id", nonnull(string)), arg("age", int)] 
  ~resolve=(_ctx, _parent, id,     age) => {
                           ^^      ^^^ 
                           string  option(int) because age is not non-null
  }

Features todolist:

  • [x] Query
  • [x] Mutation
  • [x] Async Fields
  • [x] Directives
  • [ ] Subscription
  • [ ] Non-type Validations (unused fragment, unused variables, and etc)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].