Skip to content

Commit

Permalink
fix: remove arc and take it from index
Browse files Browse the repository at this point in the history
  • Loading branch information
MedHeikelBouzayene committed Jan 5, 2025
1 parent e1db59b commit e6539b0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
12 changes: 12 additions & 0 deletions src/core/blueprint/index.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use indexmap::IndexMap;

use super::InputObjectTypeDefinition;
Expand Down Expand Up @@ -38,6 +40,16 @@ impl Index {
matches!(def, Some(Definition::Scalar(_))) || scalar::Scalar::is_predefined(type_name)
}

pub fn get_interfaces(&self) -> HashSet<String> {
self.map
.iter()
.filter_map(|(_, (def, _))| match def {
Definition::Interface(interface) => Some(interface.name.to_owned()),
_ => None,
})
.collect()
}

pub fn type_is_enum(&self, type_name: &str) -> bool {
let def = self.map.get(type_name).map(|(def, _)| def);

Expand Down
18 changes: 3 additions & 15 deletions src/core/jit/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::ops::Deref;
use std::sync::Arc;

Expand All @@ -11,7 +11,7 @@ use async_graphql_value::Value;

use super::model::{Directive as JitDirective, *};
use super::BuildError;
use crate::core::blueprint::{Blueprint, Definition, Index, QueryField};
use crate::core::blueprint::{Blueprint, Index, QueryField};
use crate::core::counter::{Count, Counter};
use crate::core::jit::model::OperationPlan;
use crate::core::{scalar, Type};
Expand Down Expand Up @@ -66,7 +66,6 @@ impl Conditions {

pub struct Builder<'a> {
pub index: Arc<Index>,
pub interfaces: Arc<HashSet<String>>,
pub arg_id: Counter<usize>,
pub field_id: Counter<usize>,
pub document: &'a ExecutableDocument,
Expand All @@ -76,23 +75,12 @@ pub struct Builder<'a> {
impl<'a> Builder<'a> {
pub fn new(blueprint: &Blueprint, document: &'a ExecutableDocument) -> Self {
let index = Arc::new(blueprint.index());
let interfaces = Arc::new(
blueprint
.definitions
.iter()
.filter_map(|def| match def {
Definition::Interface(interface) => Some(interface.name.to_owned()),
_ => None,
})
.collect(),
);

Self {
document,
index,
arg_id: Counter::default(),
field_id: Counter::default(),
interfaces,
}
}

Expand Down Expand Up @@ -377,7 +365,7 @@ impl<'a> Builder<'a> {
operation.ty,
self.index.clone(),
is_introspection_query,
Some(Arc::clone(&self.interfaces)),
Some(self.index.get_interfaces()),
);
Ok(plan)
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/jit/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub struct OperationPlan<Input> {
pub min_cache_ttl: Option<NonZeroU64>,
pub selection: Vec<Field<Input>>,
pub before: Option<IR>,
pub interfaces: Option<Arc<HashSet<String>>>,
pub interfaces: Option<HashSet<String>>,
}

impl<Input> OperationPlan<Input> {
Expand Down Expand Up @@ -355,7 +355,7 @@ impl<Input> OperationPlan<Input> {
operation_type: OperationType,
index: Arc<Index>,
is_introspection_query: bool,
interfaces: Option<Arc<HashSet<String>>>,
interfaces: Option<HashSet<String>>,
) -> Self
where
Input: Clone,
Expand Down

0 comments on commit e6539b0

Please sign in to comment.