cube-js/cube

GraphQL API does not support fragments

Open

#8,274 建立於 2024年5月17日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)Rust (19,563 star) (1,965 fork)batch import
api:graphqlhelp wanted

描述

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.

貢獻者指南