-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): add task dependencies/dependents (#9190)
### Description Adds `direct_dependencies` and `direct_dependents` fields to `Task` ### Testing Instructions Added some tests in `tests/query/task.t`
- Loading branch information
1 parent
4402e7d
commit e8ffdb8
Showing
10 changed files
with
234 additions
and
25 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1 +1,74 @@ | ||
use async_graphql::Object; | ||
use turborepo_errors::Spanned; | ||
|
||
use crate::{ | ||
engine::TaskNode, | ||
query::{package::Package, Array}, | ||
run::task_id::TaskId, | ||
}; | ||
|
||
pub struct Task { | ||
pub name: String, | ||
pub package: Package, | ||
pub script: Option<Spanned<String>>, | ||
} | ||
|
||
#[Object] | ||
impl Task { | ||
async fn name(&self) -> String { | ||
self.name.clone() | ||
} | ||
|
||
async fn package(&self) -> Package { | ||
self.package.clone() | ||
} | ||
|
||
async fn script(&self) -> Option<String> { | ||
self.script.as_ref().map(|script| script.value.to_string()) | ||
} | ||
|
||
async fn direct_dependents(&self) -> Array<Task> { | ||
let task_id = TaskId::from_static(self.package.name.to_string(), self.name.clone()); | ||
self.package | ||
.run | ||
.engine() | ||
.dependents(&task_id) | ||
.into_iter() | ||
.flatten() | ||
.filter_map(|task| match task { | ||
TaskNode::Root => None, | ||
TaskNode::Task(task) => Some(Task { | ||
name: task.task().to_string(), | ||
package: Package { | ||
run: self.package.run.clone(), | ||
name: task.package().to_string().into(), | ||
}, | ||
script: self.package.get_tasks().get(task.task()).cloned(), | ||
}), | ||
}) | ||
.collect() | ||
} | ||
|
||
async fn direct_dependencies(&self) -> Array<Task> { | ||
let task_id = TaskId::new(self.package.name.as_ref(), &self.name); | ||
|
||
self.package | ||
.run | ||
.engine() | ||
.dependencies(&task_id) | ||
.into_iter() | ||
.flatten() | ||
.filter_map(|task| match task { | ||
TaskNode::Root => None, | ||
TaskNode::Task(task) => Some(Task { | ||
name: task.task().to_string(), | ||
package: Package { | ||
run: self.package.run.clone(), | ||
name: task.package().to_string().into(), | ||
}, | ||
script: self.package.get_tasks().get(task.task()).cloned(), | ||
}), | ||
}) | ||
.collect() | ||
} | ||
} |
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
Oops, something went wrong.