cube-js / cube-js/cube

Nullable TimeDimension creates incorrect GraphQL errors

Open
#6,972 9 comments 1 reaction 1 assignee Claimed by @vasilev-alex View on GitHub
api:graphql help wanted
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**Describe the bug**
Where a date or datetime is in GQL whenever that is an optional field an error is returned EG:
Message: Cannot return null for non-nullable field TimeDimension.day
It seems to be because although the TimeDimension is correctly created as optional in the GQL Schema, the properties are not - so querying for the property creates the error.

**To Reproduce**
Steps to reproduce the behavior:
Create a cube with a time dimension:
```
managementStartDate: {
sql: `management_start_date`,
type: `time`,
},
```
Query that field via GQL interface:
managementStartDate {
day
}

Receive errors per null field.

**Expected behavior**
Where the underlying data is null there should be no error included in the errors array.

**Screenshots**
![image](https://github.com/cube-js/cube/assets/5369087/489d307f-82e5-4cf3-ab3e-0075c6304840)

**Minimally reproducible Cube Schema**
In case your bug report is data modelling related please put your minimally reproducible Cube Schema here.
You can use selects without tables in order to achieve that as follows.

```javascript
cube(`Orders`, {
sql: `
select 1 as id, null as shippedDate
UNION ALL
select 2 as id, '2023-07-01 12:00:00.000' as shippedDate
`,
measures: {
count: {
type: `count`,
},
},
dimensions: {
shippedDate: {
sql: `shippedDate`,
type: `time`,
},
},
});
```

**Version:**
0.33.39

**Additional context**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.