Hi,
Is there a way to Short circuit a filter, e.g. using some sort of OR logic!?
For example, lets say we have the query snippet:
@filter(uid(C_ID))
, where C_ID is populated as:
var(func:eq(customer_id, "123455999")) {
C_ID AS foo_id
}
If the customer_id value (in this case 123455999) did not have a value, is it possible to have logic such that the filter does not fire?
Thanks
MichelDiz
(Michel Diz)
August 24, 2020, 4:32pm
2
What is the type of foo_id
? If this is a custom ID, why you are using uid() func? What value must be evaluated?
Here is a working example:
Mutation:
{
set {
_:e1 <ehid> "1" .
_:c1 <customer_id> "2" .
_:c1 <subscribes_as> _:e1 .
_:o1 <xcode> "x3" .
_:o1 <authenticate_as> _:c1 .
}
}
Query (with filter)
{
var(func:eq(customer_id, "2")) {
C_ID AS customer_id
}
search_by_ehid_using_cust_id_link (func:eq(ehid, "1")) @normalize {
~subscribes_as @filter(uid(C_ID)) {
~authenticate_as{
result: xcode
}
}
}
}
If I pass in customer_id value other than 2, the filter correctly kicks in and no xcode is returned. If however, I dont have a customer_id value at all (and as per your question, this will be an int, so prob be zero in that case ) - i dont want the filter logic to be applied.
MichelDiz
(Michel Diz)
August 24, 2020, 5:12pm
4
Do you mean something like this?
opened 12:48AM - 19 Apr 17 UTC
closed 06:23PM - 16 Oct 19 UTC
kind/feature
priority/P1
area/querylang
status/accepted
We should support `@include` directive.
```
{
var shareids(eq(_share_hash_, "β¦ hash"))
me(id: var(shareids)) { # gives you share ids.
_share_ @include(if: gt(count(var(shareids)), 1))
}
}
```
1 Like
MichelDiz
(Michel Diz)
August 24, 2020, 5:18pm
5
For me, still not clear what you wish as result.
{
var(func:eq(customer_id, "2")) {
C_ID AS customer_id
}
search_by_ehid_using_cust_id_link (func:eq(ehid, "1")) @normalize {
~subscribes_as @filter(uid(C_ID)) {
~authenticate_as{
result: xcode
}
}
}
}
Resutl
{
"data": {
"search_by_ehid_using_cust_id_link": [
{
"result": "x3"
}
]
}
}
This is the main result, which you find it fine.
With the same query, but set to 1 / 0 / or any
var(func:eq(customer_id, "1"))
I get
{
"data": {
"search_by_ehid_using_cust_id_link": []
}
}
And any other combination I gonna have the same result. With this in mind, I canβt get what exactly you wanna have.
Sorry, I know its hairy -
but if customer_id has a value, I want it injected into filter, and the filter used, e.g.
var(func:eq(customer_id, "10000000000"))
if customer_id is not set by the client (and because its an int, will have a default value of 0) - i dont want the filter to run.
so if ehid is β1β and customer_id not set, i want xcode to be x3
@include looks like it would have helped
hey @MichelDiz , just wondering if my last comment clarified better what i am trying to achieve and/or if u had any other thoughts? Cheers
amaster507
(Anthony Master)
August 24, 2020, 8:21pm
8
Are you just wanting to get the single one with a filter if a specific id is given, and if not then get all?
That logic will have to be done by the UI and sent as two different queries.
1 Like
Ok, thanks. In my use case i have quite a few combinations of data with the same pattern, which is why i was trying to avoid pushing this logic to the client
amaster507
(Anthony Master)
August 24, 2020, 9:09pm
10
Build a reusable function that generates that part of the query.
Edit: I updated the name to reflect the actual desired effect.
1 Like