3 unstable releases
Uses old Rust 2015
0.1.1 | Aug 14, 2017 |
---|---|
0.1.0 | Aug 10, 2017 |
0.0.1 | Jun 28, 2017 |
#84 in #idl
Used in graphql-idl-parser-ffi
685KB
32K
SLoC
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!
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
Dependencies
~3–4.5MB
~93K SLoC