Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(query): predicate bug #9842

Merged
merged 1 commit into from
Jan 29, 2025
Merged
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
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ impl PackagePredicate {
let less_than = self
.less_than
.as_ref()
.map(|pair| Self::check_greater_than(pkg, &pair.field, &pair.value));
.map(|pair| Self::check_less_than(pkg, &pair.field, &pair.value));

let not = self.not.as_ref().map(|predicate| !predicate.check(pkg));
let has = self
.has
Expand Down
8 changes: 7 additions & 1 deletion crates/turborepo-lib/src/query/package.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, sync::Arc};
use std::{collections::HashMap, fmt, sync::Arc};

use async_graphql::Object;
use itertools::Itertools;
Expand All @@ -16,6 +16,12 @@ pub struct Package {
name: PackageName,
}

impl fmt::Debug for Package {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Package").field("name", &self.name).finish()
}
}

impl Package {
pub fn new(run: Arc<Run>, name: PackageName) -> Result<Self, Error> {
run.pkg_dep_graph()
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ fn test_query() -> Result<(), anyhow::Error> {
"npm@10.5.0",
"query",
"get package that doesn't exist" => "query { package(name: \"doesnotexist\") { path } }",
"get packages with less than 1 dependents" => "query { packages(filter: {lessThan: {field: DIRECT_DEPENDENT_COUNT, value: 1}}) { items { name directDependents { length } } } }",
"get packages with more than 0 dependents" => "query { packages(filter: {greaterThan: {field: DIRECT_DEPENDENT_COUNT, value: 0}}) { items { name directDependents { length } } } }",
);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: crates/turborepo/tests/query.rs
expression: query_output
---
{
"data": {
"packages": {
"items": [
{
"name": "//",
"directDependents": {
"length": 0
}
},
{
"name": "another",
"directDependents": {
"length": 0
}
},
{
"name": "my-app",
"directDependents": {
"length": 0
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
source: crates/turborepo/tests/query.rs
expression: query_output
---
{
"data": {
"packages": {
"items": [
{
"name": "//",
"directDependents": {
"length": 0
}
},
{
"name": "another",
"directDependents": {
"length": 0
}
},
{
"name": "my-app",
"directDependents": {
"length": 0
}
},
{
"name": "util",
"directDependents": {
"length": 1
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: crates/turborepo/tests/query.rs
expression: query_output
---
{
"data": {
"packages": {
"items": [
{
"name": "util",
"directDependents": {
"length": 1
}
}
]
}
}
}
Loading