Skip to content

Commit

Permalink
fix: bug in modify for graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Heikel Bouzayene authored and Heikel Bouzayene committed Oct 9, 2024
1 parent b3261e4 commit 80a9e61
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
15 changes: 13 additions & 2 deletions src/core/blueprint/operators/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@ fn create_related_fields(

if let Some(type_) = config.find_type(type_name) {
for (name, field) in &type_.fields {
if !field.has_resolver() {
if field.modify.is_some() {
map.insert(
field.modify.clone().unwrap().name.unwrap(),
(
name.clone(),
create_related_fields(config, field.type_of.name(), visited),
),
);

Check warning on line 34 in src/core/blueprint/operators/graphql.rs

View check run for this annotation

Codecov / codecov/patch

src/core/blueprint/operators/graphql.rs#L28-L34

Added lines #L28 - L34 were not covered by tests
} else if !field.has_resolver() {
map.insert(
name.clone(),
create_related_fields(config, field.type_of.name(), visited),
(
name.clone(),
create_related_fields(config, field.type_of.name(), visited),
),
);
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/core/ir/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ fn format_selection_set<'a>(
let set = selection_set
.filter_map(|field| {
// add to set only related fields that should be resolved with current resolver
related_fields
.get(field.name())
.map(|related_fields| format_selection_field(field, related_fields))
related_fields.get(field.name()).map(|related_fields| {
format_selection_field(field, &related_fields.0, &related_fields.1)
})
})
.collect::<Vec<_>>();

Expand All @@ -143,8 +143,11 @@ fn format_selection_set<'a>(
Some(format!("{{ {} }}", set.join(" ")))
}

fn format_selection_field(field: &SelectionField, related_fields: &RelatedFields) -> String {
let name = field.name();
fn format_selection_field(
field: &SelectionField,
name: &str,
related_fields: &RelatedFields,
) -> String {
let arguments = format_selection_field_arguments(field);
let selection_set = format_selection_set(field.selection_set(), related_fields);

Expand Down
4 changes: 2 additions & 2 deletions src/core/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub use resolver_context_like::{
/// resolver i.e. fields that don't have their own resolver and are resolved by
/// the ancestor
#[derive(Debug, Default, Clone)]
pub struct RelatedFields(pub HashMap<String, RelatedFields>);
pub struct RelatedFields(pub HashMap<String, (String, RelatedFields)>);

impl Deref for RelatedFields {
type Target = HashMap<String, RelatedFields>;
type Target = HashMap<String, (String, RelatedFields)>;

fn deref(&self) -> &Self::Target {
&self.0
Expand Down

0 comments on commit 80a9e61

Please sign in to comment.