Skip to content

GraphQL API does not support fragments #8274

Open
@peterklingelhofer

Description

@peterklingelhofer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api:graphqlIssues related to GraphQL APIenhancementNew feature proposalhelp wantedCommunity contributions are welcome.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions