Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(insights): Use GET for insights when access token #20355

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions frontend/src/queries/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isTrendsFilter,
} from 'scenes/insights/sharedUtils'

import { getCurrentExporterData } from '~/exporter/exporterViewLogic'
import { AnyPartialFilterType, OnlineExportContext, QueryExportContext } from '~/types'

import { queryNodeToFilter } from './nodes/InsightQuery/utils/queryNodeToFilter'
Expand Down Expand Up @@ -181,7 +182,7 @@ export async function query<N extends DataNode = DataNode>(
client_query_id: queryId,
session_id: currentSessionId(),
}
const [resp] = await legacyInsightQuery({
const resp = await legacyInsightQuery({
filters: params,
currentTeamId: getCurrentTeamId(),
methodOptions,
Expand Down Expand Up @@ -460,22 +461,35 @@ export async function legacyInsightQuery({
currentTeamId,
methodOptions,
refresh,
}: LegacyInsightQueryParams): Promise<[Response, string]> {
const [apiUrl, data] = legacyInsightQueryData({ filters, currentTeamId, refresh })
}: LegacyInsightQueryParams): Promise<Response> {
const exporterContext = getCurrentExporterData()
let fetchResponse: Response

// Special case for insights that require an access token, which only works with GET
if (
exporterContext &&
exporterContext.accessToken &&
(isTrendsFilter(filters) ||
isStickinessFilter(filters) ||
isLifecycleFilter(filters) ||
isRetentionFilter(filters))
) {
const apiUrl = legacyInsightQueryURL({ filters, currentTeamId, refresh })
fetchResponse = await api.getResponse(apiUrl, methodOptions)
} else if (
isTrendsFilter(filters) ||
isStickinessFilter(filters) ||
isLifecycleFilter(filters) ||
isRetentionFilter(filters) ||
isFunnelsFilter(filters) ||
isPathsFilter(filters)
) {
const [apiUrl, data] = legacyInsightQueryData({ filters, currentTeamId, refresh })
fetchResponse = await api.createResponse(apiUrl, data, methodOptions)
} else {
throw new Error(`Unsupported insight type: ${filters.insight}`)
}
return [fetchResponse, apiUrl]
return fetchResponse
}

export async function hogqlQuery(queryString: string, values?: Record<string, any>): Promise<HogQLQueryResponse> {
Expand Down
Loading