has_prefix filter with arrays #653
Replies: 1 comment
-
Modeling positions explicitly has the advantage of being able to describe
the issue precisely, beyond just "it isn't a prefix." Users appreciate
knowing "an element is missing" versus "items got reordered" etc.
cargo-semver-checks will need a lint like this soon (just waiting on a
schema update) and we're going to implement it that way as well. That would
be my recommendation in general.
If you'd prefer a specific operator for this, it could be implemented but
it'll be a bunch of work to design, build, and test properly. If that's
work you're interested in doing, I'd be happy to point you in the right
direction when I get home from vacation at the end of next week.
…On Thu, Aug 8, 2024, 2:11 PM Miikka Koskinen ***@***.***> wrote:
I'm trying out Trustfall for a prototype of a linter for some data model
changes, basically copying the idea in cargo-semver-checks. I'd like to
figure out how to write a query that checks if one array is a prefix of
another.
I've got a schema like this:
schema { query: RootSchemaQuery }
type RootSchemaQuery {
DataDiff: DataDiff!
}
type DataDiff {
baseline: Data
current: Data!
}
type Data {
items: [String!]!
}
You're allowed to add new items to the end of the items array, but you
aren't allowed to remove or reorder them (you can assume that the items are
unique). I'd like to write a query that finds instance where that's not the
case. For example, this is okay:
{
"baseline": ["a", "b"],
"current": ["a", "b", "c"]
}
This is not:
{
"baseline": ["a", "b"],
"current": ["b", "a", "c"]
}
If items was string, the query below would work. However, it does not
work with arrays.
query {
DataDiff {
baseline { items @output(name: "baseline_items") @tag }
current { items @output(name: "current_items") @filter(op: "not_has_prefix", value: ["%items"]) }
}
}
Is there a way to make this work, or another way to write this query? I
figured out cargo-semver-checks would have similar query somewhere but I
couldn't find an example.
Possible another approach would be to change the schema like this and make
the adapter include the position in the array for each item in the items
array. Then I could query for all the items that are missing or that have
switched places. However, it does not feel as elegant.
type Data {
items: [Item!]!
}
type Item {
value: String!
position: Int
}
—
Reply to this email directly, view it on GitHub
<#653>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAR5MST225GBZXAO26KUPILZQOYFXAVCNFSM6AAAAABMG76QZCVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZXGAZDMOJSGA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
miikka
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying out Trustfall for a prototype of a linter for some data model changes, basically copying the idea in cargo-semver-checks. I'd like to figure out how to write a query that checks if one array is a prefix of another.
I've got a schema like this:
You're allowed to add new items to the end of the
items
array, but you aren't allowed to remove or reorder them (you can assume that the items are unique). I'd like to write a query that finds instance where that's not the case. For example, this is okay:This is not:
If
items
was string, the query below would work. However, it does not work with arrays.Is there a way to make this work, or another way to write this query? I figured out cargo-semver-checks would have similar query somewhere but I couldn't find an example.
Possible another approach would be to change the schema like this and make the adapter include the position in the array for each item in the
items
array. Then I could query for all the items that are missing or that have switched places. However, it does not feel as elegant.Beta Was this translation helpful? Give feedback.
All reactions