Skip to content

Commit b83db33

Browse files
committed
added feature-based parser
1 parent 95f114e commit b83db33

12 files changed

+88
-31
lines changed

Cargo.lock

Lines changed: 58 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ documentation = "https://github.com/dotansimha/graphql-tools-rs"
1111
authors = ["Dotan Simha <[email protected]>"]
1212

1313
[dependencies]
14-
graphql-parser = { version = "0.5.0", package = "graphql-parser-hive-fork" }
14+
graphql-parser = { version = "^0.4.0", optional = true }
15+
graphql-parser-hive-fork = { version = "^0.5.0", optional = true }
1516
lazy_static = "1.4.0"
1617
serde = { version = "1.0", features = ["derive"] }
1718
serde_json = "1.0"
1819
serde_with = "2.2.0"
1920

20-
[dev-dependencies]
21-
graphql-parser = { version = "0.5.0", package = "graphql-parser-hive-fork" }
21+
[features]
22+
default = ["graphql_parser"]
23+
graphql_parser_fork = ["dep:graphql-parser-hive-fork"]
24+
graphql_parser = ["dep:graphql-parser"]

README.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
[Documentation](https://docs.rs/graphql-tools) | [Crate](https://crates.io/crates/graphql-tools) | [GitHub](https://github.com/dotansimha/graphql-tools-rs)
44

5-
> **Note: this crate is still under development (see roadmap below)**
6-
75
The [`graphql_tools` crate](https://crates.io/crates/graphql-tools) implements tooling around GraphQL for Rust libraries. Most of the tools are based on `trait`s and `struct`s implemented in [`graphql_parser` crate](https://crates.io/crates/graphql-parser).
86

97
The goal of this library is to create a common layer of tools that has similar/improved APIs to [`graphql-js` reference implementation](https://github.com/graphql/graphql-js) and [`graphql-tools` from the JS/TS ecosystem](https://github.com/ardatan/graphql-tools).
@@ -25,23 +23,16 @@ Or, if you are using [`cargo-edit`](https://github.com/killercup/cargo-edit):
2523
cargo add graphql-tools
2624
```
2725

28-
### Roadmap and progress
29-
30-
- [ ] Better documentation
31-
- [x] AST Visitor for GraphQL schema (`graphql_parser::schema::Document`)
32-
- [x] AST Visitor for GraphQL operations (`graphql_parser::operation::Document`)
33-
- [x] AST Visitor with TypeInfo
34-
- [x] AST tools (ongoing)
35-
- [x] `struct` extensions
36-
- [x] GraphQL Validation engine
37-
- [x] Validation rules
38-
- [x] GraphQL operations transformer
26+
By default, this crate is using the [`graphql-parser`](https://github.com/graphql-rust/graphql-parser) library for parsing. If you wish to use an alternative implementation such as [`graphql-hive/graphql-parser-hive-fork`](https://github.com/graphql-hive/graphql-parser-hive-fork), use the following `features` setup:
3927

40-
> If you have an idea / missing feature, feel free to open an issue / start a GitHub discussion!
28+
```toml
29+
[dependencies]
30+
graphql-tools = { version = "...", features = "graphql_parser_fork", default-features = false }
31+
```
4132

4233
#### Validation Rules
4334

44-
> This comparison is based on `graphql-js` refernece implementation.
35+
> This comparison is based on `graphql-js` refernece implementation.
4536
4637
- [x] ExecutableDefinitions (not actually needed)
4738
- [x] UniqueOperationNames
@@ -68,4 +59,4 @@ cargo add graphql-tools
6859
- [x] ProvidedRequiredArguments
6960
- [x] VariablesInAllowedPosition
7061
- [x] OverlappingFieldsCanBeMerged
71-
- [ ] UniqueInputFieldNames (blocked by https://github.com/graphql-rust/graphql-parser/issues/59)
62+
- [ ] UniqueInputFieldNames (blocked by https://github.com/graphql-rust/graphql-parser/issues/59)

src/ast/operation_transformer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use graphql_parser::query::*;
1+
use crate::parser::query::*;
22

33
#[derive(Clone, Debug)]
44
pub enum Transformed<T> {

src/ast/operation_visitor.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::{BTreeMap, HashMap};
22

3-
use graphql_parser::query::TypeCondition;
3+
use crate::parser::query::TypeCondition;
44

55
use crate::static_graphql::{
66
query::{self, *},
@@ -278,7 +278,8 @@ fn visit_input_value<'a, Visitor, UserContext>(
278278
let input_type = context
279279
.current_input_type_literal()
280280
.and_then(|v| context.schema.type_by_name(v.inner_type()))
281-
.and_then(|v| v.input_field_by_name(sub_key)).map(|v| &v.value_type);
281+
.and_then(|v| v.input_field_by_name(sub_key))
282+
.map(|v| &v.value_type);
282283

283284
context.with_input_type(input_type, |context| {
284285
let param = &(sub_key.clone(), sub_value.clone());

src/ast/schema_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub trait SchemaVisitor<T = ()> {
174174

175175
#[test]
176176
fn visit_schema() {
177-
use graphql_parser::schema::parse_schema;
177+
use crate::parser::schema::parse_schema;
178178
let schema_ast = parse_schema(
179179
r#"
180180
scalar Date

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod static_graphql {
1111
macro_rules! static_graphql {
1212
($m:ident, $m2:ident, {$($n:ident,)*}) => {
1313
pub mod $m {
14-
use graphql_parser::$m2 as $m;
14+
use crate::parser::$m2 as $m;
1515
pub use $m::*;
1616
$(
1717
pub type $n = $m::$n<'static, String>;
@@ -35,3 +35,8 @@ pub mod static_graphql {
3535
pub mod introspection;
3636

3737
pub mod validation;
38+
39+
#[cfg(feature = "graphql_parser")]
40+
pub extern crate graphql_parser as parser;
41+
#[cfg(feature = "graphql_parser_fork")]
42+
pub extern crate graphql_parser_hive_fork as parser;

src/validation/rules/overlapping_fields_can_be_merged.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use graphql_parser::query::{Definition, TypeCondition};
2-
use graphql_parser::Pos;
1+
use crate::parser::query::{Definition, TypeCondition};
2+
use crate::parser::Pos;
33

44
use super::ValidationRule;
55
use crate::ast::ext::TypeDefinitionExtension;

src/validation/rules/unique_argument_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use graphql_parser::Pos;
3+
use crate::parser::Pos;
44

55
use super::ValidationRule;
66
use crate::ast::{visit_document, OperationVisitor, OperationVisitorContext};

src/validation/rules/unique_variable_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::hash_map::Entry;
22
use std::collections::HashMap;
33

4-
use graphql_parser::Pos;
4+
use crate::parser::Pos;
55

66
use super::ValidationRule;
77
use crate::ast::{visit_document, OperationVisitor, OperationVisitorContext};

0 commit comments

Comments
 (0)