Skip to content
A GraphQL query parser in C++ with C and C++ APIs
C++ Python C CMake Go
Latest commit bb3ab49 May 10, 2016 @swolchok swolchok Merge pull request #33 from kenshaw/master
Adding pkg-config generation to CMakeLists
Failed to load latest commit information.
ast s/Array/List/g Mar 7, 2016
c expose C API for serializing AST to JSON Sep 16, 2015
cmake Adding pkg-config generation to CMakeLists May 10, 2016
go Adding pkg-config generation to CMakeLists May 10, 2016
python Make out-of-source build work Sep 14, 2015
test Merge pull request #31 from gjtorikian/test-memory May 3, 2016
.gitignore Adding pkg-config generation to CMakeLists May 10, 2016
.travis.yml Add valgrind package to Travis CI May 2, 2016
AstNode.h Initial import Aug 13, 2015
CMakeLists.txt Adding pkg-config generation to CMakeLists May 10, 2016
CONTRIBUTING.md Initial import Aug 13, 2015
GraphQLParser.cpp Make lexer re-entrant and thread it through parser Sep 15, 2015
GraphQLParser.h Initial import Aug 13, 2015
JsonVisitor.cpp s/Array/List/g Mar 7, 2016
JsonVisitor.h s/Array/List/g Mar 7, 2016
LICENSE Initial import Aug 13, 2015
PATENTS Initial import Aug 13, 2015
README.md Update README Feb 22, 2016
dump_json_ast.cpp dump_json_ast: don't leak return value of graphql_ast_to_json Oct 8, 2015
lexer.cpp Accept `subscription` as an operation type. Apr 29, 2016
lexer.h Accept `subscription` as an operation type. Apr 29, 2016
lexer.lpp Accept `subscription` as an operation type. Apr 29, 2016
libgraphqlparser.pc.in Adding pkg-config generation to CMakeLists May 10, 2016
location.hh Accept `subscription` as an operation type. Apr 29, 2016
parser.tab.cpp Accept `subscription` as an operation type. Apr 29, 2016
parser.tab.hpp Accept `subscription` as an operation type. Apr 29, 2016
parser.ypp Accept `subscription` as an operation type. Apr 29, 2016
position.hh Accept `subscription` as an operation type. Apr 29, 2016
stack.hh Accept `subscription` as an operation type. Apr 29, 2016
syntaxdefs.h Make lexer re-entrant and thread it through parser Sep 16, 2015

README.md

libgraphqlparser

libgraphqlparser is a parser for GraphQL, a query language created by Facebook for describing data requirements on complex application data models, implemented in C++11. It can be used on its own in C++ code (or in C code via the pure C API defined in the c subdirectory), or you can use it as the basis for an extension module for your favorite programming language instead of writing your own parser from scratch.

Example

The provided dump_json_ast is a simple program that reads GraphQL text on stdin and prints a JSON representation of the AST to stdout.

The python subdirectory contains an example Python binding for the pure C API.

Requirements

libgraphqlparser requires a C++ compiler that supports C++11. It also requires Mac OS X or Linux.

To run tests, please download googletest from https://googletest.googlecode.com/files/gtest-1.7.0.zip and unzip it in the test subdirectory.

Building libgraphqlparser

libgraphqlparser is built with CMake. If a sufficiently-recent version of Flex and Bison are installed on your system, it will use them; otherwise, it will rely on the checked-in parser.tab.{c,h}pp and lexer.{h,cpp}.

To build libgraphqlparser from source:

$ # inside the project root:
$ cmake .
$ make

Then, to install it on your system:

$ make install

How libgraphqlparser works

libgraphqlparser uses flex and bison to generate a C++ parser for GraphQL. These tools work well but have idiosyncratic interfaces by modern standards, so GraphQLParser.h provides a simple interface to parse GraphQL.

In order to make it simpler to write code based around the GraphQL AST, libgraphqlparser includes an extremely simple code generation framework in the ast/ subdirectory. This framework is used to build the AST classes themselves, as well as a visitor over the AST. It may be easier to understand the output of the generation steps directly (i.e., Ast.h, Ast.cpp, and AstVisitor.h) rather than trying to read the generation scripts. Simply building libgraphqlparser will cause these files to be generated.

libgraphqlparser also uses the AST generation framework to build a pure C API in the c subdirectory. This API can be used from C code, and it should also simplify the task of creating bindings to other programming languages.

License

libgraphqlparser is BSD-licensed. We also provide an additional patent grant.

Related Projects

Something went wrong with that request. Please try again.