cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.69k stars 1.75k forks source link

GraphQL API does not support fragments #8274

Open peterklingelhofer opened 3 months ago

peterklingelhofer commented 3 months ago

Describe the bug We would expect the GraphQL API to support GraphQL fragments, but all columns coming from GraphQL fragments show up as null.

To Reproduce Steps to reproduce the behavior:

  1. Go to Cube Playground
  2. Click on GraphiQL
  3. Attempt a query with fragments:
    fragment Fields on OrdersMembers {
    count
    totalAmount
    toRemove
    }
    query FragmentQuery {
    cube(
    limit: 5000
    timezone: "America/Los_Angeles"
    ) {
    orders {
      ...Fields
      timestamp {
        hour
      }
    }
    }
    }

Note that all columns return null.

  1. Attempt a non-fragment query:
    query NonFragmentQuery {
    cube(
    limit: 5000
    timezone: "America/Los_Angeles"
    ) {
    orders {
      count
      totalAmount
      toRemove
      timestamp {
        hour
      }
    }
    }
    }

    Note that data returns as we would expect.

Expected behavior Equivalent queries should return the exact same data.

Screenshots If applicable, add screenshots to help explain your problem.

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, 100 as amount, 'new' status
  UNION ALL
  select 2 as id, 200 as amount, 'new' status
  UNION ALL
  select 3 as id, 300 as amount, 'processed' status
  UNION ALL
  select 4 as id, 500 as amount, 'processed' status
  UNION ALL
  select 5 as id, 600 as amount, 'shipped' status
  `,
  measures: {
    count: {
      type: `count`,
    },
    totalAmount: {
      sql: `amount`,
      type: `sum`,
    },
    toRemove: {
      type: `count`,
    },
  },
  dimensions: {
    status: {
      sql: `status`,
      type: `string`,
    },
  },
});

Version: 0.34.50

Additional context I'm not sure if reaching for something like Postgraphile could help standardize the GraphQL implementation here (and be less work to maintain), food for thought.

github-actions[bot] commented 3 months ago

If you are interested in working on this issue, please go ahead and provide PR for that. We'd be happy to review it and merge it. If this is the first time you are contributing a Pull Request to Cube, please check our contribution guidelines. You can also post any questions while contributing in the #contributors channel in the Cube Slack.