# GraphQL filter with OR Issue

**URL:** <https://community.hubspot.com/t/graphql-filter-with-or-issue/113532>\
**Category:** CMS Development\
**Created:** [August 2, 2024, 1:49am UTC](https://community.hubspot.com/t/graphql-filter-with-or-issue/113532 "2024-08-02T01:49:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JBrake](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jbrake/32/76513_2.png) [@JBrake](https://community.hubspot.com/u/JBrake)\
**Post date:** [August 2, 2024, 1:49am UTC](https://community.hubspot.com/t/graphql-filter-with-or-issue/113532/1 "2024-08-02T01:49:07Z")

</div>

I am using GraphQL to load a list of objects that have the publish\_status of “published” AND where the publish\_date is null OR the publish\_date is less than or equal to today, AND where the expiry\_date is null OR the expiry\_date is greater than or equal to tomorrow.

Is this even possible? I’ve tied every combination I can think of but cannot get the out come I need.  
Has anyone done some thing like this sucessfully before?

```lia-code-sample
# $today: {{ unixtimestamp(today() }}
# $tomorrow {{ unixtimestamp(today().plusDays(1)) }}

query LoadMyObjectList($today: Date, $tomorrow:Date) {
 CRM {
 MyObjects: p_myobject_collection(
 orderBy: start_date__desc
 offset: $page
 limit: $limit
 filter: {publish_status__eq: "published", OR: [{publish_date__lte: $today, publish_date __null: true},{expiry_date__ gte: $today, expiry_date__null: true}]}}
 ) {
 total
 limit
 offset
 items {
 hs_object_id
 name
 description
 link
 publish_status
 publish_date
 start_date
 }
 }
 }
}

```

Jonathan

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [August 2, 2024, 2:25am UTC](https://community.hubspot.com/t/graphql-filter-with-or-issue/113532/2 "2024-08-02T02:25:35Z")

</div>

Hey @JBrake

So I haven’t tested this, but in theory the following query should represent this logical expression:

**publish\_status=“published”** AND (

( **publish\_date \<= $today** AND **expiry\_date \>= $tomorrow** )

OR

( **publish\_date \<= $today** AND **expiry\_date == null** )

OR

( **publish\_date == null** AND **expiry\_date \>= $tomorrow** )

OR

( **publish\_date == null** AND **expiry\_date == null** )

)

```lia-code-sample
# $today: {{ unixtimestamp(today()) }}
# $tomorrow {{ unixtimestamp(today().plusDays(1)) }}

query LoadMyObjectList($today: Date, $tomorrow: Date) {
 CRM {
 MyObjects: p_myobject_collection(
 orderBy: start_date__desc
 offset: $page
 limit: $limit
 filter: {publish_status__eq: "published",
 OR: [
 {publish_date __lte: $today, expiry_date__ gte: $tomorrow},
 {publish_date __lte: $today, expiry_date__ null: true},
 {publish_date __null: true, expiry_date__ gte: $tomorrow},
 {publish_date __null: true, expiry_date__ null: true},
 ]}
 ) {
 total
 limit
 offset
 items {
 hs_object_id
 name
 description
 link
 publish_status
 publish_date
 start_date
 }
 }
 }
}

```

I believe this is what you’re looking for.

You also had a missing “)” when defining your $today variable

Hopefully this gets you moving!

If I can clarify anything please don’t hesitate to reach out!

---

<div class="post-metadata">

**Author:** ![JBrake](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jbrake/32/76513_2.png) [@JBrake](https://community.hubspot.com/u/JBrake)\
**Post date:** [August 2, 2024, 2:34am UTC](https://community.hubspot.com/t/graphql-filter-with-or-issue/113532/3 "2024-08-02T02:34:12Z")

</div>

Thanks for the prompt reply, yeah I tried that and get the error:

```lia-code-sample
"errors": [
 {
 "message": "Exception while fetching data (/CRM/MyObjectsCollection) : No value present",
 "locations": [
 {
 "line": 19,
 "column": 5,
 "sourceName": null
 }
 ],
 "path": [
 "CRM",
 "MyObjectsCollection"
 ],
 "extensions": null,
 "errorType": "DataFetchingException"
 }
 ]

```

Jonathan

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [August 2, 2024, 3:02am UTC](https://community.hubspot.com/t/graphql-filter-with-or-issue/113532/4 "2024-08-02T03:02:42Z")

</div>

Heu @JBrake

The “No value present” error typically occurs in GraphQL when the query attempts to access a value that is either missing or not present in the context it expects.

I would check that all variables are recieving the expected values:

- $today
- $tomorrow
- $page
- $limit

After a quick review when defining $tomorrow you might try the [plus\_time](https://developers.hubspot.com/docs/cms/hubl/filters#plus-time) filter rather than the plusDays function. You may also need to throw a render filter on those today functions to ensure the correct computation order.

EDIT: I would also remove the filters slowly to id which is throwing the error.

---

<div class="post-metadata">

**Author:** ![JBrake](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jbrake/32/76513_2.png) [@JBrake](https://community.hubspot.com/u/JBrake)\
**Post date:** [August 4, 2024, 9:35pm UTC](https://community.hubspot.com/t/graphql-filter-with-or-issue/113532/5 "2024-08-04T21:35:09Z")

</div>

Hey ya,

Sorry for the late reply, our friday come early.

plusDays / plus\_time didn’t make a difference an the output is the same. I have managed to identify the problem though, and have implemented a workaround with an additional property and a workflow, while inforcing that a date is entered into the two date fields I am querying on.  
The problem it seams is this:

`publish_date __null: true, expiry_date__ null: true`

You cannot use \_\_null or \_\_not\_null to check for null values in date fields.  
I reckon you should be, null is a valid (non)value for any field.  
Jonathan

``
