#graphql #ast #validation #gql #tool

graphql-tools

Tools for working with GraphQL in Rust, based on graphql-parser Document

29 releases

new 0.4.0 Nov 13, 2024
0.2.5 Feb 15, 2024
0.2.2 Feb 13, 2023
0.2.1 Dec 5, 2022
0.0.9 Dec 28, 2021

#47 in HTTP server

Download history 1012/week @ 2024-07-25 891/week @ 2024-08-01 857/week @ 2024-08-08 858/week @ 2024-08-15 960/week @ 2024-08-22 994/week @ 2024-08-29 929/week @ 2024-09-05 926/week @ 2024-09-12 824/week @ 2024-09-19 731/week @ 2024-09-26 875/week @ 2024-10-03 698/week @ 2024-10-10 1004/week @ 2024-10-17 766/week @ 2024-10-24 790/week @ 2024-10-31 829/week @ 2024-11-07

3,483 downloads per month
Used in hive-apollo-router-plugin

MIT/Apache

495KB
13K SLoC

graphql-tools (Rust)

Documentation | Crate | GitHub

The graphql_tools crate implements tooling around GraphQL for Rust libraries. Most of the tools are based on traits and structs implemented in graphql_parser crate.

The goal of this library is to create a common layer of tools that has similar/improved APIs to graphql-js reference implementation and graphql-tools from the JS/TS ecosystem.

Getting Started

Crates.io

Add graphql-tools as a dependency of your project by adding the following to your Cargo.toml file:

[dependencies]
graphql-tools = "..."

Or, if you are using cargo-edit:

cargo add graphql-tools

By default, this crate is using the graphql-parser library for parsing. If you wish to use an alternative implementation such as graphql-hive/graphql-parser-hive-fork, use the following features setup:

[dependencies]
graphql-tools = { version = "...", features = "graphql_parser_fork", default-features = false }

Validation Rules

This comparison is based on graphql-js reference implementation.

  • ExecutableDefinitions (not actually needed)
  • UniqueOperationNames
  • LoneAnonymousOperation
  • SingleFieldSubscriptions
  • KnownTypeNames
  • FragmentsOnCompositeTypes
  • VariablesAreInputTypes
  • LeafFieldSelections
  • FieldsOnCorrectType
  • UniqueFragmentNames
  • KnownFragmentNames
  • NoUnusedFragments
  • PossibleFragmentSpreads
  • NoFragmentCycles
  • UniqueVariableNames
  • NoUndefinedVariables
  • NoUnusedVariables
  • KnownDirectives
  • UniqueDirectivesPerLocation
  • KnownArgumentNames
  • UniqueArgumentNames
  • ValuesOfCorrectType
  • ProvidedRequiredArguments
  • VariablesInAllowedPosition
  • OverlappingFieldsCanBeMerged
  • UniqueInputFieldNames (blocked by https://github.com/graphql-rust/graphql-parser/issues/59)

Dependencies

~1.2–2.3MB
~49K SLoC