cube-js / cube

📊 Cube — Universal semantic layer platform for AI, BI, spreadsheets, and embedded analytics
https://cube.dev
Other
18.01k stars 1.78k forks source link

Support fragments in GraphQL API queries #8717

Open zahinafsar opened 2 months ago

zahinafsar commented 2 months ago

Using fragment in GraphQL

Returns

{
  "errors": [
    {
      "message": "Query should contain either measures, dimensions or timeDimensions with granularities in order to be valid",
      "locations": [
        {
          "line": 34,
          "column": 3
        }
      ],
      "path": [
        "cube"
      ]
    }
  ],
  "data": null
}

The Query

    fragment recoveredSalesStats on Result {
        orders {
            recovered_sales
            created_at @include(if: $charts) {
                            hour @include(if: $isHourly)
                            day @include(if: $isDaily)
                            week @include(if: $isWeekly)
                            month @include(if: $isMonthly)
                            year @include(if: $isYearly)
                        }
        }
    }

    query GetRecoveredSalesStats(
        $currDateRange: [String]
        $prevDateRange: [String]
        $brandId: String
        $workflowId: String
        $charts: Boolean = true
        $isHourly: Boolean = false
        $isDaily: Boolean = false
        $isWeekly: Boolean = false
        $isMonthly: Boolean = false
        $isYearly: Boolean = false
        $timezone: String
    ) {
        cube(
            timezone: $timezone
            where: {
                workflows: { id: { equals: $workflowId } }
                brands: { id: { equals: $brandId } }
                orders: { created_at: { inDateRange: $currDateRange } }
            }
        ) {
            ...recoveredSalesStats
        }
        prev: cube(
            timezone: $timezone
            where: {
                workflows: { id: { equals: $workflowId } }
                brands: { id: { equals: $brandId } }
                orders: { created_at: { inDateRange: $prevDateRange } }
            }
        ) {
            ...recoveredSalesStats
        }
    }
github-actions[bot] commented 1 month 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.