Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions crates/lineark-codegen/src/emit_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ fn emit_struct(obj: &ObjectDef, type_kind_map: &HashMap<String, TypeKind>) -> To
}

/// Check if a field should be included in the struct.
/// Includes Scalar, Enum, and Object types (for nested objects).
/// Excludes Interface and Union types (not representable as simple structs).
/// Includes Scalar, Enum, Object, and Interface types.
/// Excludes Union types (not representable as simple structs).
fn is_includable_field(ty: &GqlType, type_kind_map: &HashMap<String, TypeKind>) -> bool {
let base = ty.base_name();
matches!(
type_kind_map.get(base),
Some(TypeKind::Scalar) | Some(TypeKind::Enum) | Some(TypeKind::Object)
Some(TypeKind::Scalar)
| Some(TypeKind::Enum)
| Some(TypeKind::Object)
| Some(TypeKind::Interface)
)
}

Expand All @@ -85,7 +88,10 @@ fn is_includable_field(ty: &GqlType, type_kind_map: &HashMap<String, TypeKind>)
fn resolve_type(ty: &GqlType, type_kind_map: &HashMap<String, TypeKind>) -> TokenStream {
let inner = resolve_inner_type(ty, type_kind_map);
let base = ty.base_name();
if matches!(type_kind_map.get(base), Some(TypeKind::Object)) {
if matches!(
type_kind_map.get(base),
Some(TypeKind::Object) | Some(TypeKind::Interface)
) {
quote! { Option<Box<#inner>> }
} else {
quote! { Option<#inner> }
Expand All @@ -98,7 +104,7 @@ fn resolve_inner_type(ty: &GqlType, type_kind_map: &HashMap<String, TypeKind>) -
GqlType::Named(name) => {
let base = name.as_str();
match type_kind_map.get(base) {
Some(TypeKind::Object) => {
Some(TypeKind::Object) | Some(TypeKind::Interface) => {
let ident = quote::format_ident!("{}", name);
quote! { #ident }
}
Expand Down
7 changes: 7 additions & 0 deletions crates/lineark-codegen/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ pub fn parse(schema_text: &str) -> ParsedSchema {
}
cst::Definition::InterfaceTypeDefinition(i) => {
let name = extract_name(&i.name());
let description = extract_description(&i.description());
type_kind_map.insert(name.clone(), TypeKind::Interface);
let fields = extract_fields(&i.fields_definition());
objects.push(ObjectDef {
name,
description,
fields,
});
}
cst::Definition::UnionTypeDefinition(u) => {
let name = extract_name(&u.name());
Expand Down
36 changes: 36 additions & 0 deletions crates/lineark-sdk/src/generated/client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ impl Client {
) -> Result<T, LinearError> {
crate::generated::queries::project_milestone::<T>(self, id).await
}
/// All notifications.
///
/// Full type: [`Notification`](super::types::Notification)
pub fn notifications<T>(&self) -> NotificationsQueryBuilder<'_, T> {
crate::generated::queries::notifications(self)
}
/// One specific notification.
///
/// Full type: [`Notification`](super::types::Notification)
pub async fn notification<
T: DeserializeOwned + GraphQLFields<FullType = super::types::Notification>,
>(
&self,
id: String,
) -> Result<T, LinearError> {
crate::generated::queries::notification::<T>(self, id).await
}
/// All issues.
///
/// Full type: [`Issue`](super::types::Issue)
Expand Down Expand Up @@ -319,6 +336,25 @@ impl Client {
) -> Result<serde_json::Value, LinearError> {
crate::generated::mutations::project_milestone_delete(self, id).await
}
/// Updates a notification.
pub async fn notification_update(
&self,
input: NotificationUpdateInput,
id: String,
) -> Result<serde_json::Value, LinearError> {
crate::generated::mutations::notification_update(self, input, id).await
}
/// Archives a notification.
pub async fn notification_archive(&self, id: String) -> Result<serde_json::Value, LinearError> {
crate::generated::mutations::notification_archive(self, id).await
}
/// Unarchives a notification.
pub async fn notification_unarchive(
&self,
id: String,
) -> Result<serde_json::Value, LinearError> {
crate::generated::mutations::notification_unarchive(self, id).await
}
/// Creates a new issue.
///
/// Full type: [`Issue`](super::types::Issue)
Expand Down
45 changes: 45 additions & 0 deletions crates/lineark-sdk/src/generated/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,51 @@ pub async fn project_milestone_delete(
.execute::<serde_json::Value>(&query, variables, "projectMilestoneDelete")
.await
}
/// Updates a notification.
pub async fn notification_update(
client: &Client,
input: NotificationUpdateInput,
id: String,
) -> Result<serde_json::Value, LinearError> {
let variables = serde_json::json!({ "input" : input, "id" : id });
let response_parts: Vec<String> = vec!["success".to_string()];
let query = String::from(
"mutation NotificationUpdate($input: NotificationUpdateInput!, $id: String!) { notificationUpdate(input: $input, id: $id) { ",
) + &response_parts.join(" ") + " } }";
client
.execute::<serde_json::Value>(&query, variables, "notificationUpdate")
.await
}
/// Archives a notification.
pub async fn notification_archive(
client: &Client,
id: String,
) -> Result<serde_json::Value, LinearError> {
let variables = serde_json::json!({ "id" : id });
let response_parts: Vec<String> = vec!["success".to_string()];
let query = String::from(
"mutation NotificationArchive($id: String!) { notificationArchive(id: $id) { ",
) + &response_parts.join(" ")
+ " } }";
client
.execute::<serde_json::Value>(&query, variables, "notificationArchive")
.await
}
/// Unarchives a notification.
pub async fn notification_unarchive(
client: &Client,
id: String,
) -> Result<serde_json::Value, LinearError> {
let variables = serde_json::json!({ "id" : id });
let response_parts: Vec<String> = vec!["success".to_string()];
let query = String::from(
"mutation NotificationUnarchive($id: String!) { notificationUnarchive(id: $id) { ",
) + &response_parts.join(" ")
+ " } }";
client
.execute::<serde_json::Value>(&query, variables, "notificationUnarchive")
.await
}
/// Creates a new issue.
///
/// Full type: [`Issue`](super::types::Issue)
Expand Down
120 changes: 120 additions & 0 deletions crates/lineark-sdk/src/generated/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,93 @@ impl<'a, T: DeserializeOwned + GraphQLFields<FullType = super::types::ProjectMil
.await
}
}
/// Query builder: All notifications.
///
/// Full type: [`Notification`](super::types::Notification)
///
/// Use setter methods to configure optional parameters, then call
/// [`.send()`](Self::send) to execute the query.
#[must_use]
pub struct NotificationsQueryBuilder<'a, T> {
client: &'a Client,
filter: Option<NotificationFilter>,
before: Option<String>,
after: Option<String>,
first: Option<i64>,
last: Option<i64>,
include_archived: Option<bool>,
order_by: Option<PaginationOrderBy>,
_marker: std::marker::PhantomData<T>,
}
impl<'a, T: DeserializeOwned + GraphQLFields<FullType = super::types::Notification>>
NotificationsQueryBuilder<'a, T>
{
pub fn filter(mut self, value: NotificationFilter) -> Self {
self.filter = Some(value);
self
}
pub fn before(mut self, value: impl Into<String>) -> Self {
self.before = Some(value.into());
self
}
pub fn after(mut self, value: impl Into<String>) -> Self {
self.after = Some(value.into());
self
}
pub fn first(mut self, value: i64) -> Self {
self.first = Some(value);
self
}
pub fn last(mut self, value: i64) -> Self {
self.last = Some(value);
self
}
pub fn include_archived(mut self, value: bool) -> Self {
self.include_archived = Some(value);
self
}
pub fn order_by(mut self, value: PaginationOrderBy) -> Self {
self.order_by = Some(value);
self
}
pub async fn send(self) -> Result<Connection<T>, LinearError> {
let mut map = serde_json::Map::new();
if let Some(ref v) = self.filter {
map.insert("filter".to_string(), serde_json::json!(v));
}
if let Some(ref v) = self.before {
map.insert("before".to_string(), serde_json::json!(v));
}
if let Some(ref v) = self.after {
map.insert("after".to_string(), serde_json::json!(v));
}
if let Some(ref v) = self.first {
map.insert("first".to_string(), serde_json::json!(v));
}
if let Some(ref v) = self.last {
map.insert("last".to_string(), serde_json::json!(v));
}
if let Some(ref v) = self.include_archived {
map.insert("includeArchived".to_string(), serde_json::json!(v));
}
if let Some(ref v) = self.order_by {
map.insert("orderBy".to_string(), serde_json::json!(v));
}
let variables = serde_json::Value::Object(map);
let selection = T::selection();
let query = format!(
"query {}({}) {{ {}({}) {{ nodes {{ {} }} pageInfo {{ hasNextPage endCursor }} }} }}",
"Notifications",
"$filter: NotificationFilter, $before: String, $after: String, $first: Int, $last: Int, $includeArchived: Boolean, $orderBy: PaginationOrderBy",
"notifications",
"filter: $filter, before: $before, after: $after, first: $first, last: $last, includeArchived: $includeArchived, orderBy: $orderBy",
selection
);
self.client
.execute_connection::<T>(&query, variables, "notifications")
.await
}
}
/// Query builder: All issues.
///
/// Full type: [`Issue`](super::types::Issue)
Expand Down Expand Up @@ -1176,6 +1263,39 @@ pub async fn project_milestone<
.execute::<T>(&query, variables, "projectMilestone")
.await
}
/// All notifications.
///
/// Full type: [`Notification`](super::types::Notification)
pub fn notifications<'a, T>(client: &'a Client) -> NotificationsQueryBuilder<'a, T> {
NotificationsQueryBuilder {
client,
filter: None,
before: None,
after: None,
first: None,
last: None,
include_archived: None,
order_by: None,
_marker: std::marker::PhantomData,
}
}
/// One specific notification.
///
/// Full type: [`Notification`](super::types::Notification)
pub async fn notification<
T: DeserializeOwned + GraphQLFields<FullType = super::types::Notification>,
>(
client: &Client,
id: String,
) -> Result<T, LinearError> {
let variables = serde_json::json!({ "id" : id });
let selection = T::selection();
let query = format!(
"query {}({}) {{ {}({}) {{ {} }} }}",
"Notification", "$id: String!", "notification", "id: $id", selection
);
client.execute::<T>(&query, variables, "notification").await
}
/// All issues.
///
/// Full type: [`Issue`](super::types::Issue)
Expand Down
Loading