A parser for the GraphQL IDL format.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
graphql-idl-parser-ffi
script
src
test
.gitignore
.rustfmt.toml
.travis.yml
Cargo.toml
LICENSE.txt
README.md
build.rs

README.md

graphql-idl-parser

A parser for GraphQL IDL files! This repository contains the code for both the Rust implementation, as well as the FFI dylib implementation, which allows you to generate a library for use in C projects (and other languages that play nice with C). See https://github.com/gjtorikian/graphql-idl-parser-ruby for a Ruby implementation!

Build Status

Why?

Two reasons:

  • I have plenty of experience doing Bison/LALR grammars in C, and I desperately wanted to learn some Rust.
  • Most of the GraphQL tooling, I'm sorry to say, appears to be in JavaScript. While that's cool, I really believe that when it comes to creating a tool ecosystem, base implementations ought to be in a language that can be consumed by other projects. In other words, the world doesn't need different GraphQL IDL parsers in Node, and Ruby, and Python, and Java, and Scala. The base format should be in something like C/C++/Rust, and then those higher level languages ought to make use of that one foundational library. This ensures consistency and correctness, no matter what your backend is written in.

Usage

Add this to your Cargo.toml:

[dependencies]
graphql-idl-parser = "^0.1"

and this to your crate root:

extern crate graphql_idl_parser;

After that, simply feed in a GraphQL IDL string to gqlidl::parse_schema, like:

let definitions = gqlidl::parse_schema(contents.as_str()).unwrap();
for def in definitions {
  // ...
}

Note that this library does not validate the format if your IDL. If you have multiple types with the same name, for example, they will be happily consumed as unique types. However, the parser will become irate if it comes across a malformed or unknown token.

Todo:

  • More documentation?
  • Support more of the IDL besides just types