cube-js/cube

Support fragments in GraphQL API queries

Open

#8717 opened on Sep 17, 2024

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Rust (19,563 stars) (1,965 forks)batch import
api:graphqlhelp wanted

Description

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
		}
	}

Contributor guide