Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

Seanaye/feat/better input ast (#4403)

Sean Aye9228af8ef129
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 4317ba39d5..049dc2bd94 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -5427,12 +5427,15 @@ version = "0.1.0"
dependencies = [
"async-graphql",
"async-trait",
+ "chrono",
+ "document_sub_type",
"either",
"entity_access",
"filter_ast",
"item_filters",
"macro_user_id",
"model-entity",
+ "model_file_type",
"models_pagination",
"models_properties",
"models_soup",
diff --git a/rust/cloud-storage/graphql_soup/Cargo.toml b/rust/cloud-storage/graphql_soup/Cargo.toml
index 185a9ec810..0dce0f2156 100644
--- a/rust/cloud-storage/graphql_soup/Cargo.toml
+++ b/rust/cloud-storage/graphql_soup/Cargo.toml
@@ -7,11 +7,14 @@ publish = false
[dependencies]
async-graphql = { workspace = true, features = ["dataloader"] }
async-trait = { workspace = true }
+chrono = { workspace = true }
+document_sub_type = { path = "../document_sub_type" }
either = { workspace = true }
entity_access = { path = "../entity_access", default-features = false }
filter_ast = { path = "../filter_ast" }
item_filters = { path = "../item_filters" }
macro_user_id = { path = "../macro_user_id" }
+model_file_type = { path = "../model_file_type" }
model-entity = { path = "../model-entity" }
models_pagination = { path = "../models_pagination" }
models_properties = { path = "../models_properties" }
diff --git a/rust/cloud-storage/graphql_soup/src/inputs.rs b/rust/cloud-storage/graphql_soup/src/inputs.rs
index 685e36b8f9..d85a9734f0 100644
--- a/rust/cloud-storage/graphql_soup/src/inputs.rs
+++ b/rust/cloud-storage/graphql_soup/src/inputs.rs
@@ -1,9 +1,27 @@
+use std::{str::FromStr, sync::Arc};
+
use async_graphql::{Enum, ID};
+use chrono::{DateTime, Utc};
+use document_sub_type::DocumentSubType;
+use filter_ast::Expr;
use item_filters::{
- CallFilters, CallStatus, ChannelFilters, ChannelThreadFilters, ChatFilters, CrmCompanyFilters,
- DocumentFilters, EmailFilters, EntityFilters, ForeignEntityFilters, NotificationFilters,
- ProjectFilters, PropertyFilter, SharedEmailFilter, TaskFilters, ast::EntityFilterAst,
+ CallStatus, SharedEmailFilter,
+ ast::{
+ CrmScope, EmailFilterAst, EntityFilterAst,
+ call::CallLiteral,
+ channel::{ChannelLiteral, ChannelThreadLiteral, ChannelTypeFilter},
+ chat::{ChatLiteral, ChatRole},
+ crm_company::CrmCompanyLiteral,
+ date::DateLiteral,
+ document::DocumentLiteral,
+ email::{Email, EmailLiteral},
+ foreign_entity::ForeignEntityLiteral,
+ project::ProjectLiteral,
+ properties::{EntityRefId, PropertiesLiteral, PropertyEntityType, PropertyMatchValue},
+ },
};
+use macro_user_id::{cowlike::CowLike, email::EmailStr, user_id::MacroUserIdStr};
+use model_file_type::FileType;
use models_pagination::{Base64Str, CursorWithValAndFilter, SimpleSortMethod};
use soup::domain::models::{SoupQuery, SoupRequest, SoupType};
use uuid::Uuid;
@@ -22,8 +40,10 @@ pub struct SoupInput {
sort_method: Option<GraphqlSimpleSortMethod>,
/// Opaque cursor returned by a previous GraphQL Soup response.
cursor: Option<String>,
- /// Typed filters applied to each Soup entity type.
- filters: Option<GraphqlEntityFilters>,
+ /// Email preview view used when hydrating email Soup items.
+ email_view: Option<GraphqlEmailView>,
+ /// AST-shaped filters applied to each Soup entity type.
+ filters: Option<GraphqlEntityFilterAst>,
}
impl SoupInput {
@@ -33,7 +53,7 @@ impl SoupInput {
) -> async_graphql::Result<SoupRequest<EntityFilterAst>> {
let filter = self
.filters
- .map(GraphqlEntityFilters::into_ast)
+ .map(GraphqlEntityFilterAst::into_ast)
.transpose()?
.unwrap_or_default();
let sort = self
@@ -61,221 +81,533 @@ impl SoupInput {
limit: self.limit.unwrap_or(20).min(500),
cursor,
user: request_context.macro_user_id.clone(),
- email_preview_view: Default::default(),
+ email_preview_view: self
+ .email_view
+ .map(GraphqlEmailView::as_preview_view_str)
+ .unwrap_or("inbox")
+ .parse()
+ .map_err(async_graphql::Error::new)?,
link_ids: request_context.link_ids.clone(),
})
}
}
+#[derive(Enum, Copy, Clone, Eq, PartialEq)]
+enum GraphqlEmailView {
+ Inbox,
+ Drafts,
+ Sent,
+ All,
+ Starred,
+ Important,
+ Other,
+}
+
+impl GraphqlEmailView {
+ fn as_preview_view_str(self) -> &'static str {
+ match self {
+ Self::Inbox => "inbox",
+ Self::Drafts => "drafts",
+ Self::Sent => "sent",
+ Self::All => "all",
+ Self::Starred => "starred",
+ Self::Important => "important",
+ Self::Other => "other",
+ }
+ }
+}
+
+/// GraphQL input mirroring `item_filters::ast::EntityFilterAst`.
#[derive(async_graphql::InputObject)]
-struct GraphqlEntityFilters {
- project_filters: Option<GraphqlProjectFilters>,
- document_filters: Option<GraphqlDocumentFilters>,
- chat_filters: Option<GraphqlChatFilters>,
- channel_filters: Option<GraphqlChannelFilters>,
- channel_thread_filters: Option<GraphqlChannelThreadFilters>,
- call_filters: Option<GraphqlCallFilters>,
- email_filters: Option<GraphqlEmailFilters>,
- crm_company_filters: Option<GraphqlCrmCompanyFilters>,
- foreign_entity_filters: Option<GraphqlForeignEntityFilters>,
- #[graphql(default)]
- property_filters: Vec<GraphqlPropertyFilter>,
-}
-
-impl GraphqlEntityFilters {
+struct GraphqlEntityFilterAst {
+ document_filter: Option<GraphqlDocumentExpr>,
+ project_filter: Option<GraphqlProjectExpr>,
+ chat_filter: Option<GraphqlChatExpr>,
+ email_filter: Option<GraphqlEmailFilterAst>,
+ channel_filter: Option<GraphqlChannelExpr>,
+ channel_thread_filter: Option<GraphqlChannelThreadExpr>,
+ call_filter: Option<GraphqlCallExpr>,
+ crm_company_filter: Option<GraphqlCrmCompanyExpr>,
+ foreign_entity_filter: Option<GraphqlForeignEntityExpr>,
+ properties_filter: Option<GraphqlPropertiesExpr>,
+}
+
+impl GraphqlEntityFilterAst {
fn into_ast(self) -> async_graphql::Result<EntityFilterAst> {
- EntityFilterAst::new_from_filters(self.into())
- .map(|filter| filter.unwrap_or_default())
- .map_err(|err| async_graphql::Error::new(format!("invalid filters: {err}")))
+ Ok(EntityFilterAst {
+ document_filter: optional_tree(self.document_filter)?,
+ project_filter: optional_tree(self.project_filter)?,
+ chat_filter: optional_tree(self.chat_filter)?,
+ email_filter: self
+ .email_filter
+ .map(GraphqlEmailFilterAst::into_ast)
+ .transpose()?
+ .unwrap_or_default(),
+ channel_filter: optional_tree(self.channel_filter)?,
+ channel_thread_filter: optional_tree(self.channel_thread_filter)?,
+ call_filter: optional_tree(self.call_filter)?,
+ crm_company_filter: optional_tree(self.crm_company_filter)?,
+ foreign_entity_filter: optional_tree(self.foreign_entity_filter)?,
+ properties_filter: optional_tree(self.properties_filter)?,
+ })
}
}
-impl From<GraphqlEntityFilters> for EntityFilters {
- fn from(value: GraphqlEntityFilters) -> Self {
- Self {
- project_filters: optional_input(value.project_filters),
- document_filters: optional_input(value.document_filters),
- chat_filters: optional_input(value.chat_filters),
- channel_filters: optional_input(value.channel_filters),
- channel_thread_filters: optional_input(value.channel_thread_filters),
- call_filters: optional_input(value.call_filters),
- email_filters: optional_input(value.email_filters),
- crm_company_filters: optional_input(value.crm_company_filters),
- foreign_entity_filters: optional_input(value.foreign_entity_filters),
- property_filters: value.property_filters.into_iter().map(Into::into).collect(),
+trait IntoFilterExpr<T>: Sized {
+ fn into_expr(self) -> async_graphql::Result<Expr<T>>;
+}
+
+fn optional_tree<I, T>(input: Option<I>) -> async_graphql::Result<Option<Arc<Expr<T>>>>
+where
+ I: IntoFilterExpr<T>,
+{
+ input.map(|expr| expr.into_expr().map(Arc::new)).transpose()
+}
+
+fn parse_uuid(value: String, field: &str) -> async_graphql::Result<Uuid> {
+ Uuid::parse_str(&value)
+ .map_err(|err| async_graphql::Error::new(format!("invalid {field} UUID `{value}`: {err}")))
+}
+
+fn parse_id(id: ID, field: &str) -> async_graphql::Result<Uuid> {
+ parse_uuid(id.to_string(), field)
+}
+
+fn parse_macro_user_id(
+ value: String,
+ field: &str,
+) -> async_graphql::Result<MacroUserIdStr<'static>> {
+ MacroUserIdStr::parse_from_str(&value)
+ .map(CowLike::into_owned)
+ .map_err(|err| async_graphql::Error::new(format!("invalid {field} `{value}`: {err}")))
+}
+
+macro_rules! filter_expr_input {
+ ($name:ident, $binary_name:ident, $literal:ty, $target:ty, $type_name:literal) => {
+ #[derive(async_graphql::InputObject)]
+ struct $binary_name {
+ left: Box<$name>,
+ right: Box<$name>,
}
+
+ #[derive(async_graphql::OneofObject)]
+ enum $name {
+ And($binary_name),
+ Or($binary_name),
+ Not(Box<$name>),
+ Literal($literal),
+ }
+
+ impl IntoFilterExpr<$target> for $name {
+ fn into_expr(self) -> async_graphql::Result<Expr<$target>> {
+ match self {
+ Self::And(exprs) => {
+ Ok(Expr::and(exprs.left.into_expr()?, exprs.right.into_expr()?))
+ }
+ Self::Or(exprs) => {
+ Ok(Expr::or(exprs.left.into_expr()?, exprs.right.into_expr()?))
+ }
+ Self::Not(expr) => expr.into_expr().map(Expr::is_not),
+ Self::Literal(literal) => literal.into_expr(),
+ }
+ }
+ }
+ };
+}
+
+filter_expr_input!(
+ GraphqlDocumentExpr,
+ GraphqlDocumentBinaryExpr,
+ GraphqlDocumentLiteral,
+ DocumentLiteral,
+ "DocumentFilterExpr"
+);
+filter_expr_input!(
+ GraphqlProjectExpr,
+ GraphqlProjectBinaryExpr,
+ GraphqlProjectLiteral,
+ ProjectLiteral,
+ "ProjectFilterExpr"
+);
+filter_expr_input!(
+ GraphqlChatExpr,
+ GraphqlChatBinaryExpr,
+ GraphqlChatLiteral,
+ ChatLiteral,
+ "ChatFilterExpr"
+);
+filter_expr_input!(
+ GraphqlEmailExpr,
+ GraphqlEmailBinaryExpr,
+ GraphqlEmailLiteral,
+ EmailLiteral,
+ "EmailFilterExpr"
+);
+filter_expr_input!(
+ GraphqlChannelExpr,
+ GraphqlChannelBinaryExpr,
+ GraphqlChannelLiteral,
+ ChannelLiteral,
+ "ChannelFilterExpr"
+);
+filter_expr_input!(
+ GraphqlChannelThreadExpr,
+ GraphqlChannelThreadBinaryExpr,
+ GraphqlChannelThreadLiteral,
+ ChannelThreadLiteral,
+ "ChannelThreadFilterExpr"
+);
+filter_expr_input!(
+ GraphqlCallExpr,
+ GraphqlCallBinaryExpr,
+ GraphqlCallLiteral,
+ CallLiteral,
+ "CallFilterExpr"
+);
+filter_expr_input!(
+ GraphqlCrmCompanyExpr,
+ GraphqlCrmCompanyBinaryExpr,
+ GraphqlCrmCompanyLiteral,
+ CrmCompanyLiteral,
+ "CrmCompanyFilterExpr"
+);
+filter_expr_input!(
+ GraphqlForeignEntityExpr,
+ GraphqlForeignEntityBinaryExpr,
+ GraphqlForeignEntityLiteral,
+ ForeignEntityLiteral,
+ "ForeignEntityFilterExpr"
+);
+filter_expr_input!(
+ GraphqlPropertiesExpr,
+ GraphqlPropertiesBinaryExpr,
+ GraphqlPropertiesLiteral,
+ PropertiesLiteral,
+ "PropertiesFilterExpr"
+);
+
+#[derive(async_graphql::InputObject)]
+struct GraphqlEmailFilterAst {
+ tree: Option<GraphqlEmailExpr>,
+ crm_scope: Option<GraphqlCrmScope>,
+}
+
+impl GraphqlEmailFilterAst {
+ fn into_ast(self) -> async_graphql::Result<EmailFilterAst> {
+ Ok(EmailFilterAst {
+ tree: optional_tree(self.tree)?,
+ crm_scope: self.crm_scope.map(GraphqlCrmScope::into_ast).transpose()?,
+ })
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlNotificationFilters {
- done: Option<bool>,
- seen: Option<bool>,
+#[derive(async_graphql::OneofObject)]
+enum GraphqlCrmScope {
+ Domains(Vec<String>),
+ Addresses(Vec<String>),
}
-impl From<GraphqlNotificationFilters> for NotificationFilters {
- fn from(value: GraphqlNotificationFilters) -> Self {
- Self {
- done: value.done,
- seen: value.seen,
+impl GraphqlCrmScope {
+ fn into_ast(self) -> async_graphql::Result<CrmScope> {
+ match self {
+ Self::Domains(domains) if domains.is_empty() => Err(async_graphql::Error::new(
+ "CrmScope.domains cannot be empty",
+ )),
+ Self::Domains(domains) => Ok(CrmScope::Domains(domains)),
+ Self::Addresses(addresses) if addresses.is_empty() => Err(async_graphql::Error::new(
+ "CrmScope.addresses cannot be empty",
+ )),
+ Self::Addresses(addresses) => Ok(CrmScope::Addresses(addresses)),
}
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlTaskFilters {
- include_cbm_atm_nc: Option<bool>,
+#[derive(async_graphql::OneofObject)]
+enum GraphqlDateLiteral {
+ Gt(String),
+ Lt(String),
+ Gte(String),
+ Lte(String),
}
-impl From<GraphqlTaskFilters> for TaskFilters {
- fn from(value: GraphqlTaskFilters) -> Self {
- Self {
- include_cbm_atm_nc: value.include_cbm_atm_nc,
- }
+impl GraphqlDateLiteral {
+ fn parse(value: String) -> async_graphql::Result<DateTime<Utc>> {
+ DateTime::parse_from_rfc3339(&value)
+ .map(|dt| dt.with_timezone(&Utc))
+ .map_err(|err| {
+ async_graphql::Error::new(format!("invalid RFC3339 date `{value}`: {err}"))
+ })
+ }
+
+ fn into_ast(self) -> async_graphql::Result<DateLiteral> {
+ Ok(match self {
+ Self::Gt(value) => DateLiteral::GreaterThan(Self::parse(value)?),
+ Self::Lt(value) => DateLiteral::LessThan(Self::parse(value)?),
+ Self::Gte(value) => DateLiteral::GreaterThanOrEqual(Self::parse(value)?),
+ Self::Lte(value) => DateLiteral::LessThanOrEqual(Self::parse(value)?),
+ })
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlDocumentFilters {
- #[graphql(default)]
- file_types: Vec<String>,
- #[graphql(default)]
- document_ids: Vec<ID>,
- #[graphql(default)]
- project_ids: Vec<ID>,
- #[graphql(default)]
- owners: Vec<String>,
- importance: Option<bool>,
- notification_filters: Option<GraphqlNotificationFilters>,
- task_filters: Option<GraphqlTaskFilters>,
- #[graphql(default)]
- sub_types: Vec<GraphqlDocumentSubTypeFilter>,
- is_email_attachment: Option<bool>,
-}
-
-impl From<GraphqlDocumentFilters> for DocumentFilters {
- fn from(value: GraphqlDocumentFilters) -> Self {
- Self {
- file_types: value.file_types,
- document_ids: ids_to_strings(value.document_ids),
- project_ids: ids_to_strings(value.project_ids),
- owners: value.owners,
- importance: value.importance,
- notification_filters: optional_input(value.notification_filters),
- task_filters: optional_input(value.task_filters),
- sub_types: value
- .sub_types
- .into_iter()
- .map(GraphqlDocumentSubTypeFilter::as_filter_value)
- .collect(),
- is_email_attachment: value.is_email_attachment,
- }
+#[derive(async_graphql::OneofObject)]
+enum GraphqlDocumentLiteral {
+ FileType(String),
+ Id(ID),
+ ProjectId(ID),
+ Owner(String),
+ Importance(bool),
+ NotificationDone(bool),
+ NotificationSeen(bool),
+ IncludeCbmAtmNc(bool),
+ SubType(GraphqlDocumentSubType),
+ FileAssoc(String),
+ IsEmailAttachment(bool),
+ CreatedAt(GraphqlDateLiteral),
+ UpdatedAt(GraphqlDateLiteral),
+}
+
+impl IntoFilterExpr<DocumentLiteral> for GraphqlDocumentLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<DocumentLiteral>> {
+ let literal = match self {
+ Self::FileAssoc(value) => {
+ let (_, file_types) = item_filters::ast::document::parse_to_file_types(&value)
+ .map_err(|err| async_graphql::Error::new(err.to_string()))?;
+ return file_types
+ .map(|file_type| Expr::val(DocumentLiteral::FileType(file_type)))
+ .reduce(Expr::or)
+ .ok_or_else(|| {
+ async_graphql::Error::new("fileAssoc expansion cannot be empty")
+ });
+ }
+ Self::FileType(value) => {
+ DocumentLiteral::FileType(FileType::from_str(&value).map_err(|err| {
+ async_graphql::Error::new(format!("invalid fileType `{value}`: {err}"))
+ })?)
+ }
+ Self::Id(id) => DocumentLiteral::Id(parse_id(id, "id")?),
+ Self::ProjectId(id) => DocumentLiteral::ProjectId(parse_id(id, "projectId")?),
+ Self::Owner(owner) => DocumentLiteral::Owner(parse_macro_user_id(owner, "owner")?),
+ Self::Importance(importance) => DocumentLiteral::Importance(importance),
+ Self::NotificationDone(done) => DocumentLiteral::NotificationDone(done),
+ Self::NotificationSeen(seen) => DocumentLiteral::NotificationSeen(seen),
+ Self::IncludeCbmAtmNc(include) => DocumentLiteral::IncludeCbmAtmNc(include),
+ Self::SubType(sub_type) => DocumentLiteral::SubType(sub_type.into()),
+ Self::IsEmailAttachment(value) => DocumentLiteral::IsEmailAttachment(value),
+ Self::CreatedAt(date) => DocumentLiteral::CreatedAt(date.into_ast()?),
+ Self::UpdatedAt(date) => DocumentLiteral::UpdatedAt(date.into_ast()?),
+ };
+ Ok(Expr::val(literal))
}
}
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
-enum GraphqlDocumentSubTypeFilter {
+enum GraphqlDocumentSubType {
Task,
Snippet,
}
-impl GraphqlDocumentSubTypeFilter {
- fn as_filter_value(self) -> String {
- match self {
- Self::Task => "task",
- Self::Snippet => "snippet",
+impl From<GraphqlDocumentSubType> for DocumentSubType {
+ fn from(value: GraphqlDocumentSubType) -> Self {
+ match value {
+ GraphqlDocumentSubType::Task => Self::Task,
+ GraphqlDocumentSubType::Snippet => Self::Snippet,
}
- .to_owned()
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlChatFilters {
- #[graphql(default)]
- role: Vec<GraphqlChatRoleFilter>,
- #[graphql(default)]
- chat_ids: Vec<ID>,
- #[graphql(default)]
- project_ids: Vec<ID>,
- #[graphql(default)]
- owners: Vec<String>,
- importance: Option<bool>,
- notification_filters: Option<GraphqlNotificationFilters>,
-}
-
-impl From<GraphqlChatFilters> for ChatFilters {
- fn from(value: GraphqlChatFilters) -> Self {
- Self {
- role: value
- .role
- .into_iter()
- .map(GraphqlChatRoleFilter::as_filter_value)
- .collect(),
- chat_ids: ids_to_strings(value.chat_ids),
- project_ids: ids_to_strings(value.project_ids),
- owners: value.owners,
- importance: value.importance,
- notification_filters: optional_input(value.notification_filters),
- }
+#[derive(async_graphql::OneofObject)]
+enum GraphqlProjectLiteral {
+ ProjectId(ID),
+ ProjectIdSelf(ID),
+ Owner(String),
+ Importance(bool),
+ NotificationDone(bool),
+ NotificationSeen(bool),
+ CreatedAt(GraphqlDateLiteral),
+ UpdatedAt(GraphqlDateLiteral),
+}
+
+impl IntoFilterExpr<ProjectLiteral> for GraphqlProjectLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<ProjectLiteral>> {
+ let literal = match self {
+ Self::ProjectId(id) => ProjectLiteral::ProjectId(parse_id(id, "projectId")?),
+ Self::ProjectIdSelf(id) => {
+ ProjectLiteral::ProjectIdSelf(parse_id(id, "projectIdSelf")?)
+ }
+ Self::Owner(owner) => ProjectLiteral::Owner(parse_macro_user_id(owner, "owner")?),
+ Self::Importance(importance) => ProjectLiteral::Importance(importance),
+ Self::NotificationDone(done) => ProjectLiteral::NotificationDone(done),
+ Self::NotificationSeen(seen) => ProjectLiteral::NotificationSeen(seen),
+ Self::CreatedAt(date) => ProjectLiteral::CreatedAt(date.into_ast()?),
+ Self::UpdatedAt(date) => ProjectLiteral::UpdatedAt(date.into_ast()?),
+ };
+ Ok(Expr::val(literal))
+ }
+}
+
+#[derive(async_graphql::OneofObject)]
+enum GraphqlChatLiteral {
+ ProjectId(ID),
+ Role(GraphqlChatRole),
+ ChatId(ID),
+ Owner(String),
+ Importance(bool),
+ NotificationDone(bool),
+ NotificationSeen(bool),
+ CreatedAt(GraphqlDateLiteral),
+ UpdatedAt(GraphqlDateLiteral),
+}
+
+impl IntoFilterExpr<ChatLiteral> for GraphqlChatLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<ChatLiteral>> {
+ let literal = match self {
+ Self::ProjectId(id) => ChatLiteral::ProjectId(parse_id(id, "projectId")?),
+ Self::Role(role) => ChatLiteral::Role(role.into()),
+ Self::ChatId(id) => ChatLiteral::ChatId(parse_id(id, "chatId")?),
+ Self::Owner(owner) => ChatLiteral::Owner(parse_macro_user_id(owner, "owner")?),
+ Self::Importance(importance) => ChatLiteral::Importance(importance),
+ Self::NotificationDone(done) => ChatLiteral::NotificationDone(done),
+ Self::NotificationSeen(seen) => ChatLiteral::NotificationSeen(seen),
+ Self::CreatedAt(date) => ChatLiteral::CreatedAt(date.into_ast()?),
+ Self::UpdatedAt(date) => ChatLiteral::UpdatedAt(date.into_ast()?),
+ };
+ Ok(Expr::val(literal))
}
}
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
-enum GraphqlChatRoleFilter {
+enum GraphqlChatRole {
User,
System,
Assistant,
}
-impl GraphqlChatRoleFilter {
- fn as_filter_value(self) -> String {
- match self {
- Self::User => "user",
- Self::System => "system",
- Self::Assistant => "assistant",
+impl From<GraphqlChatRole> for ChatRole {
+ fn from(value: GraphqlChatRole) -> Self {
+ match value {
+ GraphqlChatRole::User => Self::User,
+ GraphqlChatRole::System => Self::System,
+ GraphqlChatRole::Assistant => Self::Assistant,
}
- .to_owned()
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlChannelFilters {
- #[graphql(default)]
- thread_ids: Vec<ID>,
- #[graphql(default)]
- mentions: Vec<String>,
- org_id: Option<i64>,
- team_id: Option<ID>,
- #[graphql(default)]
- channel_ids: Vec<ID>,
- #[graphql(default)]
- sender_ids: Vec<String>,
- #[graphql(default)]
- channel_types: Vec<GraphqlChannelTypeFilter>,
- importance: Option<bool>,
- notification_filters: Option<GraphqlNotificationFilters>,
-}
-
-impl From<GraphqlChannelFilters> for ChannelFilters {
- fn from(value: GraphqlChannelFilters) -> Self {
- Self {
- thread_ids: ids_to_strings(value.thread_ids),
- mentions: value.mentions,
- org_id: value.org_id,
- team_id: value.team_id.map(|id| id.to_string()),
- channel_ids: ids_to_strings(value.channel_ids),
- sender_ids: value.sender_ids,
- channel_types: value
- .channel_types
- .into_iter()
- .map(GraphqlChannelTypeFilter::as_filter_value)
- .collect(),
- importance: value.importance,
- notification_filters: optional_input(value.notification_filters),
+#[derive(async_graphql::OneofObject)]
+enum GraphqlEmailLiteral {
+ Sender(GraphqlEmailValue),
+ Cc(GraphqlEmailValue),
+ Bcc(GraphqlEmailValue),
+ Recipient(GraphqlEmailValue),
+ ThreadId(ID),
+ Owner(ID),
+ ProjectId(String),
+ Importance(bool),
+ NotificationDone(bool),
+ NotificationSeen(bool),
+ Shared(GraphqlSharedEmailFilter),
+ CalendarOnly(bool),
+ CreatedAt(GraphqlDateLiteral),
+ UpdatedAt(GraphqlDateLiteral),
+}
+
+impl IntoFilterExpr<EmailLiteral> for GraphqlEmailLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<EmailLiteral>> {
+ let literal = match self {
+ Self::Sender(value) => EmailLiteral::Sender(value.into_ast()?),
+ Self::Cc(value) => EmailLiteral::Cc(value.into_ast()?),
+ Self::Bcc(value) => EmailLiteral::Bcc(value.into_ast()?),
+ Self::Recipient(value) => EmailLiteral::Recipient(value.into_ast()?),
+ Self::ThreadId(id) => EmailLiteral::ThreadId(parse_id(id, "threadId")?),
+ Self::Owner(id) => EmailLiteral::Owner(parse_id(id, "owner")?),
+ Self::ProjectId(id) => EmailLiteral::ProjectId(id),
+ Self::Importance(importance) => EmailLiteral::Importance(importance),
+ Self::NotificationDone(done) => EmailLiteral::NotificationDone(done),
+ Self::NotificationSeen(seen) => EmailLiteral::NotificationSeen(seen),
+ Self::Shared(shared) => EmailLiteral::Shared(shared.into()),
+ Self::CalendarOnly(calendar_only) => EmailLiteral::CalendarOnly(calendar_only),
+ Self::CreatedAt(date) => EmailLiteral::CreatedAt(date.into_ast()?),
+ Self::UpdatedAt(date) => EmailLiteral::UpdatedAt(date.into_ast()?),
+ };
+ Ok(Expr::val(literal))
+ }
+}
+
+#[derive(async_graphql::OneofObject)]
+enum GraphqlEmailValue {
+ Partial(String),
+ Complete(String),
+ Domain(String),
+}
+
+impl GraphqlEmailValue {
+ fn into_ast(self) -> async_graphql::Result<Email> {
+ Ok(match self {
+ Self::Partial(value) => Email::Partial(value),
+ Self::Complete(value) => Email::Complete(
+ EmailStr::parse_from_str(&value)
+ .map(CowLike::into_owned)
+ .map_err(|err| {
+ async_graphql::Error::new(format!(
+ "invalid complete email `{value}`: {err}"
+ ))
+ })?,
+ ),
+ Self::Domain(value) => Email::Domain(value),
+ })
+ }
+}
+
+#[derive(Enum, Copy, Clone, Eq, PartialEq)]
+enum GraphqlSharedEmailFilter {
+ Exclude,
+ Include,
+ Only,
+}
+
+impl From<GraphqlSharedEmailFilter> for SharedEmailFilter {
+ fn from(value: GraphqlSharedEmailFilter) -> Self {
+ match value {
+ GraphqlSharedEmailFilter::Exclude => Self::Exclude,
+ GraphqlSharedEmailFilter::Include => Self::Include,
+ GraphqlSharedEmailFilter::Only => Self::Only,
}
}
}
+#[derive(async_graphql::OneofObject)]
+enum GraphqlChannelLiteral {
+ ThreadId(ID),
+ Mention(String),
+ OrganizationId(i64),
+ TeamId(ID),
+ ChannelId(ID),
+ Sender(String),
+ ChannelType(GraphqlChannelTypeFilter),
+ Importance(bool),
+ NotificationDone(bool),
+ NotificationSeen(bool),
+}
+
+impl IntoFilterExpr<ChannelLiteral> for GraphqlChannelLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<ChannelLiteral>> {
+ let literal = match self {
+ Self::ThreadId(id) => ChannelLiteral::ThreadId(parse_id(id, "threadId")?),
+ Self::Mention(mention) => {
+ ChannelLiteral::Mention(parse_macro_user_id(mention, "mention")?)
+ }
+ Self::OrganizationId(id) => ChannelLiteral::OrganizationId(id),
+ Self::TeamId(id) => ChannelLiteral::TeamId(parse_id(id, "teamId")?),
+ Self::ChannelId(id) => ChannelLiteral::ChannelId(parse_id(id, "channelId")?),
+ Self::Sender(sender) => ChannelLiteral::Sender(parse_macro_user_id(sender, "sender")?),
+ Self::ChannelType(channel_type) => ChannelLiteral::ChannelType(channel_type.into()),
+ Self::Importance(importance) => ChannelLiteral::Importance(importance),
+ Self::NotificationDone(done) => ChannelLiteral::NotificationDone(done),
+ Self::NotificationSeen(seen) => ChannelLiteral::NotificationSeen(seen),
+ };
+ Ok(Expr::val(literal))
+ }
+}
+
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
enum GraphqlChannelTypeFilter {
Public,
@@ -284,59 +616,62 @@ enum GraphqlChannelTypeFilter {
Team,
}
-impl GraphqlChannelTypeFilter {
- fn as_filter_value(self) -> String {
- match self {
- Self::Public => "public",
- Self::Private => "private",
- Self::DirectMessage => "direct_message",
- Self::Team => "team",
+impl From<GraphqlChannelTypeFilter> for ChannelTypeFilter {
+ fn from(value: GraphqlChannelTypeFilter) -> Self {
+ match value {
+ GraphqlChannelTypeFilter::Public => Self::Public,
+ GraphqlChannelTypeFilter::Private => Self::Private,
+ GraphqlChannelTypeFilter::DirectMessage => Self::DirectMessage,
+ GraphqlChannelTypeFilter::Team => Self::Team,
}
- .to_owned()
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlChannelThreadFilters {
- #[graphql(default)]
- thread_ids: Vec<ID>,
- #[graphql(default)]
- channel_ids: Vec<ID>,
- #[graphql(default)]
- root_sender_ids: Vec<String>,
-}
-
-impl From<GraphqlChannelThreadFilters> for ChannelThreadFilters {
- fn from(value: GraphqlChannelThreadFilters) -> Self {
- Self {
- thread_ids: ids_to_strings(value.thread_ids),
- channel_ids: ids_to_strings(value.channel_ids),
- root_sender_ids: value.root_sender_ids,
- }
+#[derive(async_graphql::OneofObject)]
+enum GraphqlChannelThreadLiteral {
+ ThreadId(ID),
+ ChannelId(ID),
+ RootSender(String),
+ NotificationDone(bool),
+ NotificationSeen(bool),
+}
+
+impl IntoFilterExpr<ChannelThreadLiteral> for GraphqlChannelThreadLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<ChannelThreadLiteral>> {
+ let literal = match self {
+ Self::ThreadId(id) => ChannelThreadLiteral::ThreadId(parse_id(id, "threadId")?),
+ Self::ChannelId(id) => ChannelThreadLiteral::ChannelId(parse_id(id, "channelId")?),
+ Self::RootSender(sender) => {
+ ChannelThreadLiteral::RootSender(parse_macro_user_id(sender, "rootSender")?)
+ }
+ Self::NotificationDone(done) => ChannelThreadLiteral::NotificationDone(done),
+ Self::NotificationSeen(seen) => ChannelThreadLiteral::NotificationSeen(seen),
+ };
+ Ok(Expr::val(literal))
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlCallFilters {
- #[graphql(default)]
- call_ids: Vec<ID>,
- #[graphql(default)]
- channel_ids: Vec<ID>,
- #[graphql(default)]
- speaker_ids: Vec<String>,
- status: Option<GraphqlCallStatus>,
- attended: Option<bool>,
-}
-
-impl From<GraphqlCallFilters> for CallFilters {
- fn from(value: GraphqlCallFilters) -> Self {
- Self {
- call_ids: ids_to_strings(value.call_ids),
- channel_ids: ids_to_strings(value.channel_ids),
- speaker_ids: value.speaker_ids,
- status: value.status.map(Into::into),
- attended: value.attended,
- }
+#[derive(async_graphql::OneofObject)]
+enum GraphqlCallLiteral {
+ CallId(ID),
+ ChannelId(ID),
+ Speaker(String),
+ Status(GraphqlCallStatus),
+ Attended(bool),
+}
+
+impl IntoFilterExpr<CallLiteral> for GraphqlCallLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<CallLiteral>> {
+ let literal = match self {
+ Self::CallId(id) => CallLiteral::CallId(parse_id(id, "callId")?),
+ Self::ChannelId(id) => CallLiteral::ChannelId(parse_id(id, "channelId")?),
+ Self::Speaker(speaker) => {
+ CallLiteral::Speaker(parse_macro_user_id(speaker, "speaker")?)
+ }
+ Self::Status(status) => CallLiteral::Status(status.into()),
+ Self::Attended(attended) => CallLiteral::Attended(attended),
+ };
+ Ok(Expr::val(literal))
}
}
@@ -357,158 +692,86 @@ impl From<GraphqlCallStatus> for CallStatus {
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlEmailFilters {
- #[graphql(default)]
- senders: Vec<String>,
- #[graphql(default)]
- cc: Vec<String>,
- #[graphql(default)]
- bcc: Vec<String>,
- #[graphql(default)]
- recipients: Vec<String>,
- #[graphql(default)]
- email_thread_ids: Vec<ID>,
- #[graphql(default)]
- link_ids: Vec<ID>,
- #[graphql(default)]
- project_ids: Vec<String>,
- importance: Option<bool>,
- notification_filters: Option<GraphqlNotificationFilters>,
- #[graphql(default)]
- include_labels: Vec<String>,
- #[graphql(default)]
- exclude_labels: Vec<String>,
- shared: Option<GraphqlSharedEmailFilter>,
- #[graphql(default)]
- crm_domains: Vec<String>,
- #[graphql(default)]
- crm_addresses: Vec<String>,
- calendar_only: Option<bool>,
-}
-
-impl From<GraphqlEmailFilters> for EmailFilters {
- fn from(value: GraphqlEmailFilters) -> Self {
- Self {
- senders: value.senders,
- cc: value.cc,
- bcc: value.bcc,
- recipients: value.recipients,
- email_thread_ids: ids_to_strings(value.email_thread_ids),
- link_ids: ids_to_strings(value.link_ids),
- project_ids: value.project_ids,
- importance: value.importance,
- notification_filters: optional_input(value.notification_filters),
- include_labels: value.include_labels,
- exclude_labels: value.exclude_labels,
- shared: value.shared.map(Into::into).unwrap_or_default(),
- crm_domains: value.crm_domains,
- crm_addresses: value.crm_addresses,
- calendar_only: value.calendar_only,
- }
- }
+#[derive(async_graphql::OneofObject)]
+enum GraphqlCrmCompanyLiteral {
+ Id(ID),
+ Hidden(bool),
}
-#[derive(Enum, Copy, Clone, Eq, PartialEq)]
-enum GraphqlSharedEmailFilter {
- Exclude,
- Include,
- Only,
+impl IntoFilterExpr<CrmCompanyLiteral> for GraphqlCrmCompanyLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<CrmCompanyLiteral>> {
+ let literal = match self {
+ Self::Id(id) => CrmCompanyLiteral::Id(parse_id(id, "id")?),
+ Self::Hidden(hidden) => CrmCompanyLiteral::Hidden(hidden),
+ };
+ Ok(Expr::val(literal))
+ }
}
-impl From<GraphqlSharedEmailFilter> for SharedEmailFilter {
- fn from(value: GraphqlSharedEmailFilter) -> Self {
- match value {
- GraphqlSharedEmailFilter::Exclude => Self::Exclude,
- GraphqlSharedEmailFilter::Include => Self::Include,
- GraphqlSharedEmailFilter::Only => Self::Only,
- }
+#[derive(async_graphql::OneofObject)]
+enum GraphqlForeignEntityLiteral {
+ Id(ID),
+ ForeignEntityId(String),
+ ForeignEntitySource(String),
+ IncludesMe(bool),
+ NotificationDone(bool),
+ NotificationSeen(bool),
+}
+
+impl IntoFilterExpr<ForeignEntityLiteral> for GraphqlForeignEntityLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<ForeignEntityLiteral>> {
+ let literal = match self {
+ Self::Id(id) => ForeignEntityLiteral::Id(parse_id(id, "id")?),
+ Self::ForeignEntityId(id) => ForeignEntityLiteral::ForeignEntityId(id),
+ Self::ForeignEntitySource(source) => ForeignEntityLiteral::ForeignEntitySource(source),
+ Self::IncludesMe(true) => ForeignEntityLiteral::IncludesMe,
+ Self::IncludesMe(false) => {
+ return Err(async_graphql::Error::new(
+ "ForeignEntityLiteral.includesMe must be true",
+ ));
+ }
+ Self::NotificationDone(done) => ForeignEntityLiteral::NotificationDone(done),
+ Self::NotificationSeen(seen) => ForeignEntityLiteral::NotificationSeen(seen),
+ };
+ Ok(Expr::val(literal))
}
}
#[derive(async_graphql::InputObject)]
-struct GraphqlCrmCompanyFilters {
- #[graphql(default)]
- company_ids: Vec<ID>,
- hidden: Option<bool>,
+struct GraphqlPropertiesLiteral {
+ property_definition_id: ID,
+ entity_type: Option<GraphqlPropertyEntityType>,
+ value: GraphqlPropertyMatchValue,
}
-impl From<GraphqlCrmCompanyFilters> for CrmCompanyFilters {
- fn from(value: GraphqlCrmCompanyFilters) -> Self {
- Self {
- company_ids: ids_to_strings(value.company_ids),
- hidden: value.hidden,
- }
+impl IntoFilterExpr<PropertiesLiteral> for GraphqlPropertiesLiteral {
+ fn into_expr(self) -> async_graphql::Result<Expr<PropertiesLiteral>> {
+ Ok(Expr::val(PropertiesLiteral {
+ property_definition_id: parse_id(self.property_definition_id, "propertyDefinitionId")?,
+ entity_type: self.entity_type.map(Into::into),
+ value: self.value.into_ast()?,
+ }))
}
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlForeignEntityFilters {
- #[graphql(default)]
- ids: Vec<ID>,
- #[graphql(default)]
- foreign_entity_ids: Vec<String>,
- #[graphql(default)]
- foreign_entity_sources: Vec<String>,
- includes_me: Option<bool>,
- notification_filters: Option<GraphqlNotificationFilters>,
-}
-
-impl From<GraphqlForeignEntityFilters> for ForeignEntityFilters {
- fn from(value: GraphqlForeignEntityFilters) -> Self {
- Self {
- ids: ids_to_strings(value.ids),
- foreign_entity_ids: value.foreign_entity_ids,
- foreign_entity_sources: value.foreign_entity_sources,
- includes_me: value.includes_me.unwrap_or_default(),
- notification_filters: optional_input(value.notification_filters),
- }
- }
+#[derive(async_graphql::OneofObject)]
+enum GraphqlPropertyMatchValue {
+ SelectOption(ID),
+ EntityRef(String),
}
-#[derive(async_graphql::InputObject)]
-struct GraphqlProjectFilters {
- #[graphql(default)]
- project_ids: Vec<ID>,
- include_root: Option<bool>,
- #[graphql(default)]
- owners: Vec<String>,
- importance: Option<bool>,
- notification_filters: Option<GraphqlNotificationFilters>,
-}
-
-impl From<GraphqlProjectFilters> for ProjectFilters {
- fn from(value: GraphqlProjectFilters) -> Self {
- Self {
- project_ids: ids_to_strings(value.project_ids),
- include_root: value.include_root.unwrap_or_default(),
- owners: value.owners,
- importance: value.importance,
- notification_filters: optional_input(value.notification_filters),
- }
- }
-}
-
-#[derive(async_graphql::InputObject)]
-struct GraphqlPropertyFilter {
- property_definition_id: ID,
- entity_type: Option<GraphqlPropertyEntityType>,
- #[graphql(default)]
- option_ids: Vec<ID>,
- #[graphql(default)]
- entity_ids: Vec<String>,
-}
-
-impl From<GraphqlPropertyFilter> for PropertyFilter {
- fn from(value: GraphqlPropertyFilter) -> Self {
- Self {
- property_definition_id: value.property_definition_id.to_string(),
- entity_type: value
- .entity_type
- .map(GraphqlPropertyEntityType::as_filter_value),
- option_ids: ids_to_strings(value.option_ids),
- entity_ids: value.entity_ids,
- }
+impl GraphqlPropertyMatchValue {
+ fn into_ast(self) -> async_graphql::Result<PropertyMatchValue> {
+ Ok(match self {
+ Self::SelectOption(id) => {
+ PropertyMatchValue::SelectOption(parse_id(id, "selectOption")?)
+ }
+ Self::EntityRef(value) => {
+ PropertyMatchValue::EntityRef(EntityRefId::new(value).map_err(|err| {
+ async_graphql::Error::new(format!("invalid entityRef: {err}"))
+ })?)
+ }
+ })
}
}
@@ -524,34 +787,21 @@ enum GraphqlPropertyEntityType {
User,
}
-impl GraphqlPropertyEntityType {
- fn as_filter_value(self) -> String {
- match self {
- Self::Channel => "CHANNEL",
- Self::Chat => "CHAT",
- Self::Company => "COMPANY",
- Self::Document => "DOCUMENT",
- Self::Project => "PROJECT",
- Self::Task => "TASK",
- Self::Thread => "THREAD",
- Self::User => "USER",
+impl From<GraphqlPropertyEntityType> for PropertyEntityType {
+ fn from(value: GraphqlPropertyEntityType) -> Self {
+ match value {
+ GraphqlPropertyEntityType::Channel => Self::Channel,
+ GraphqlPropertyEntityType::Chat => Self::Chat,
+ GraphqlPropertyEntityType::Company => Self::Company,
+ GraphqlPropertyEntityType::Document => Self::Document,
+ GraphqlPropertyEntityType::Project => Self::Project,
+ GraphqlPropertyEntityType::Task => Self::Task,
+ GraphqlPropertyEntityType::Thread => Self::Thread,
+ GraphqlPropertyEntityType::User => Self::User,
}
- .to_owned()
}
}
-fn optional_input<T, U>(value: Option<T>) -> U
-where
- T: Into<U>,
- U: Default,
-{
- value.map(Into::into).unwrap_or_default()
-}
-
-fn ids_to_strings(ids: Vec<ID>) -> Vec<String> {
- ids.into_iter().map(|id| id.to_string()).collect()
-}
-
/// GraphQL representation of supported simple Soup sorts.
#[derive(Enum, Copy, Clone, Eq, PartialEq)]
pub enum GraphqlSimpleSortMethod {
@@ -575,3 +825,6 @@ impl From<GraphqlSimpleSortMethod> for SimpleSortMethod {
}
}
}
+
+#[cfg(test)]
+mod tests;
diff --git a/rust/cloud-storage/graphql_soup/src/inputs/tests.rs b/rust/cloud-storage/graphql_soup/src/inputs/tests.rs
new file mode 100644
index 0000000000..c68b93d7f1
--- /dev/null
+++ b/rust/cloud-storage/graphql_soup/src/inputs/tests.rs
@@ -0,0 +1,78 @@
+use async_graphql::ID;
+use filter_ast::Expr;
+use item_filters::ast::{chat::ChatLiteral, document::DocumentLiteral};
+use macro_user_id::{cowlike::CowLike, user_id::MacroUserIdStr};
+
+use super::*;
+
+fn test_request_context() -> GraphqlSoupRequestContext {
+ GraphqlSoupRequestContext {
+ macro_user_id: MacroUserIdStr::parse_from_str("macro|[email protected]")
+ .unwrap()
+ .into_owned(),
+ link_ids: vec![],
+ team_receipt: None,
+ }
+}
+
+#[test]
+fn maps_email_view_to_soup_request() {
+ let request = SoupInput {
+ limit: None,
+ expand: None,
+ sort_method: None,
+ cursor: None,
+ email_view: Some(GraphqlEmailView::Sent),
+ filters: None,
+ }
+ .into_request(&test_request_context())
+ .unwrap();
+
+ assert_eq!(request.email_preview_view.to_string(), "sent");
+}
+
+#[test]
+fn defaults_email_view_to_inbox() {
+ let request = SoupInput {
+ limit: None,
+ expand: None,
+ sort_method: None,
+ cursor: None,
+ email_view: None,
+ filters: None,
+ }
+ .into_request(&test_request_context())
+ .unwrap();
+
+ assert_eq!(request.email_preview_view.to_string(), "inbox");
+}
+
+#[test]
+fn expands_document_file_assoc() {
+ let expr = GraphqlDocumentLiteral::FileAssoc("assoc:pdf".to_owned())
+ .into_expr()
+ .unwrap();
+
+ assert!(matches!(expr, Expr::Literal(DocumentLiteral::FileType(_))));
+}
+
+#[test]
+fn builds_binary_filter_expressions() {
+ let expr = GraphqlChatExpr::And(GraphqlChatBinaryExpr {
+ left: Box::new(GraphqlChatExpr::Literal(GraphqlChatLiteral::ChatId(ID(
+ "00000000-0000-0000-0000-000000000001".to_owned(),
+ )))),
+ right: Box::new(GraphqlChatExpr::Literal(GraphqlChatLiteral::ChatId(ID(
+ "00000000-0000-0000-0000-000000000002".to_owned(),
+ )))),
+ })
+ .into_expr()
+ .unwrap();
+
+ assert!(matches!(
+ expr,
+ Expr::And(left, right)
+ if matches!(*left, Expr::Literal(ChatLiteral::ChatId(_)))
+ && matches!(*right, Expr::Literal(ChatLiteral::ChatId(_)))
+ ));
+}
diff --git a/rust/cloud-storage/graphql_soup/src/objects.rs b/rust/cloud-storage/graphql_soup/src/objects.rs
index c240fb3c90..a78c356c11 100644
--- a/rust/cloud-storage/graphql_soup/src/objects.rs
+++ b/rust/cloud-storage/graphql_soup/src/objects.rs
@@ -4,12 +4,15 @@ use models_pagination::PaginatedOpaqueCursor;
use models_properties::service::property_value::PropertyValue;
use models_soup::{
SoupProperty,
- call_record::SoupCallRecord,
+ call_record::{SoupCallRecord, SoupCallRecordParticipant},
chat::SoupChat,
- comms::{ChannelType, SoupChannel, SoupChannelThread},
+ comms::{ChannelMessage, ChannelParticipant, ChannelType, SoupChannel, SoupChannelThread},
crm_company::SoupCrmCompany,
document::{SoupDocument, SoupDocumentSubType},
- email_thread::SoupEnrichedEmailThreadPreview,
+ email_thread::{
+ SoupAttachment, SoupContact, SoupEnrichedEmailThreadPreview, SoupLabel,
+ SoupLabelListVisibility, SoupLabelType, SoupMessageListVisibility,
+ },
foreign_entity::SoupForeignEntity,
item::SoupItem,
project::SoupProject,
@@ -18,9 +21,7 @@ use notification::domain::models::UserNotificationRow;
use serde_json::Value;
use soup::domain::models::FrecencySoupItem;
-use crate::loaders::{
- EntityNotificationsKey, EntityNotificationsLoader, EntityPropertiesKey, EntityPropertiesLoader,
-};
+use crate::loaders::{EntityNotificationsKey, EntityNotificationsLoader};
/// Page returned by `Query.soup`.
#[derive(SimpleObject)]
@@ -65,8 +66,8 @@ pub enum GraphqlSoupEntityType {
EmailThread,
/// Channel entity.
Channel,
- /// Channel message entity.
- ChannelMessage,
+ /// Channel thread entity.
+ ChannelThread,
/// Call entity.
Call,
/// CRM company entity.
@@ -85,7 +86,7 @@ impl From<EntityType> for GraphqlSoupEntityType {
EntityType::Project => Self::Project,
EntityType::EmailThread => Self::EmailThread,
EntityType::Channel => Self::Channel,
- EntityType::ChannelMessage => Self::ChannelMessage,
+ EntityType::ChannelMessage => Self::ChannelThread,
EntityType::Call => Self::Call,
EntityType::CrmCompany => Self::CrmCompany,
EntityType::ForeignEntity => Self::ForeignEntity,
@@ -220,22 +221,13 @@ impl GraphqlSoupDocument {
.map(GraphqlSoupDocumentSubType::from)
}
- async fn properties(
- &self,
- ctx: &Context<'_>,
- ) -> async_graphql::Result<Vec<GraphqlSoupProperty>> {
- let loader = ctx.data::<DataLoader<EntityPropertiesLoader>>()?;
- let key = EntityPropertiesKey {
- entity_id: self.0.id.to_string(),
- entity_type: self.0.entity_type().to_string(),
- };
-
- let properties = loader
- .load_one(key)
- .await
- .map_err(|err| async_graphql::Error::new(err.to_string()))?
- .unwrap_or_default();
- Ok(properties.into_iter().map(GraphqlSoupProperty).collect())
+ async fn properties(&self) -> Vec<GraphqlSoupProperty> {
+ self.0
+ .properties
+ .iter()
+ .cloned()
+ .map(GraphqlSoupProperty)
+ .collect()
}
async fn notifications(
@@ -546,6 +538,19 @@ impl GraphqlSoupChat {
self.0.viewed_at.map(|ts| ts.to_rfc3339())
}
+ async fn deleted_at(&self) -> Option<String> {
+ self.0.deleted_at.map(|ts| ts.to_rfc3339())
+ }
+
+ async fn properties(&self) -> Vec<GraphqlSoupProperty> {
+ self.0
+ .properties
+ .iter()
+ .cloned()
+ .map(GraphqlSoupProperty)
+ .collect()
+ }
+
async fn notifications(
&self,
ctx: &Context<'_>,
@@ -594,6 +599,19 @@ impl GraphqlSoupProject {
self.0.viewed_at.map(|ts| ts.to_rfc3339())
}
+ async fn deleted_at(&self) -> Option<String> {
+ self.0.deleted_at.map(|ts| ts.to_rfc3339())
+ }
+
+ async fn properties(&self) -> Vec<GraphqlSoupProperty> {
+ self.0
+ .properties
+ .iter()
+ .cloned()
+ .map(GraphqlSoupProperty)
+ .collect()
+ }
+
async fn notifications(
&self,
ctx: &Context<'_>,
@@ -609,6 +627,184 @@ impl GraphqlSoupProject {
}
}
+/// GraphQL email participant/contact.
+pub struct GraphqlSoupEmailParticipant {
+ id: ID,
+ link_id: ID,
+ name: Option<String>,
+ email: Option<String>,
+ sfs_photo_url: Option<String>,
+}
+
+impl From<&SoupContact> for GraphqlSoupEmailParticipant {
+ fn from(value: &SoupContact) -> Self {
+ Self {
+ id: ID(value.id.to_string()),
+ link_id: ID(value.link_id.to_string()),
+ name: value.name.clone(),
+ email: value.email_address.clone(),
+ sfs_photo_url: value.sfs_photo_url.clone(),
+ }
+ }
+}
+
+#[Object]
+impl GraphqlSoupEmailParticipant {
+ async fn id(&self) -> &ID {
+ &self.id
+ }
+
+ async fn link_id(&self) -> &ID {
+ &self.link_id
+ }
+
+ async fn name(&self) -> Option<&str> {
+ self.name.as_deref()
+ }
+
+ async fn email(&self) -> Option<&str> {
+ self.email.as_deref()
+ }
+
+ async fn sfs_photo_url(&self) -> Option<&str> {
+ self.sfs_photo_url.as_deref()
+ }
+}
+
+/// GraphQL email label.
+pub struct GraphqlSoupEmailLabel {
+ id: ID,
+ link_id: ID,
+ provider_label_id: String,
+ name: String,
+ created_at: String,
+ message_list_visibility: &'static str,
+ label_list_visibility: &'static str,
+ type_: &'static str,
+}
+
+impl From<&SoupLabel> for GraphqlSoupEmailLabel {
+ fn from(value: &SoupLabel) -> Self {
+ Self {
+ id: ID(value.id.to_string()),
+ link_id: ID(value.link_id.to_string()),
+ provider_label_id: value.provider_label_id.clone(),
+ name: value.name.clone(),
+ created_at: value.created_at.to_rfc3339(),
+ message_list_visibility: match value.message_list_visibility {
+ SoupMessageListVisibility::Show => "show",
+ SoupMessageListVisibility::Hide => "hide",
+ },
+ label_list_visibility: match value.label_list_visibility {
+ SoupLabelListVisibility::LabelShow => "label_show",
+ SoupLabelListVisibility::LabelShowIfUnread => "label_show_if_unread",
+ SoupLabelListVisibility::LabelHide => "label_hide",
+ },
+ type_: match value.type_ {
+ SoupLabelType::System => "system",
+ SoupLabelType::User => "user",
+ },
+ }
+ }
+}
+
+#[Object]
+impl GraphqlSoupEmailLabel {
+ async fn id(&self) -> &ID {
+ &self.id
+ }
+
+ async fn link_id(&self) -> &ID {
+ &self.link_id
+ }
+
+ async fn provider_label_id(&self) -> &str {
+ &self.provider_label_id
+ }
+
+ async fn name(&self) -> &str {
+ &self.name
+ }
+
+ async fn created_at(&self) -> &str {
+ &self.created_at
+ }
+
+ async fn message_list_visibility(&self) -> &'static str {
+ self.message_list_visibility
+ }
+
+ async fn label_list_visibility(&self) -> &'static str {
+ self.label_list_visibility
+ }
+
+ async fn type_(&self) -> &'static str {
+ self.type_
+ }
+}
+
+/// GraphQL email attachment.
+pub struct GraphqlSoupEmailAttachment {
+ id: ID,
+ message_id: ID,
+ provider_attachment_id: Option<String>,
+ filename: Option<String>,
+ mime_type: Option<String>,
+ size_bytes: Option<i64>,
+ content_id: Option<String>,
+ created_at: String,
+}
+
+impl From<&SoupAttachment> for GraphqlSoupEmailAttachment {
+ fn from(value: &SoupAttachment) -> Self {
+ Self {
+ id: ID(value.id.to_string()),
+ message_id: ID(value.message_id.to_string()),
+ provider_attachment_id: value.provider_attachment_id.clone(),
+ filename: value.filename.clone(),
+ mime_type: value.mime_type.clone(),
+ size_bytes: value.size_bytes,
+ content_id: value.content_id.clone(),
+ created_at: value.created_at.to_rfc3339(),
+ }
+ }
+}
+
+#[Object]
+impl GraphqlSoupEmailAttachment {
+ async fn id(&self) -> &ID {
+ &self.id
+ }
+
+ async fn message_id(&self) -> &ID {
+ &self.message_id
+ }
+
+ async fn provider_attachment_id(&self) -> Option<&str> {
+ self.provider_attachment_id.as_deref()
+ }
+
+ async fn filename(&self) -> Option<&str> {
+ self.filename.as_deref()
+ }
+
+ async fn mime_type(&self) -> Option<&str> {
+ self.mime_type.as_deref()
+ }
+
+ async fn size_bytes(&self) -> Option<i64> {
+ self.size_bytes
+ }
+
+ async fn content_id(&self) -> Option<&str> {
+ self.content_id.as_deref()
+ }
+
+ async fn created_at(&self) -> &str {
+ &self.created_at
+ }
+}
+
/// GraphQL email thread entity.
pub struct GraphqlSoupEmailThread(SoupEnrichedEmailThreadPreview);
@@ -618,10 +814,27 @@ impl GraphqlSoupEmailThread {
ID(self.0.thread.id.to_string())
}
+ async fn provider_id(&self) -> Option<&str> {
+ self.0.thread.provider_id.as_deref()
+ }
+
async fn owner_id(&self) -> String {
self.0.thread.owner_id.as_ref().to_owned()
}
+ async fn inbox_visible(&self) -> bool {
+ self.0.thread.inbox_visible
+ }
+
+ async fn link_id(&self) -> Option<ID> {
+ self.0
+ .participants
+ .first()
+ .map(|participant| participant.link_id)
+ .or_else(|| self.0.labels.first().map(|label| label.link_id))
+ .map(|id| ID(id.to_string()))
+ }
+
async fn name(&self) -> Option<&str> {
self.0.thread.name.as_deref()
}
@@ -638,6 +851,10 @@ impl GraphqlSoupEmailThread {
self.0.thread.sender_name.as_deref()
}
+ async fn sender_photo_url(&self) -> Option<&str> {
+ self.0.thread.sender_photo_url.as_deref()
+ }
+
async fn is_read(&self) -> bool {
self.0.thread.is_read
}
@@ -678,6 +895,39 @@ impl GraphqlSoupEmailThread {
self.0.participants.len()
}
+ async fn participants(&self) -> Vec<GraphqlSoupEmailParticipant> {
+ self.0
+ .participants
+ .iter()
+ .map(GraphqlSoupEmailParticipant::from)
+ .collect()
+ }
+
+ async fn attachments(&self) -> Vec<GraphqlSoupEmailAttachment> {
+ self.0
+ .attachments
+ .iter()
+ .map(GraphqlSoupEmailAttachment::from)
+ .collect()
+ }
+
+ async fn labels(&self) -> Vec<GraphqlSoupEmailLabel> {
+ self.0
+ .labels
+ .iter()
+ .map(GraphqlSoupEmailLabel::from)
+ .collect()
+ }
+
+ async fn properties(&self) -> Vec<GraphqlSoupProperty> {
+ self.0
+ .properties
+ .iter()
+ .cloned()
+ .map(GraphqlSoupProperty)
+ .collect()
+ }
+
async fn notifications(
&self,
ctx: &Context<'_>,
@@ -693,6 +943,74 @@ impl GraphqlSoupEmailThread {
}
}
+/// GraphQL channel participant.
+pub struct GraphqlSoupChannelParticipant(ChannelParticipant);
+
+#[Object]
+impl GraphqlSoupChannelParticipant {
+ async fn channel_id(&self) -> ID {
+ ID(self.0.channel_id.0.to_string())
+ }
+
+ async fn user_id(&self) -> String {
+ self.0.user_id.as_ref().to_owned()
+ }
+
+ async fn role(&self) -> &'static str {
+ match self.0.role {
+ models_soup::comms::ParticipantRole::Owner => "owner",
+ models_soup::comms::ParticipantRole::Admin => "admin",
+ models_soup::comms::ParticipantRole::Member => "member",
+ }
+ }
+
+ async fn joined_at(&self) -> String {
+ self.0.joined_at.to_rfc3339()
+ }
+
+ async fn left_at(&self) -> Option<String> {
+ self.0.left_at.map(|ts| ts.to_rfc3339())
+ }
+}
+
+/// GraphQL channel message summary.
+pub struct GraphqlSoupChannelMessage(ChannelMessage);
+
+#[Object]
+impl GraphqlSoupChannelMessage {
+ async fn message_id(&self) -> ID {
+ ID(self.0.message_id.to_string())
+ }
+
+ async fn thread_id(&self) -> Option<ID> {
+ self.0.thread_id.map(|id| ID(id.to_string()))
+ }
+
+ async fn sender_id(&self) -> &str {
+ &self.0.sender_id
+ }
+
+ async fn content(&self) -> &str {
+ &self.0.content
+ }
+
+ async fn created_at(&self) -> String {
+ self.0.created_at.to_rfc3339()
+ }
+
+ async fn updated_at(&self) -> String {
+ self.0.updated_at.to_rfc3339()
+ }
+
+ async fn deleted_at(&self) -> Option<String> {
+ self.0.deleted_at.map(|ts| ts.to_rfc3339())
+ }
+
+ async fn mentions(&self) -> &[String] {
+ &self.0.mentions
+ }
+}
+
/// GraphQL channel entity.
pub struct GraphqlSoupChannel(SoupChannel);
@@ -725,6 +1043,15 @@ impl GraphqlSoupChannel {
self.0.channel.channel.owner_id.as_ref().to_owned()
}
+ async fn organization_id(&self) -> Option<ID> {
+ self.0
+ .channel
+ .channel
+ .org_id
+ .as_ref()
+ .map(|id| ID(id.0.to_string()))
+ }
+
async fn team_id(&self) -> Option<ID> {
self.0.channel.channel.team_id.map(|id| ID(id.to_string()))
}
@@ -741,10 +1068,49 @@ impl GraphqlSoupChannel {
self.0.viewed_at.map(|ts| ts.to_rfc3339())
}
+ async fn interacted_at(&self) -> Option<String> {
+ self.0.interacted_at.map(|ts| ts.to_rfc3339())
+ }
+
async fn participant_count(&self) -> usize {
self.0.channel.participants.len()
}
+ async fn participant_ids(&self) -> Vec<String> {
+ self.0
+ .channel
+ .participants
+ .iter()
+ .map(|participant| participant.user_id.as_ref().to_owned())
+ .collect()
+ }
+
+ async fn participants(&self) -> Vec<GraphqlSoupChannelParticipant> {
+ self.0
+ .channel
+ .participants
+ .iter()
+ .cloned()
+ .map(GraphqlSoupChannelParticipant)
+ .collect()
+ }
+
+ async fn latest_message(&self) -> Option<GraphqlSoupChannelMessage> {
+ self.0
+ .latest_message
+ .latest_message
+ .clone()
+ .map(GraphqlSoupChannelMessage)
+ }
+
+ async fn latest_non_thread_message(&self) -> Option<GraphqlSoupChannelMessage> {
+ self.0
+ .latest_message
+ .latest_non_thread_message
+ .clone()
+ .map(GraphqlSoupChannelMessage)
+ }
+
async fn notifications(
&self,
ctx: &Context<'_>,
@@ -812,6 +1178,38 @@ impl GraphqlSoupChannelThread {
}
}
+/// GraphQL call participant.
+pub struct GraphqlSoupCallParticipant {
+ user_id: String,
+ joined_at: String,
+ left_at: Option<String>,
+}
+
+impl From<&SoupCallRecordParticipant> for GraphqlSoupCallParticipant {
+ fn from(value: &SoupCallRecordParticipant) -> Self {
+ Self {
+ user_id: value.user_id.clone(),
+ joined_at: value.joined_at.to_rfc3339(),
+ left_at: value.left_at.map(|ts| ts.to_rfc3339()),
+ }
+ }
+}
+
+#[Object]
+impl GraphqlSoupCallParticipant {
+ async fn user_id(&self) -> &str {
+ &self.user_id
+ }
+
+ async fn joined_at(&self) -> &str {
+ &self.joined_at
+ }
+
+ async fn left_at(&self) -> Option<&str> {
+ self.left_at.as_deref()
+ }
+}
+
/// GraphQL call entity.
pub struct GraphqlSoupCall(SoupCallRecord);
@@ -825,10 +1223,18 @@ impl GraphqlSoupCall {
ID(self.0.channel_id.to_string())
}
+ async fn channel_name(&self) -> Option<&str> {
+ self.0.channel_name.as_deref()
+ }
+
async fn created_by(&self) -> &str {
&self.0.created_by
}
+ async fn custom_name(&self) -> Option<&str> {
+ self.0.custom_name.as_deref()
+ }
+
async fn name(&self) -> Option<&str> {
self.0
.custom_name
@@ -856,6 +1262,14 @@ impl GraphqlSoupCall {
self.0.is_active
}
+ async fn status(&self) -> &'static str {
+ match self.0.status {
+ item_filters::CallStatus::Attended => "ATTENDED",
+ item_filters::CallStatus::Missed => "MISSED",
+ item_filters::CallStatus::Unattended => "UNATTENDED",
+ }
+ }
+
async fn attended(&self) -> bool {
self.0.attended
}
@@ -864,6 +1278,22 @@ impl GraphqlSoupCall {
self.0.participants.len()
}
+ async fn participant_ids(&self) -> Vec<String> {
+ self.0
+ .participants
+ .iter()
+ .map(|participant| participant.user_id.clone())
+ .collect()
+ }
+
+ async fn participants(&self) -> Vec<GraphqlSoupCallParticipant> {
+ self.0
+ .participants
+ .iter()
+ .map(GraphqlSoupCallParticipant::from)
+ .collect()
+ }
+
async fn notifications(
&self,
ctx: &Context<'_>,
@@ -984,3 +1414,6 @@ impl GraphqlSoupForeignEntity {
.await
}
}
+
+#[cfg(test)]
+mod tests;
diff --git a/rust/cloud-storage/graphql_soup/src/objects/tests.rs b/rust/cloud-storage/graphql_soup/src/objects/tests.rs
new file mode 100644
index 0000000000..31891f4746
--- /dev/null
+++ b/rust/cloud-storage/graphql_soup/src/objects/tests.rs
@@ -0,0 +1,41 @@
+#[test]
+fn soup_response_schema_exposes_frontend_fields() {
+ let sdl = crate::build_schema().sdl();
+
+ for expected in [
+ "type GraphqlSoupChannel {",
+ "organizationId: ID",
+ "interactedAt: String",
+ "participantIds: [String!]!",
+ "participants: [GraphqlSoupChannelParticipant!]!",
+ "latestMessage: GraphqlSoupChannelMessage",
+ "latestNonThreadMessage: GraphqlSoupChannelMessage",
+ "type GraphqlSoupEmailThread {",
+ "providerId: String",
+ "inboxVisible: Boolean!",
+ "linkId: ID",
+ "senderPhotoUrl: String",
+ "participants: [GraphqlSoupEmailParticipant!]!",
+ "attachments: [GraphqlSoupEmailAttachment!]!",
+ "labels: [GraphqlSoupEmailLabel!]!",
+ "properties: [GraphqlSoupProperty!]!",
+ "type GraphqlSoupCall {",
+ "channelName: String",
+ "customName: String",
+ "status: String!",
+ "participantIds: [String!]!",
+ "participants: [GraphqlSoupCallParticipant!]!",
+ "type GraphqlSoupChat {",
+ "deletedAt: String",
+ "type GraphqlSoupProject {",
+ ] {
+ assert_sdl_line(&sdl, expected);
+ }
+}
+
+fn assert_sdl_line(sdl: &str, expected: &str) {
+ assert!(
+ sdl.lines().any(|line| line.trim() == expected),
+ "schema missing exact line `{expected}`"
+ );
+}
diff --git a/rust/cloud-storage/schema.graphql b/rust/cloud-storage/schema.graphql
new file mode 100644
index 0000000000..dff716217a
--- /dev/null
+++ b/rust/cloud-storage/schema.graphql
@@ -0,0 +1,733 @@
+input GraphqlCallBinaryExpr {
+ left: GraphqlCallExpr!
+ right: GraphqlCallExpr!
+}
+
+input GraphqlCallExpr @oneOf {
+ and: GraphqlCallBinaryExpr
+ or: GraphqlCallBinaryExpr
+ not: GraphqlCallExpr
+ literal: GraphqlCallLiteral
+}
+
+input GraphqlCallLiteral @oneOf {
+ callId: ID
+ channelId: ID
+ speaker: String
+ status: GraphqlCallStatus
+ attended: Boolean
+}
+
+enum GraphqlCallStatus {
+ ATTENDED
+ MISSED
+ UNATTENDED
+}
+
+input GraphqlChannelBinaryExpr {
+ left: GraphqlChannelExpr!
+ right: GraphqlChannelExpr!
+}
+
+input GraphqlChannelExpr @oneOf {
+ and: GraphqlChannelBinaryExpr
+ or: GraphqlChannelBinaryExpr
+ not: GraphqlChannelExpr
+ literal: GraphqlChannelLiteral
+}
+
+input GraphqlChannelLiteral @oneOf {
+ threadId: ID
+ mention: String
+ organizationId: Int
+ teamId: ID
+ channelId: ID
+ sender: String
+ channelType: GraphqlChannelTypeFilter
+ importance: Boolean
+ notificationDone: Boolean
+ notificationSeen: Boolean
+}
+
+input GraphqlChannelThreadBinaryExpr {
+ left: GraphqlChannelThreadExpr!
+ right: GraphqlChannelThreadExpr!
+}
+
+input GraphqlChannelThreadExpr @oneOf {
+ and: GraphqlChannelThreadBinaryExpr
+ or: GraphqlChannelThreadBinaryExpr
+ not: GraphqlChannelThreadExpr
+ literal: GraphqlChannelThreadLiteral
+}
+
+input GraphqlChannelThreadLiteral @oneOf {
+ threadId: ID
+ channelId: ID
+ rootSender: String
+ notificationDone: Boolean
+ notificationSeen: Boolean
+}
+
+enum GraphqlChannelTypeFilter {
+ PUBLIC
+ PRIVATE
+ DIRECT_MESSAGE
+ TEAM
+}
+
+input GraphqlChatBinaryExpr {
+ left: GraphqlChatExpr!
+ right: GraphqlChatExpr!
+}
+
+input GraphqlChatExpr @oneOf {
+ and: GraphqlChatBinaryExpr
+ or: GraphqlChatBinaryExpr
+ not: GraphqlChatExpr
+ literal: GraphqlChatLiteral
+}
+
+input GraphqlChatLiteral @oneOf {
+ projectId: ID
+ role: GraphqlChatRole
+ chatId: ID
+ owner: String
+ importance: Boolean
+ notificationDone: Boolean
+ notificationSeen: Boolean
+ createdAt: GraphqlDateLiteral
+ updatedAt: GraphqlDateLiteral
+}
+
+enum GraphqlChatRole {
+ USER
+ SYSTEM
+ ASSISTANT
+}
+
+input GraphqlCrmCompanyBinaryExpr {
+ left: GraphqlCrmCompanyExpr!
+ right: GraphqlCrmCompanyExpr!
+}
+
+input GraphqlCrmCompanyExpr @oneOf {
+ and: GraphqlCrmCompanyBinaryExpr
+ or: GraphqlCrmCompanyBinaryExpr
+ not: GraphqlCrmCompanyExpr
+ literal: GraphqlCrmCompanyLiteral
+}
+
+input GraphqlCrmCompanyLiteral @oneOf {
+ id: ID
+ hidden: Boolean
+}
+
+input GraphqlCrmScope @oneOf {
+ domains: [String!]
+ addresses: [String!]
+}
+
+input GraphqlDateLiteral @oneOf {
+ gt: String
+ lt: String
+ gte: String
+ lte: String
+}
+
+input GraphqlDocumentBinaryExpr {
+ left: GraphqlDocumentExpr!
+ right: GraphqlDocumentExpr!
+}
+
+input GraphqlDocumentExpr @oneOf {
+ and: GraphqlDocumentBinaryExpr
+ or: GraphqlDocumentBinaryExpr
+ not: GraphqlDocumentExpr
+ literal: GraphqlDocumentLiteral
+}
+
+input GraphqlDocumentLiteral @oneOf {
+ fileType: String
+ id: ID
+ projectId: ID
+ owner: String
+ importance: Boolean
+ notificationDone: Boolean
+ notificationSeen: Boolean
+ includeCbmAtmNc: Boolean
+ subType: GraphqlDocumentSubType
+ fileAssoc: String
+ isEmailAttachment: Boolean
+ createdAt: GraphqlDateLiteral
+ updatedAt: GraphqlDateLiteral
+}
+
+enum GraphqlDocumentSubType {
+ TASK
+ SNIPPET
+}
+
+input GraphqlEmailBinaryExpr {
+ left: GraphqlEmailExpr!
+ right: GraphqlEmailExpr!
+}
+
+input GraphqlEmailExpr @oneOf {
+ and: GraphqlEmailBinaryExpr
+ or: GraphqlEmailBinaryExpr
+ not: GraphqlEmailExpr
+ literal: GraphqlEmailLiteral
+}
+
+input GraphqlEmailFilterAst {
+ tree: GraphqlEmailExpr
+ crmScope: GraphqlCrmScope
+}
+
+input GraphqlEmailLiteral @oneOf {
+ sender: GraphqlEmailValue
+ cc: GraphqlEmailValue
+ bcc: GraphqlEmailValue
+ recipient: GraphqlEmailValue
+ threadId: ID
+ owner: ID
+ projectId: String
+ importance: Boolean
+ notificationDone: Boolean
+ notificationSeen: Boolean
+ shared: GraphqlSharedEmailFilter
+ calendarOnly: Boolean
+ createdAt: GraphqlDateLiteral
+ updatedAt: GraphqlDateLiteral
+}
+
+input GraphqlEmailValue @oneOf {
+ partial: String
+ complete: String
+ domain: String
+}
+
+enum GraphqlEmailView {
+ INBOX
+ DRAFTS
+ SENT
+ ALL
+ STARRED
+ IMPORTANT
+ OTHER
+}
+
+"""
+GraphQL input mirroring `item_filters::ast::EntityFilterAst`.
+"""
+input GraphqlEntityFilterAst {
+ documentFilter: GraphqlDocumentExpr
+ projectFilter: GraphqlProjectExpr
+ chatFilter: GraphqlChatExpr
+ emailFilter: GraphqlEmailFilterAst
+ channelFilter: GraphqlChannelExpr
+ channelThreadFilter: GraphqlChannelThreadExpr
+ callFilter: GraphqlCallExpr
+ crmCompanyFilter: GraphqlCrmCompanyExpr
+ foreignEntityFilter: GraphqlForeignEntityExpr
+ propertiesFilter: GraphqlPropertiesExpr
+}
+
+input GraphqlForeignEntityBinaryExpr {
+ left: GraphqlForeignEntityExpr!
+ right: GraphqlForeignEntityExpr!
+}
+
+input GraphqlForeignEntityExpr @oneOf {
+ and: GraphqlForeignEntityBinaryExpr
+ or: GraphqlForeignEntityBinaryExpr
+ not: GraphqlForeignEntityExpr
+ literal: GraphqlForeignEntityLiteral
+}
+
+input GraphqlForeignEntityLiteral @oneOf {
+ id: ID
+ foreignEntityId: String
+ foreignEntitySource: String
+ includesMe: Boolean
+ notificationDone: Boolean
+ notificationSeen: Boolean
+}
+
+input GraphqlProjectBinaryExpr {
+ left: GraphqlProjectExpr!
+ right: GraphqlProjectExpr!
+}
+
+input GraphqlProjectExpr @oneOf {
+ and: GraphqlProjectBinaryExpr
+ or: GraphqlProjectBinaryExpr
+ not: GraphqlProjectExpr
+ literal: GraphqlProjectLiteral
+}
+
+input GraphqlProjectLiteral @oneOf {
+ projectId: ID
+ projectIdSelf: ID
+ owner: String
+ importance: Boolean
+ notificationDone: Boolean
+ notificationSeen: Boolean
+ createdAt: GraphqlDateLiteral
+ updatedAt: GraphqlDateLiteral
+}
+
+input GraphqlPropertiesBinaryExpr {
+ left: GraphqlPropertiesExpr!
+ right: GraphqlPropertiesExpr!
+}
+
+input GraphqlPropertiesExpr @oneOf {
+ and: GraphqlPropertiesBinaryExpr
+ or: GraphqlPropertiesBinaryExpr
+ not: GraphqlPropertiesExpr
+ literal: GraphqlPropertiesLiteral
+}
+
+input GraphqlPropertiesLiteral {
+ propertyDefinitionId: ID!
+ entityType: GraphqlPropertyEntityType
+ value: GraphqlPropertyMatchValue!
+}
+
+enum GraphqlPropertyEntityType {
+ CHANNEL
+ CHAT
+ COMPANY
+ DOCUMENT
+ PROJECT
+ TASK
+ THREAD
+ USER
+}
+
+input GraphqlPropertyMatchValue @oneOf {
+ selectOption: ID
+ entityRef: String
+}
+
+enum GraphqlSharedEmailFilter {
+ EXCLUDE
+ INCLUDE
+ ONLY
+}
+
+"""
+GraphQL representation of supported simple Soup sorts.
+"""
+enum GraphqlSimpleSortMethod {
+ """
+ Sort by most recently viewed.
+ """
+ VIEWED_AT
+ """
+ Sort by creation timestamp.
+ """
+ CREATED_AT
+ """
+ Sort by update timestamp.
+ """
+ UPDATED_AT
+ """
+ Sort by viewed timestamp, falling back to updated timestamp.
+ """
+ VIEWED_UPDATED
+}
+
+type GraphqlSoupCall {
+ id: ID!
+ channelId: ID!
+ channelName: String
+ createdBy: String!
+ customName: String
+ name: String
+ summary: String
+ startedAt: String!
+ endedAt: String
+ durationMs: Int
+ isActive: Boolean!
+ status: String!
+ attended: Boolean!
+ participantCount: Int!
+ participantIds: [String!]!
+ participants: [GraphqlSoupCallParticipant!]!
+ notifications: [GraphqlSoupNotification!]!
+}
+
+type GraphqlSoupCallParticipant {
+ userId: String!
+ joinedAt: String!
+ leftAt: String
+}
+
+type GraphqlSoupChannel {
+ id: ID!
+ name: String
+ channelType: String!
+ ownerId: String!
+ organizationId: ID
+ teamId: ID
+ createdAt: String!
+ updatedAt: String!
+ viewedAt: String
+ interactedAt: String
+ participantCount: Int!
+ participantIds: [String!]!
+ participants: [GraphqlSoupChannelParticipant!]!
+ latestMessage: GraphqlSoupChannelMessage
+ latestNonThreadMessage: GraphqlSoupChannelMessage
+ notifications: [GraphqlSoupNotification!]!
+}
+
+type GraphqlSoupChannelMessage {
+ messageId: ID!
+ threadId: ID
+ senderId: String!
+ content: String!
+ createdAt: String!
+ updatedAt: String!
+ deletedAt: String
+ mentions: [String!]!
+}
+
+type GraphqlSoupChannelParticipant {
+ channelId: ID!
+ userId: String!
+ role: String!
+ joinedAt: String!
+ leftAt: String
+}
+
+type GraphqlSoupChannelThread {
+ id: ID!
+ channelId: ID!
+ senderId: String!
+ content: String!
+ createdAt: String!
+ updatedAt: String!
+ effectiveUpdatedAt: String!
+ replyCount: Int!
+ notifications: [GraphqlSoupNotification!]!
+}
+
+type GraphqlSoupChat {
+ id: ID!
+ name: String!
+ ownerId: String!
+ projectId: ID
+ isPersistent: Boolean!
+ createdAt: String!
+ updatedAt: String!
+ viewedAt: String
+ deletedAt: String
+ properties: [GraphqlSoupProperty!]!
+ notifications: [GraphqlSoupNotification!]!
+}
+
+type GraphqlSoupCrmCompany {
+ id: ID!
+ teamId: ID!
+ name: String
+ description: String
+ emailSync: Boolean!
+ hidden: Boolean!
+ createdAt: String!
+ updatedAt: String!
+ viewedAt: String
+ domains: [String!]!
+ notifications: [GraphqlSoupNotification!]!
+}
+
+type GraphqlSoupDocument {
+ id: ID!
+ name: String!
+ ownerId: String!
+ fileType: String
+ projectId: ID
+ createdAt: String!
+ updatedAt: String!
+ viewedAt: String
+ deletedAt: String
+ subType: GraphqlSoupDocumentSubType
+ properties: [GraphqlSoupProperty!]!
+ notifications: [GraphqlSoupNotification!]!
+}
+
+type GraphqlSoupDocumentSubType {
+ kind: String!
+ isCompleted: Boolean
+}
+
+type GraphqlSoupEmailAttachment {
+ id: ID!
+ messageId: ID!
+ providerAttachmentId: String
+ filename: String
+ mimeType: String
+ sizeBytes: Int
+ contentId: String
+ createdAt: String!
+}
+
+type GraphqlSoupEmailLabel {
+ id: ID!
+ linkId: ID!
+ providerLabelId: String!
+ name: String!
+ createdAt: String!
+ messageListVisibility: String!
+ labelListVisibility: String!
+ type: String!
+}
+
+type GraphqlSoupEmailParticipant {
+ id: ID!
+ linkId: ID!
+ name: String
+ email: String
+ sfsPhotoUrl: String
+}
+
+type GraphqlSoupEmailThread {
+ id: ID!
+ providerId: String
+ ownerId: String!
+ inboxVisible: Boolean!
+ linkId: ID
+ name: String
+ snippet: String
+ senderEmail: String
+ senderName: String
+ senderPhotoUrl: String
+ isRead: Boolean!
+ isDraft: Boolean!
+ isImportant: Boolean!
+ projectId: ID
+ sortTs: String!
+ createdAt: String!
+ updatedAt: String!
+ viewedAt: String
+ attachmentCount: Int!
+ participantCount: Int!
+ participants: [GraphqlSoupEmailParticipant!]!
+ attachments: [GraphqlSoupEmailAttachment!]!
+ labels: [GraphqlSoupEmailLabel!]!
+ properties: [GraphqlSoupProperty!]!
+ notifications: [GraphqlSoupNotification!]!
+}
+
+"""
+GraphQL union over expanded Soup entity variants.
+"""
+union GraphqlSoupEntity = GraphqlSoupDocument | GraphqlSoupChat | GraphqlSoupProject | GraphqlSoupEmailThread | GraphqlSoupChannel | GraphqlSoupChannelThread | GraphqlSoupCall | GraphqlSoupCrmCompany | GraphqlSoupForeignEntity
+
+"""
+GraphQL representation of Soup entity types.
+"""
+enum GraphqlSoupEntityType {
+ """
+ Document entity.
+ """
+ DOCUMENT
+ """
+ Chat entity.
+ """
+ CHAT
+ """
+ Project entity.
+ """
+ PROJECT
+ """
+ Email thread entity.
+ """
+ EMAIL_THREAD
+ """
+ Channel entity.
+ """
+ CHANNEL
+ """
+ Channel thread entity.
+ """
+ CHANNEL_THREAD
+ """
+ Call entity.
+ """
+ CALL
+ """
+ CRM company entity.
+ """
+ CRM_COMPANY
+ """
+ Foreign entity.
+ """
+ FOREIGN_ENTITY
+ """
+ Unknown or unsupported entity type.
+ """
+ UNKNOWN
+}
+
+type GraphqlSoupForeignEntity {
+ id: ID!
+ foreignEntityId: String!
+ foreignEntitySource: String!
+ storedForId: String!
+ storedForAuthEntity: String!
+ metadata: JSON!
+ createdAt: String!
+ updatedAt: String!
+ notifications: [GraphqlSoupNotification!]!
+}
+
+type GraphqlSoupItem {
+ id: String!
+ entityType: GraphqlSoupEntityType!
+ frecencyScore: Float!
+ entity: GraphqlSoupEntity!
+}
+
+type GraphqlSoupNotification {
+ id: ID!
+ eventType: String!
+ entityType: GraphqlSoupEntityType!
+ entityId: String!
+ sent: Boolean!
+ done: Boolean!
+ seen: Boolean!
+ createdAt: String!
+ viewedAt: String
+ updatedAt: String!
+ senderId: String
+ metadata: JSON!
+}
+
+type GraphqlSoupProject {
+ id: ID!
+ name: String!
+ ownerId: String!
+ parentId: ID
+ createdAt: String!
+ updatedAt: String!
+ viewedAt: String
+ deletedAt: String
+ properties: [GraphqlSoupProperty!]!
+ notifications: [GraphqlSoupNotification!]!
+}
+
+type GraphqlSoupProperty {
+ id: ID!
+ displayName: String!
+ dataType: String!
+ isMultiSelect: Boolean!
+ specificEntityType: String
+ isSystem: Boolean!
+ isMetadata: Boolean!
+ value: GraphqlSoupPropertyValue
+}
+
+"""
+GraphQL entity reference stored in a property value.
+"""
+type GraphqlSoupPropertyEntityReference {
+ entityId: String!
+ entityType: String!
+ specificMessageId: ID
+}
+
+"""
+GraphQL representation of a property value.
+"""
+type GraphqlSoupPropertyValue {
+ kind: String!
+ boolValue: Boolean
+ numberValue: Float
+ stringValue: String
+ dateValue: String
+ selectOptionIds: [ID!]!
+ entityReferences: [GraphqlSoupPropertyEntityReference!]!
+ links: [String!]!
+}
+
+"""
+A scalar that can represent any JSON value.
+"""
+scalar JSON
+
+"""
+Input for `Query.soup`.
+"""
+input SoupInput {
+ """
+ Maximum number of items to return. Defaults to 20, max 500.
+ """
+ limit: Int
+ """
+ Whether to return expanded Soup items. Defaults to true.
+ """
+ expand: Boolean
+ """
+ Simple timestamp sort. Defaults to VIEWED_AT. Frecency is intentionally
+ not supported by this initial GraphQL adapter.
+ """
+ sortMethod: GraphqlSimpleSortMethod
+ """
+ Opaque cursor returned by a previous GraphQL Soup response.
+ """
+ cursor: String
+ """
+ Email preview view used when hydrating email Soup items.
+ """
+ emailView: GraphqlEmailView
+ """
+ AST-shaped filters applied to each Soup entity type.
+ """
+ filters: GraphqlEntityFilterAst
+}
+
+"""
+Page returned by `Query.soup`.
+"""
+type SoupPage {
+ """
+ Items in the current page.
+ """
+ items: [GraphqlSoupItem!]!
+ """
+ Opaque cursor for the next page, if one exists.
+ """
+ nextCursor: String
+ """
+ Whether more items are available after this page.
+ """
+ hasMore: Boolean!
+}
+
+type SoupQueryRoot {
+ """
+ Fetch a page of Soup items using the existing Soup filter AST format.
+ """
+ soup(input: SoupInput!): SoupPage!
+}
+
+"""
+Directs the executor to include this field or fragment only when the `if` argument is true.
+"""
+directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
+"""
+Indicates that an Input Object is a OneOf Input Object (and thus requires exactly one of its field be provided)
+"""
+directive @oneOf on INPUT_OBJECT
+"""
+Directs the executor to skip this field or fragment when the `if` argument is true.
+"""
+directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
+schema {
+ query: SoupQueryRoot
+}
+