README.md
1# libgraphqlparser
2
3libgraphqlparser is a parser for
4[GraphQL](http://facebook.github.io/graphql/), a query language
5created by Facebook for describing data requirements on complex
6application data models, implemented in C++11. It can be used on its
7own in C++ code (or in C code via the pure C API defined in the `c`
8subdirectory), or you can use it as the basis for an extension module
9for your favorite programming language instead of writing your own
10parser from scratch.
11
12## Example
13
14The provided `dump_json_ast` is a simple program that reads GraphQL
15text on stdin and prints a JSON representation of the AST to stdout.
16
17The `python` subdirectory contains an example Python binding for the
18pure C API.
19
20## Requirements
21
22libgraphqlparser requires a C++ compiler that supports C++11. It
23also requires Mac OS X or Linux.
24
25To run tests, please download googletest from
26https://github.com/google/googletest/archive/release-1.8.0.zip
27and unzip it in the `test` subdirectory.
28
29## Building libgraphqlparser
30
31libgraphqlparser is built with [CMake](http://www.cmake.org/). If a
32sufficiently-recent version of [Flex](http://flex.sourceforge.net/) and [Bison](http://www.gnu.org/software/bison/) are installed on your
33system, it will use them; otherwise, it will rely on the checked-in
34`parser.tab.{c,h}pp` and `lexer.{h,cpp}`.
35
36To build libgraphqlparser from source:
37
38```
39$ # inside the project root:
40$ cmake .
41$ make
42```
43
44Then, to install it on your system:
45
46```
47$ make install
48```
49
50## How libgraphqlparser works
51
52libgraphqlparser uses flex and bison to generate a C++ parser for
53GraphQL. These tools work well but have idiosyncratic interfaces by
54modern standards, so GraphQLParser.h provides a simple interface to
55parse GraphQL.
56
57In order to make it simpler to write code based around the GraphQL
58AST, libgraphqlparser includes an extremely simple code generation
59framework in the `ast/` subdirectory. This framework is used to build
60the AST classes themselves, as well as a visitor over the AST. It may
61be easier to understand the output of the generation steps directly
62(i.e., Ast.h, Ast.cpp, and AstVisitor.h) rather than trying to read
63the generation scripts. Simply building libgraphqlparser will cause
64these files to be generated.
65
66libgraphqlparser also uses the AST generation framework to build a
67pure C API in the `c` subdirectory. This API can be used from C code,
68and it should also simplify the task of creating bindings to other
69programming languages.
70
71## License
72libgraphqlparser is BSD-licensed. We also provide an additional patent grant.
73
74## Related Projects
75
76- [graphql-parser (Ruby interface)](https://github.com/Shopify/graphql-parser)
77- [py-graphqlparser (Python interface)](https://github.com/elastic-coders/py-graphqlparser)
78- [graphql_parser (Elixir interface)](https://github.com/aarvay/graphql_parser)
79- [graphql-parser-php (PHP interface)](https://github.com/dosten/graphql-parser-php)
80- [graphql-libgraphqlparser (Ruby interface)](https://github.com/rmosolgo/graphql-libgraphqlparser-ruby)
81