Skip to content

Commit 7c9ba34

Browse files
authored
Refactor and introduce new OperationVisitor (#29)
1 parent ecd3b98 commit 7c9ba34

38 files changed

+4038
-2785
lines changed

src/ast/ast_visitor.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/ast/collect_fields.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use std::collections::HashMap;
22

3-
use super::{AbstractTypeDefinitionExtension, TypeInfoRegistry};
3+
use super::{AbstractTypeDefinitionExtension, OperationVisitorContext, SchemaDocumentExtension};
44
use crate::ast::ext::{SubTypeExtension, TypeDefinitionExtension};
55
use crate::static_graphql::{
66
query::{self, Selection, TypeCondition},
77
schema::{self, TypeDefinition},
88
};
9-
pub fn collect_fields(
9+
pub fn collect_fields<'a>(
1010
selection_set: &query::SelectionSet,
1111
parent_type: &schema::TypeDefinition,
1212
known_fragments: &HashMap<String, query::FragmentDefinition>,
13-
type_info_registry: &TypeInfoRegistry,
13+
context: &'a OperationVisitorContext<'a>,
1414
) -> HashMap<String, Vec<query::Field>> {
1515
let mut map = HashMap::new();
1616
let mut visited_fragments_names: Vec<String> = Vec::new();
@@ -19,7 +19,7 @@ pub fn collect_fields(
1919
selection_set,
2020
parent_type,
2121
known_fragments,
22-
type_info_registry,
22+
context,
2323
&mut map,
2424
&mut visited_fragments_names,
2525
);
@@ -30,10 +30,10 @@ pub fn collect_fields(
3030
fn does_fragment_condition_match<'a>(
3131
fragment_condition: &'a Option<TypeCondition>,
3232
current_selection_set_type: &'a TypeDefinition,
33-
type_info_registry: &'a TypeInfoRegistry<'a>,
33+
context: &'a OperationVisitorContext<'a>,
3434
) -> bool {
3535
if let Some(TypeCondition::On(type_name)) = fragment_condition {
36-
if let Some(conditional_type) = type_info_registry.type_by_name.get(type_name) {
36+
if let Some(conditional_type) = context.schema.type_by_name(type_name) {
3737
if conditional_type
3838
.name()
3939
.eq(&current_selection_set_type.name())
@@ -60,11 +60,11 @@ fn does_fragment_condition_match<'a>(
6060
}
6161
}
6262

63-
fn collect_fields_inner(
63+
fn collect_fields_inner<'a>(
6464
selection_set: &query::SelectionSet,
6565
parent_type: &schema::TypeDefinition,
6666
known_fragments: &HashMap<String, query::FragmentDefinition>,
67-
type_info_registry: &TypeInfoRegistry,
67+
context: &'a OperationVisitorContext<'a>,
6868
result_arr: &mut HashMap<String, Vec<query::Field>>,
6969
visited_fragments_names: &mut Vec<String>,
7070
) {
@@ -74,12 +74,12 @@ fn collect_fields_inner(
7474
existing.push(f.clone());
7575
}
7676
Selection::InlineFragment(f) => {
77-
if does_fragment_condition_match(&f.type_condition, parent_type, type_info_registry) {
77+
if does_fragment_condition_match(&f.type_condition, parent_type, context) {
7878
collect_fields_inner(
7979
&f.selection_set,
8080
&parent_type,
8181
known_fragments,
82-
type_info_registry,
82+
context,
8383
result_arr,
8484
visited_fragments_names,
8585
);
@@ -97,13 +97,13 @@ fn collect_fields_inner(
9797
if does_fragment_condition_match(
9898
&Some(fragment.type_condition.clone()),
9999
&parent_type,
100-
type_info_registry,
100+
context,
101101
) {
102102
collect_fields_inner(
103103
&fragment.selection_set,
104104
&parent_type,
105105
known_fragments,
106-
type_info_registry,
106+
context,
107107
result_arr,
108108
visited_fragments_names,
109109
);

0 commit comments

Comments
 (0)