cube icon indicating copy to clipboard operation
cube copied to clipboard

Nullable TimeDimension creates incorrect GraphQL errors

Open iiq374 opened this issue 2 years ago • 9 comments

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

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.

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

iiq374 avatar Aug 02 '23 21:08 iiq374

If you are interested in working on this issue, please leave a comment below and we will be happy to assign the issue to you. If this is the first time you are contributing a Pull Request to Cube.js, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube.js Slack.

github-actions[bot] avatar Aug 10 '23 18:08 github-actions[bot]

Still reproduces on Cube v0.36.7:

Screenshot 2024-10-09 at 00 55 44

igorlukanin avatar Oct 08 '24 22:10 igorlukanin

Yes, confirmed this is still happening on latest version Cube v0.36.7:

kevinleeTCA avatar Oct 09 '24 23:10 kevinleeTCA

Hi @paveltiunov - I did small experiment by changing in the file packages/cubejs-api-gateway/src/graphql.ts timeDimension Object like below and removed notNull condition and it worked.

export const TimeDimension = objectType({
  name: 'TimeDimension',
  definition(t) {
    t.field('value', {
      type: 'DateTime',
    });
    t.nonNull.field('second', {
      type: 'DateTime',
    });
    t.nonNull.field('minute', {
      type: 'DateTime',
    });
    t.nonNull.field('hour', {
      type: 'DateTime',
    });
    t.nonNull.field('day', {
      type: 'DateTime',
    });
    t.nonNull.field('week', {
      type: 'DateTime',
    });
    t.nonNull.field('month', {
      type: 'DateTime',
    });
    t.nonNull.field('quarter', {
      type: 'DateTime'
    });
    t.nonNull.field('year', {
      type: 'DateTime',
    });
  },
});

Will this have any impact on any other thing or not, just wanted to know that. If it does not affect anything can this be changed for all time dimesion granularity types?

rkshvish avatar Mar 10 '25 10:03 rkshvish

This is causing problems for us too. Is there a reason for requiring time dimensions to always be non-null?

shan63 avatar Mar 12 '25 17:03 shan63

Hi! We can't use GraphQL to query views that contain nullable time dimensions, which is a pretty huge blocker. Any progress on this issue? Thanks!

scastiel avatar Mar 19 '25 18:03 scastiel

Any progress on this issue ?

simonwalsh avatar Mar 26 '25 16:03 simonwalsh

Hey there! We’ve also been running into a bit of a roadblock with GraphQL as it doesn’t support querying views that have nullable time dimensions. This has been a pretty big blocker for us, so I just wanted to check if there’s been any progress or updates on that front. Thanks a lot!

alena-kono avatar Apr 11 '25 11:04 alena-kono

Also having to find workarounds for this that should not be necessary.

DarrellKilian avatar Oct 30 '25 08:10 DarrellKilian