ProgramingIsTheFuture / graphql_to_ocaml

Compiles Graphql code to OCaml with Graphql_Lwt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

graphql_to_ocaml

This projects helps us generating OCaml code based on a graphql code.

Build more, write less.

This project is an atempt to transform the process of building graphql api into something faster and esier.

This is super useful to work with .graphql files and use them inside our ocaml application.

Working with this project

Cli:

  • -o - where to store the generated code (optional) (default: "schema.ml")
  • filename - Graphql code to compile (required)

Exampels are located inside the examples folder.

Generation Example

Receiving a Graphql file like this:

schema {
  query: MyQuery
}

type MyQuery {
  Hello: String!
}

Will give us a OCaml file like this:

open Graphql_lwt;;

type 'ctx schema = { hello: 'ctx Schema.resolve_info -> unit -> string; };;

let schema schema_from_typ = let open Schema in
  Schema.schema [
    field "Hello" ~typ:(non_null string) ~args:Arg.[]
      ~resolve:schema_from_typ.hello;
    ];;

Inspiration

This project is inspired by the gqlgen built with Golang.

TODO

  • Create a basic CLI
    • Run tests
    • Compile graphql code
  • Upgrade the identation with Format module
  • Add support to types with methods
  • Add support to the schema initialization
  • Reorganize the project
  • Add more documentation
  • Write more exampels and tests
  • Test the code with a simple Graphql Application
  • Add support for mutation schema
  • Add graph dependency

About

Compiles Graphql code to OCaml with Graphql_Lwt


Languages

Language:OCaml 100.0%