Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed mutations #2025

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
37 changes: 19 additions & 18 deletions src/rust/terminusdb-community/src/graphql/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ pub struct FilterInputObject {
}

pub struct FilterInputObjectTypeInfo {
filter_type_name: GraphQLName<'static>,
type_name: GraphQLName<'static>,
frames: Arc<AllFrames>,
pub filter_type_name: GraphQLName<'static>,
pub type_name: GraphQLName<'static>,
pub allframes: Arc<AllFrames>,
}

impl FilterInputObjectTypeInfo {
pub fn new(type_name: &GraphQLName, all_frames: &Arc<AllFrames>) -> Self {
Self {
filter_type_name: filter_name(&type_name),
filter_type_name: filter_name(type_name),
type_name: type_name.as_static(),
frames: all_frames.clone(),
allframes: all_frames.clone(),
}
}
}
Expand All @@ -46,7 +46,7 @@ impl GraphQLType for FilterInputObject {
where
DefaultScalarValue: 'r,
{
if let Some(TypeDefinition::Class(d)) = &info.frames.frames.get(&info.type_name) {
if let Some(TypeDefinition::Class(d)) = &info.allframes.frames.get(&info.type_name) {
let mut args: Vec<_> = d
.fields()
.iter()
Expand Down Expand Up @@ -97,7 +97,7 @@ impl GraphQLType for FilterInputObject {
}
BaseOrDerived::Derived(c) => {
// is this foreign?
if info.frames.is_foreign(c) {
if info.allframes.is_foreign(c) {
registry.arg::<Option<CollectionIdFilterInputObject>>(
name.as_str(),
&(),
Expand All @@ -107,7 +107,7 @@ impl GraphQLType for FilterInputObject {
name.as_str(),
&CollectionFilterInputObjectTypeInfo::new(
c,
&info.frames,
&info.allframes,
),
)
}
Expand All @@ -132,24 +132,25 @@ impl GraphQLType for FilterInputObject {
BaseTypeKind::DateTime => registry
.arg::<Option<DateTimeFilterInputObject>>(name.as_str(), &()),
}
} else if let Some(enum_type) = field_definition.enum_type(&info.frames) {
} else if let Some(enum_type) = field_definition.enum_type(&info.allframes)
{
registry.arg::<Option<EnumFilterInputObject>>(
name.as_str(),
&EnumFilterInputObjectTypeInfo::new(enum_type, &info.frames),
&EnumFilterInputObjectTypeInfo::new(enum_type, &info.allframes),
)
} else {
match field_definition.range() {
BaseOrDerived::Base(_) => {
panic!("This branch should be unreachable - not a base type")
}
BaseOrDerived::Derived(c) => {
if info.frames.is_foreign(c) {
if info.allframes.is_foreign(c) {
registry
.arg::<Option<IdFilterInputObject>>(name.as_str(), &())
} else {
registry.arg::<Option<FilterInputObject>>(
name.as_str(),
&FilterInputObjectTypeInfo::new(c, &info.frames),
&FilterInputObjectTypeInfo::new(c, &info.allframes),
)
}
}
Expand All @@ -160,7 +161,7 @@ impl GraphQLType for FilterInputObject {
.collect();

let mut applicable_restrictions = Vec::new();
for restriction in info.frames.restrictions.values() {
for restriction in info.allframes.restrictions.values() {
if restriction.on == info.type_name {
applicable_restrictions.push(restriction.id.to_owned());
}
Expand All @@ -181,17 +182,17 @@ impl GraphQLType for FilterInputObject {

args.push(registry.arg::<Option<Vec<FilterInputObject>>>(
"_and",
&FilterInputObjectTypeInfo::new(&info.type_name, &info.frames),
&FilterInputObjectTypeInfo::new(&info.type_name, &info.allframes),
));

args.push(registry.arg::<Option<Vec<FilterInputObject>>>(
"_or",
&FilterInputObjectTypeInfo::new(&info.type_name, &info.frames),
&FilterInputObjectTypeInfo::new(&info.type_name, &info.allframes),
));

args.push(registry.arg::<Option<FilterInputObject>>(
"_not",
&FilterInputObjectTypeInfo::new(&info.type_name, &info.frames),
&FilterInputObjectTypeInfo::new(&info.type_name, &info.allframes),
));

registry
Expand Down Expand Up @@ -244,7 +245,7 @@ impl CollectionFilterInputObjectTypeInfo {

impl GraphQLType for CollectionFilterInputObject {
fn name(info: &Self::TypeInfo) -> Option<&str> {
Some(&info.filter_type_name.as_str())
Some(info.filter_type_name.as_str())
}

fn meta<'r>(
Expand Down Expand Up @@ -302,7 +303,7 @@ impl GraphQLValue for CollectionFilterInputObject {
type TypeInfo = CollectionFilterInputObjectTypeInfo;

fn type_name<'i>(&self, info: &'i Self::TypeInfo) -> Option<&'i str> {
Some(&info.filter_type_name.as_str())
Some(info.filter_type_name.as_str())
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/rust/terminusdb-community/src/graphql/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,9 +731,9 @@ pub struct ClassDefinition {
pub documentation: OneOrMore<ClassDocumentationDefinition>,
pub metadata: Option<serde_json::Value>,
pub key: Option<KeyDefinition>,
pub is_subdocument: Option<Vec<()>>,
pub is_unfoldable: Option<Vec<()>>,
pub is_abstract: Option<Vec<()>>,
pub is_subdocument: bool,
pub is_unfoldable: bool,
pub is_abstract: bool,
pub one_of: Option<Vec<OneOf>>,
pub inherits: Option<Vec<GraphQLName<'static>>>,
pub fields: BTreeMap<GraphQLName<'static>, FieldDefinition>,
Expand Down Expand Up @@ -801,9 +801,9 @@ impl UncleanClassDefinition {
documentation: OneOrMore::More(documentation),
metadata: self.metadata.clone(),
key,
is_subdocument: self.is_subdocument.clone(),
is_unfoldable: self.is_unfoldable.clone(),
is_abstract: self.is_abstract,
is_subdocument: self.is_subdocument.is_some(),
is_unfoldable: self.is_unfoldable.is_some(),
is_abstract: self.is_abstract.is_some(),
inherits,
one_of,
fields,
Expand Down
2 changes: 1 addition & 1 deletion src/rust/terminusdb-community/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ impl GraphQLExecutionContext {
TerminusTypeCollection,
TerminusMutationRoot,
EmptySubscription::<TerminusContext<'static>>::new(),
type_collection.clone(),
type_collection,
(),
(),
);

Self { root_node, context }
Expand Down