Skip to content

Commit 0ecda8b

Browse files
evanpurkhisersnigdhas
authored andcommitted
chore(js): rename queryClient things -> Api* (#47126)
1 parent c50d63a commit 0ecda8b

File tree

7 files changed

+49
-39
lines changed

7 files changed

+49
-39
lines changed

static/app/actionCreators/events.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import {getPeriod} from 'sentry/utils/getPeriod';
1717
import {PERFORMANCE_URL_PARAM} from 'sentry/utils/performance/constants';
1818
import {QueryBatching} from 'sentry/utils/performance/contexts/genericQueryBatcher';
1919
import {
20-
QueryKey,
20+
ApiQueryKey,
2121
useApiQuery,
22+
UseApiQueryOptions,
2223
useMutation,
2324
UseMutationOptions,
2425
useQueryClient,
25-
UseQueryOptions,
2626
} from 'sentry/utils/queryClient';
2727
import RequestError from 'sentry/utils/requestError/requestError';
2828
import useApi from 'sentry/utils/useApi';
@@ -230,13 +230,13 @@ export const makeFetchEventAttachmentsQueryKey = ({
230230
orgSlug,
231231
projectSlug,
232232
eventId,
233-
}: FetchEventAttachmentParameters): QueryKey => [
233+
}: FetchEventAttachmentParameters): ApiQueryKey => [
234234
`/projects/${orgSlug}/${projectSlug}/events/${eventId}/attachments/`,
235235
];
236236

237237
export const useFetchEventAttachments = (
238238
{orgSlug, projectSlug, eventId}: FetchEventAttachmentParameters,
239-
options: Partial<UseQueryOptions<FetchEventAttachmentResponse>> = {}
239+
options: Partial<UseApiQueryOptions<FetchEventAttachmentResponse>> = {}
240240
) => {
241241
const organization = useOrganization();
242242
return useApiQuery<FetchEventAttachmentResponse>(

static/app/actionCreators/prompts.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {Client} from 'sentry/api';
2-
import {QueryKey, useApiQuery} from 'sentry/utils/queryClient';
2+
import {ApiQueryKey, useApiQuery} from 'sentry/utils/queryClient';
33

44
type PromptsUpdateParams = {
55
/**
@@ -92,7 +92,7 @@ export const makePromptsCheckQueryKey = ({
9292
feature,
9393
organizationId,
9494
projectId,
95-
}: PromptCheckParams): QueryKey => [
95+
}: PromptCheckParams): ApiQueryKey => [
9696
'/prompts-activity/',
9797
{query: {feature, organization_id: organizationId, project_id: projectId}},
9898
];

static/app/components/events/interfaces/crashContent/exception/useSourceMapDebug.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import uniqBy from 'lodash/uniqBy';
44
import type {ExceptionValue, Frame, Organization} from 'sentry/types';
55
import {defined} from 'sentry/utils';
66
import {
7-
QueryKey,
7+
ApiQueryKey,
88
useApiQuery,
9+
UseApiQueryOptions,
910
useQueries,
10-
UseQueryOptions,
1111
} from 'sentry/utils/queryClient';
1212
import useApi from 'sentry/utils/useApi';
1313

@@ -83,7 +83,7 @@ const sourceMapDebugQuery = ({
8383
eventId,
8484
frameIdx,
8585
exceptionIdx,
86-
}: UseSourceMapDebugProps): QueryKey => [
86+
}: UseSourceMapDebugProps): ApiQueryKey => [
8787
`/projects/${orgSlug}/${projectSlug}/events/${eventId}/source-map-debug/`,
8888
{
8989
query: {
@@ -105,7 +105,7 @@ export type StacktraceFilenameQuery = {filename: string; query: UseSourceMapDebu
105105

106106
export function useSourceMapDebug(
107107
props?: UseSourceMapDebugProps,
108-
options: Partial<UseQueryOptions<SourceMapDebugResponse>> = {}
108+
options: Partial<UseApiQueryOptions<SourceMapDebugResponse>> = {}
109109
) {
110110
return useApiQuery<SourceMapDebugResponse>(props ? sourceMapDebugQuery(props) : [''], {
111111
staleTime: Infinity,
@@ -125,7 +125,7 @@ export function useSourceMapDebugQueries(props: UseSourceMapDebugProps[]) {
125125
retry: false,
126126
};
127127
return useQueries({
128-
queries: props.map<UseQueryOptions<SourceMapDebugResponse>>(p => {
128+
queries: props.map<UseApiQueryOptions<SourceMapDebugResponse>>(p => {
129129
const key = sourceMapDebugQuery(p);
130130
return {
131131
queryKey: sourceMapDebugQuery(p),

static/app/components/events/interfaces/frame/useStacktraceLink.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {Event, Frame, StacktraceLinkResult} from 'sentry/types';
2-
import {QueryKey, useApiQuery, UseQueryOptions} from 'sentry/utils/queryClient';
2+
import {ApiQueryKey, useApiQuery, UseApiQueryOptions} from 'sentry/utils/queryClient';
33

44
interface UseStacktraceLinkProps {
55
event: Event;
@@ -12,11 +12,11 @@ const stacktraceLinkQueryKey = (
1212
orgSlug: string,
1313
projectSlug: string | undefined,
1414
query: any
15-
): QueryKey => [`/projects/${orgSlug}/${projectSlug}/stacktrace-link/`, {query}];
15+
): ApiQueryKey => [`/projects/${orgSlug}/${projectSlug}/stacktrace-link/`, {query}];
1616

1717
function useStacktraceLink(
1818
{event, frame, orgSlug, projectSlug}: UseStacktraceLinkProps,
19-
options: Partial<UseQueryOptions<StacktraceLinkResult>> = {}
19+
options: Partial<UseApiQueryOptions<StacktraceLinkResult>> = {}
2020
) {
2121
const query = {
2222
file: frame.filename,

static/app/utils/queryClient.tsx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ type QueryKeyEndpointOptions = {
88
query?: Record<string, any>;
99
};
1010

11-
export type QueryKey =
11+
export type ApiQueryKey =
1212
| readonly [url: string]
1313
| readonly [url: string, options: QueryKeyEndpointOptions];
1414

15-
interface UseQueryOptions<TQueryFnData, TError = RequestError, TData = TQueryFnData>
16-
extends Omit<
17-
reactQuery.UseQueryOptions<TQueryFnData, TError, TData, QueryKey>,
15+
export interface UseApiQueryOptions<
16+
TQueryFnData,
17+
TError = RequestError,
18+
TData = TQueryFnData
19+
> extends Omit<
20+
reactQuery.UseQueryOptions<TQueryFnData, TError, TData, ApiQueryKey>,
1821
'queryKey' | 'queryFn'
1922
> {
2023
/**
@@ -35,6 +38,15 @@ interface UseQueryOptions<TQueryFnData, TError = RequestError, TData = TQueryFnD
3538
staleTime: number;
3639
}
3740

41+
/**
42+
* TODO(epurkhiser): Remove once getsentry references are updated
43+
*/
44+
export interface UseQueryOptions<
45+
TQueryFnData,
46+
TError = RequestError,
47+
TData = TQueryFnData
48+
> extends UseApiQueryOptions<TQueryFnData, TError, TData> {}
49+
3850
// Overrides to the default react-query options.
3951
// See https://tanstack.com/query/v4/docs/guides/important-defaults
4052
const DEFAULT_QUERY_CLIENT_CONFIG: QueryClientConfig = {
@@ -47,9 +59,9 @@ const DEFAULT_QUERY_CLIENT_CONFIG: QueryClientConfig = {
4759

4860
function isQueryFn<TQueryFnData, TError, TData>(
4961
queryFnOrQueryOptions?:
50-
| reactQuery.QueryFunction<TQueryFnData, QueryKey>
51-
| UseQueryOptions<TQueryFnData, TError, TData>
52-
): queryFnOrQueryOptions is reactQuery.QueryFunction<TQueryFnData, QueryKey> {
62+
| reactQuery.QueryFunction<TQueryFnData, ApiQueryKey>
63+
| UseApiQueryOptions<TQueryFnData, TError, TData>
64+
): queryFnOrQueryOptions is reactQuery.QueryFunction<TQueryFnData, ApiQueryKey> {
5365
return typeof queryFnOrQueryOptions === 'function';
5466
}
5567

@@ -69,8 +81,8 @@ function isQueryFn<TQueryFnData, TError, TData>(
6981
* );
7082
*/
7183
function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
72-
queryKey: QueryKey,
73-
queryOptions: UseQueryOptions<TQueryFnData, TError, TData>
84+
queryKey: ApiQueryKey,
85+
queryOptions: UseApiQueryOptions<TQueryFnData, TError, TData>
7486
): reactQuery.UseQueryResult<TData, TError>;
7587
/**
7688
* Example usage with custom query function:
@@ -82,16 +94,16 @@ function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
8294
* )
8395
*/
8496
function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
85-
queryKey: QueryKey,
86-
queryFn: reactQuery.QueryFunction<TQueryFnData, QueryKey>,
87-
queryOptions?: UseQueryOptions<TQueryFnData, TError, TData>
97+
queryKey: ApiQueryKey,
98+
queryFn: reactQuery.QueryFunction<TQueryFnData, ApiQueryKey>,
99+
queryOptions?: UseApiQueryOptions<TQueryFnData, TError, TData>
88100
): reactQuery.UseQueryResult<TData, TError>;
89101
function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
90-
queryKey: QueryKey,
102+
queryKey: ApiQueryKey,
91103
queryFnOrQueryOptions:
92-
| reactQuery.QueryFunction<TQueryFnData, QueryKey>
93-
| UseQueryOptions<TQueryFnData, TError, TData>,
94-
queryOptions?: UseQueryOptions<TQueryFnData, TError, TData>
104+
| reactQuery.QueryFunction<TQueryFnData, ApiQueryKey>
105+
| UseApiQueryOptions<TQueryFnData, TError, TData>,
106+
queryOptions?: UseApiQueryOptions<TQueryFnData, TError, TData>
95107
): reactQuery.UseQueryResult<TData, TError> {
96108
// XXX: We need to set persistInFlight to disable query cancellation on unmount.
97109
// The current implementation of our API client does not reject on query
@@ -101,7 +113,7 @@ function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
101113

102114
const [path, endpointOptions] = queryKey;
103115

104-
const defaultQueryFn: reactQuery.QueryFunction<TQueryFnData, QueryKey> = () =>
116+
const defaultQueryFn: reactQuery.QueryFunction<TQueryFnData, ApiQueryKey> = () =>
105117
api.requestPromise(path, {
106118
method: 'GET',
107119
query: endpointOptions?.query,
@@ -121,7 +133,5 @@ function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
121133
// eslint-disable-next-line import/export
122134
export * from '@tanstack/react-query';
123135

124-
const useQuery = useApiQuery;
125-
126136
// eslint-disable-next-line import/export
127-
export {DEFAULT_QUERY_CLIENT_CONFIG, useApiQuery, useQuery, UseQueryOptions};
137+
export {DEFAULT_QUERY_CLIENT_CONFIG, useApiQuery};

static/app/utils/useCommitters.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {Committer} from 'sentry/types';
2-
import {QueryKey, useApiQuery, UseQueryOptions} from 'sentry/utils/queryClient';
2+
import {ApiQueryKey, useApiQuery, UseApiQueryOptions} from 'sentry/utils/queryClient';
33

44
import useOrganization from './useOrganization';
55

@@ -16,11 +16,11 @@ const makeCommittersQueryKey = (
1616
orgSlug: string,
1717
projectSlug: string,
1818
eventId: string
19-
): QueryKey => [`/projects/${orgSlug}/${projectSlug}/events/${eventId}/committers/`];
19+
): ApiQueryKey => [`/projects/${orgSlug}/${projectSlug}/events/${eventId}/committers/`];
2020

2121
function useCommitters(
2222
{eventId, projectSlug}: UseCommittersProps,
23-
options: Partial<UseQueryOptions<CommittersResponse>> = {}
23+
options: Partial<UseApiQueryOptions<CommittersResponse>> = {}
2424
) {
2525
const org = useOrganization();
2626
return useApiQuery<CommittersResponse>(

static/app/views/issueList/queries/useFetchSavedSearchesForOrg.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {SavedSearch} from 'sentry/types';
2-
import {useApiQuery, UseQueryOptions} from 'sentry/utils/queryClient';
2+
import {useApiQuery, UseApiQueryOptions} from 'sentry/utils/queryClient';
33

44
type FetchSavedSearchesForOrgParameters = {
55
orgSlug: string;
@@ -14,7 +14,7 @@ export const makeFetchSavedSearchesForOrgQueryKey = ({
1414

1515
export const useFetchSavedSearchesForOrg = (
1616
{orgSlug}: FetchSavedSearchesForOrgParameters,
17-
options: Partial<UseQueryOptions<FetchSavedSearchesForOrgResponse>> = {}
17+
options: Partial<UseApiQueryOptions<FetchSavedSearchesForOrgResponse>> = {}
1818
) => {
1919
return useApiQuery<FetchSavedSearchesForOrgResponse>(
2020
makeFetchSavedSearchesForOrgQueryKey({orgSlug}),

0 commit comments

Comments
 (0)