Skip to content

Commit

Permalink
Fixing bug with predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Jan 29, 2025
1 parent c9e037e commit 4213e1b
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 2 deletions.
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> {
"[email protected]",
"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
}
}
]
}
}
}

0 comments on commit 4213e1b

Please sign in to comment.