libgraphql
Documentation | Github | Crate
libgraphql is a comprehensive "GraphQL Engine" for building tools, clients,
and servers that need to validate, interpret, execute, or otherwise
manipulate GraphQ schemas and operations.
Broadly, libgraphql models GraphQL systems in terms of a validated[^1]
Schema
(which defines types and directives) and a collection of zero or more validated[^2]
Operations
(queries, mutations, & subscriptions).
[^1]: libgraphql validates
Schema
objects as they are
built
by type-checking all type & directive definitions and validating most of the
constraints specified in the
latest GraphQL specification.
[^2]: libgraphql validates all
Operation
objects (including
Query,
Mutation,
and
Subscription
objects) as they are
built
by type-checking and validating each operation against a pre-validated
Schema.
Quick Start
Add libgraphql to your Cargo.toml:
Basic usage:
use graphql_schema;
use QueryBuilder;
use Schema;
// Write a GraphQL schema directly in rust code
let schema = graphql_schema! ;
// Or load the GraphQL schema from a file on disk at runtime:
let schema =
build_from_file.expect;
// Print all GraphQL types defined in the loaded schema:
for in schema.defined_types
// Find the `User` object type in the `Schema`:
let user_type =
schema.defined_types
.get
.expect;
// Build a GraphQL query from a string at runtime:
let query_str = r##"
query MyFullName {
me {
firstName,
lastName,
}
}
"##;
let frag_registry = empty;
let query = build_from_str.expect;
// Or load a query from a file on disk at runtime:
let query =
build_from_file.expect;
// Identify the name and type of each root field selected in the query:
println!;
for field_selection in query.selection_set.selected_fields
Development Details
Testing
Run all tests:
Run all tests and generate test coverage output:
Documentation
Generate and view the API documentation:
Online documentation is available at: https://docs.rs/libgraphql/latest/libgraphql/
License
libgraphql is MIT licensed.
libgraphql re-exports some types provided by the graphql_parser crate, which is licensed under the MIT license.