-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): more filters and basic ordering (#18)
* misc: Cleanup * feat(sdk): Refactor query building and add more filters + sorting * feat(api): Add more filters and ordering to API * style: fmt * misc: Rename `Attribute` to `Property` across the board * Revert "misc: Rename `Attribute` to `Property` across the board" This reverts commit 00dc6a0. * fix(api): Entity types * misc: "Fix" codegen * test(sdk): Fix tests * docs: Update GraphQL schema * style(sdk): clippy + fmt * test: Remove unused tests * test(sdk): Fix tests (again)
- Loading branch information
Showing
33 changed files
with
2,246 additions
and
635 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
use juniper::GraphQLInputObject; | ||
|
||
use sdk::mapping; | ||
|
||
use crate::schema::ValueType; | ||
|
||
/// Filter the entities by attributes and their values and value types | ||
#[derive(Debug, GraphQLInputObject)] | ||
pub struct EntityAttributeFilter { | ||
pub attribute: String, | ||
|
||
pub value: Option<String>, | ||
pub value_not: Option<String>, | ||
pub value_in: Option<Vec<String>>, | ||
pub value_not_in: Option<Vec<String>>, | ||
|
||
pub value_type: Option<ValueType>, | ||
pub value_type_not: Option<ValueType>, | ||
pub value_type_in: Option<Vec<ValueType>>, | ||
pub value_type_not_in: Option<Vec<ValueType>>, | ||
} | ||
|
||
impl EntityAttributeFilter { | ||
pub fn add_to_entity_query( | ||
self, | ||
mut query: mapping::entity_queries::FindMany, | ||
) -> mapping::entity_queries::FindMany { | ||
if let Some(value) = self.value { | ||
query = query.attribute(&self.attribute, &value); | ||
} | ||
|
||
if let Some(value_not) = self.value_not { | ||
query = query.attribute_not(&self.attribute, &value_not); | ||
} | ||
|
||
if let Some(value_in) = self.value_in { | ||
query = query.attribute_in(&self.attribute, value_in.clone()); | ||
} | ||
|
||
if let Some(value_not_in) = self.value_not_in { | ||
query = query.attribute_not_in(&self.attribute, value_not_in.clone()); | ||
} | ||
|
||
if let Some(value_type) = self.value_type { | ||
query = query.attribute_value_type(&self.attribute, &value_type.to_string()); | ||
} | ||
|
||
if let Some(value_type_not) = self.value_type_not { | ||
query = query.attribute_value_type_not(&self.attribute, &value_type_not.to_string()); | ||
} | ||
|
||
if let Some(value_type_in) = self.value_type_in { | ||
query = query.attribute_value_type_in( | ||
&self.attribute, | ||
value_type_in.into_iter().map(|vt| vt.to_string()).collect(), | ||
); | ||
} | ||
|
||
if let Some(value_type_not_in) = self.value_type_not_in { | ||
query = query.attribute_value_type_not_in( | ||
&self.attribute, | ||
value_type_not_in | ||
.into_iter() | ||
.map(|vt| vt.to_string()) | ||
.collect(), | ||
); | ||
} | ||
|
||
query | ||
} | ||
|
||
pub fn add_to_relation_query( | ||
self, | ||
mut query: mapping::relation_queries::FindMany, | ||
) -> mapping::relation_queries::FindMany { | ||
if let Some(value) = self.value { | ||
query = query.attribute(&self.attribute, &value); | ||
} | ||
|
||
if let Some(value_not) = self.value_not { | ||
query = query.attribute_not(&self.attribute, &value_not); | ||
} | ||
|
||
if let Some(value_in) = self.value_in { | ||
query = query.attribute_in(&self.attribute, value_in.clone()); | ||
} | ||
|
||
if let Some(value_not_in) = self.value_not_in { | ||
query = query.attribute_not_in(&self.attribute, value_not_in.clone()); | ||
} | ||
|
||
if let Some(value_type) = self.value_type { | ||
query = query.attribute_value_type(&self.attribute, &value_type.to_string()); | ||
} | ||
|
||
if let Some(value_type_not) = self.value_type_not { | ||
query = query.attribute_value_type_not(&self.attribute, &value_type_not.to_string()); | ||
} | ||
|
||
if let Some(value_type_in) = self.value_type_in { | ||
query = query.attribute_value_type_in( | ||
&self.attribute, | ||
value_type_in.into_iter().map(|vt| vt.to_string()).collect(), | ||
); | ||
} | ||
|
||
if let Some(value_type_not_in) = self.value_type_not_in { | ||
query = query.attribute_value_type_not_in( | ||
&self.attribute, | ||
value_type_not_in | ||
.into_iter() | ||
.map(|vt| vt.to_string()) | ||
.collect(), | ||
); | ||
} | ||
|
||
query | ||
} | ||
} |
Oops, something went wrong.