From 44453634a2963b9daf8ae598901d33ff7dac4227 Mon Sep 17 00:00:00 2001 From: Julian Bez Date: Thu, 15 Feb 2024 09:12:39 +0100 Subject: [PATCH] Use GET for insights when access token --- frontend/src/queries/query.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/frontend/src/queries/query.ts b/frontend/src/queries/query.ts index 1072be3faa713..465cf19dba7de 100644 --- a/frontend/src/queries/query.ts +++ b/frontend/src/queries/query.ts @@ -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' @@ -181,7 +182,7 @@ export async function query( client_query_id: queryId, session_id: currentSessionId(), } - const [resp] = await legacyInsightQuery({ + const resp = await legacyInsightQuery({ filters: params, currentTeamId: getCurrentTeamId(), methodOptions, @@ -460,10 +461,22 @@ export async function legacyInsightQuery({ currentTeamId, methodOptions, refresh, -}: LegacyInsightQueryParams): Promise<[Response, string]> { - const [apiUrl, data] = legacyInsightQueryData({ filters, currentTeamId, refresh }) +}: LegacyInsightQueryParams): Promise { + 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) || @@ -471,11 +484,12 @@ export async function legacyInsightQuery({ 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): Promise {