MCPcopy Index your code
hub / github.com/StellateHQ/graphql-query

github.com/StellateHQ/graphql-query @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
604 symbols 1,130 edges 47 files 96 documented · 16%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

graphql_query

Stupendously fast and easy GraphQL Query Language handling.

The graphql_query library follows two goals:

  • To support a pleasant-to-use API for the GraphQL Query Language
  • To be stupendously fast at processing GraphQL Query Language ASTs

In short, surprise! The graphql_query crate while handling a part of GraphQL does not aim to support full, server-side GraphQL execution or the GraphQL Schema Language. Many parts of the server-side execution of requests are one-off operations. Parsing a schema and using it are operations that could even be preprocessed using the reference GraphQL.js implementation.

A harder focus is to optimize how individual GraphQL requests are handled and making it easier to write complex code on top of an easy to use AST. GraphQL throughput is highly important in ensuring that GraphQL doesn't fall behind any other solutions, which don't feature a rich query language. On top, having an AST and library that's sufficiently easy to use and contains enough primitives and utilities at the same time as valuing performance is something that's harder to do when focusing on building a full GraphQL server.

As such, this library focuses on just processing GraphQL queries for the purpose of intermediary GraphQL layers, which operate inbetween GraphQL clients and GraphQL servers.

A good place to start learning more about this crate is the ast module...

Sample Code

The library currently consists of utilities to parse, print, validate, visit, and transform GraphQL Query Language ASTs.

use graphql_query::{ast::*, validate::*};

let ctx = ASTContext::new();
let ast = Document::parse(&ctx, "{ field }").unwrap();

DefaultRules::validate(&ctx, &ast).unwrap()

let output = ast.print();

Performance

How far along is this library in achieving that? Right on the mark.

Benchmarks performed on an M1 Macbook Pro

Parsing

test graphql_ast_parse_graphql_query   ... bench:       2,886 ns/iter (+/- 130)
test graphql_ast_parse_graphql_parser  ... bench:      25,122 ns/iter (+/- 1,711)
test graphql_ast_parse_apollo_parser   ... bench:      36,242 ns/iter (+/- 1,062)

Printing

test graphql_ast_print_graphql_query  ... bench:       1,082 ns/iter (+/- 79)
test graphql_ast_print_gql_parser     ... bench:       1,137 ns/iter (+/- 48)
test graphql_ast_print_apollo_parser  ... bench:      20,861 ns/iter (+/- 518)

Others

test graphql_ast_fold                 ... bench:       8,466 ns/iter (+/- 768)
test graphql_ast_validate             ... bench:       1,504 ns/iter (+/- 46)
test graphql_load_introspection       ... bench:      90,265 ns/iter (+/- 4,899)

What's not here

  • An SDL implementation
  • Schema-aware validation rules, but entirely possible with our schema_reference
  • The execute/collectFields algorithm - purposefully as we focussed on the execution language

Extension points exported contracts — how you extend this code

ParseNode (Interface)
(Private) Trait for parsing AST Nodes from a Parser Context. The [`super::ParseNode`] trait implements the public `parse [28 …
src/ast/parser.rs
Visitor (Interface)
Trait for a visitor that carries methods that are called as callback while AST nodes implementing the visitor pattern ar [14 …
src/visit/visitor.rs
ValueFromNode (Interface)
Trait for convertin AST Value Nodes of a GraphQL language document to [serde_json::Value]s. [9 implementers]
src/json/conversion.rs
ParseFromCtx (Interface)
(Private) Trait for parsing AST Nodes from a Parser Context. The [`super::ParseNode`] trait implements the public `parse [15 …
src/schema/sdl/parser.rs
ValidationRule (Interface)
Trait for a `ValidationRule` that checks a given `GraphQl` document against its rules using a visitor. A rule always im [11 …
src/validate/validate.rs
PrintNode (Interface)
Trait for printing AST Nodes to a new String allocated on the heap. This is implemented by all AST Nodes and can hence b [26 …
src/ast/printer.rs
FoldNode (Interface)
(no doc) [18 implementers]
src/visit/folder.rs
BuildSchemaType (Interface)
(no doc) [7 implementers]
src/schema/build_client_schema.rs

Core symbols most depended-on inside this repo

push
called by 125
src/visit/path.rs
alloc
called by 75
src/ast/ast.rs
assert_parse
called by 59
src/ast/parser.rs
next
called by 48
src/schema/sdl/parser.rs
next
called by 46
src/ast/parser.rs
pop
called by 46
src/visit/path.rs
peek
called by 28
src/ast/parser.rs
alloc_str
called by 28
src/ast/ast.rs

Shape

Method 317
Function 144
Class 92
Enum 27
Interface 24

Languages

Rust100%

Modules by API surface

src/ast/ast.rs64 symbols
src/schema/schema.rs58 symbols
src/visit/visitor.rs52 symbols
src/visit/folder.rs42 symbols
src/visit/folder_simple.rs39 symbols
src/ast/parser.rs27 symbols
src/visit/compose.rs26 symbols
src/schema/introspection.rs22 symbols
src/ast/printer.rs19 symbols
src/schema/sdl/tests.rs17 symbols
src/schema/sdl/parse_ast.rs16 symbols
src/ast/lexer.rs16 symbols

For agents

$ claude mcp add graphql-query \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page