• Stars
    star
    1,069
  • Rank 43,234 (Top 0.9 %)
  • Language
    C++
  • License
    MIT License
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A GraphQL query parser in C++ with C and C++ APIs

libgraphqlparser

libgraphqlparser is a parser for GraphQL, a query language 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, first, compile and install the library as described above. Then, please download googletest from https://github.com/google/googletest/archive/release-1.8.0.zip and unzip it in the test subdirectory. In consequence, a folder googletest-release-1.8.0 should be contained in test. Next, within the test folder, run cmake . and make to generate the runTests binary. To execute the tests run ./test/runTests from the main folder.

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 MIT-licensed.

Related Projects

Contributing to this repo

This repository is managed by EasyCLA. Project participants must sign the free (GraphQL Specification Membership agreement before making a contribution. You only need to do this one time, and it can be signed by individual contributors or their employers.

To initiate the signature process please open a PR against this repo. The EasyCLA bot will block the merge if we still need a membership agreement from you.

You can find detailed information here. If you have issues, please email [email protected].

If your company benefits from GraphQL and you would like to provide essential financial support for the systems and people that power our community, please also consider membership in the GraphQL Foundation.

More Repositories

1

graphql-js

A reference implementation of GraphQL for JavaScript
TypeScript
20,017
star
2

graphiql

GraphiQL & the GraphQL LSP Reference Ecosystem for building browser & IDE tools.
TypeScript
16,071
star
3

graphql-spec

GraphQL is a query language and execution engine tied to any backend service.
Shell
14,293
star
4

dataloader

DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching.
JavaScript
12,787
star
5

graphql-playground

๐ŸŽฎ GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration)
TypeScript
8,766
star
6

express-graphql

Create a GraphQL HTTP server with Express.
TypeScript
6,341
star
7

graphql-relay-js

A library to help construct a graphql-js server supporting react-relay.
TypeScript
1,537
star
8

swapi-graphql

A GraphQL schema and server wrapping SWAPI.
JavaScript
1,039
star
9

graphql.github.io

GraphQL Documentation at graphql.org
MDX
830
star
10

vscode-graphql

MIGRATED: VSCode GraphQL extension (autocompletion, go-to definition, syntax highlighting)
TypeScript
555
star
11

graphql-wg

Working group notes for GraphQL
JavaScript
528
star
12

graphql-language-service

An interface for building GraphQL language services for IDEs
420
star
13

graphql-over-http

Working draft of "GraphQL over HTTP" specification
JavaScript
386
star
14

graphql-landscape

๐ŸŒ„Landscape for the GraphQL ecosystem
308
star
15

graphql-http

Simple, pluggable, zero-dependency, GraphQL over HTTP spec compliant server, client and audit suite.
TypeScript
300
star
16

codemirror-graphql

GraphQL mode and helpers for CodeMirror.
148
star
17

foundation

GraphQL Foundation Charter and Legal Documents
87
star
18

composite-schemas-wg

The GraphQL Composite Schemas WG (subcommittee)
JavaScript
62
star
19

graphql-scalars

GraphQL Scalars specifications repo.
Shell
41
star
20

faq

GraphQL FAQ
37
star
21

defer-stream-wg

Repository for discussions on the GraphQL defer-stream spec proposal
JavaScript
28
star
22

nullability-wg

JavaScript
27
star
23

graphql-js-wg

Working group notes for graphql-js
JavaScript
25
star
24

composite-schemas-spec

Shell
22
star
25

marketing

Foundation marketing work
HTML
13
star
26

EasyCLA

Test repo for setting up EasyCLA, the tool we'll use to manage specification membership sigs
5
star
27

graphql-directory

The GraphQL Directory is used to manage project mailing lists
Python
4
star
28

wg-template

A template for GraphQL subcommittees
1
star
29

.github

Default community health files for GraphQL Foundation
1
star