Skip to content

Commit

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

use indexmap::IndexMap;

use super::InputObjectTypeDefinition;
Expand Down Expand Up @@ -40,16 +38,6 @@ 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
19 changes: 16 additions & 3 deletions src/core/jit/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
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, Index, QueryField};
use crate::core::blueprint::{Blueprint, Definition, Index, QueryField};
use crate::core::counter::{Count, Counter};
use crate::core::jit::model::OperationPlan;
use crate::core::{scalar, Type};
Expand Down Expand Up @@ -66,6 +66,7 @@ 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 @@ -75,11 +76,23 @@ 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 @@ -364,7 +377,7 @@ impl<'a> Builder<'a> {
operation.ty,
self.index.clone(),
is_introspection_query,
Some(self.index.get_interfaces()),
Some(Arc::clone(&self.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<HashSet<String>>,
pub interfaces: Option<Arc<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<HashSet<String>>,
interfaces: Option<Arc<HashSet<String>>>,
) -> Self
where
Input: Clone,
Expand Down

0 comments on commit c12bc49

Please sign in to comment.