Browse Source

chore(js): rename queryClient things -> Api* (#47126)

Evan Purkhiser 1 year ago
parent
commit
0c6d56de27

+ 4 - 4
static/app/actionCreators/events.tsx

@@ -17,12 +17,12 @@ import {getPeriod} from 'sentry/utils/getPeriod';
 import {PERFORMANCE_URL_PARAM} from 'sentry/utils/performance/constants';
 import {QueryBatching} from 'sentry/utils/performance/contexts/genericQueryBatcher';
 import {
-  QueryKey,
+  ApiQueryKey,
   useApiQuery,
+  UseApiQueryOptions,
   useMutation,
   UseMutationOptions,
   useQueryClient,
-  UseQueryOptions,
 } from 'sentry/utils/queryClient';
 import RequestError from 'sentry/utils/requestError/requestError';
 import useApi from 'sentry/utils/useApi';
@@ -230,13 +230,13 @@ export const makeFetchEventAttachmentsQueryKey = ({
   orgSlug,
   projectSlug,
   eventId,
-}: FetchEventAttachmentParameters): QueryKey => [
+}: FetchEventAttachmentParameters): ApiQueryKey => [
   `/projects/${orgSlug}/${projectSlug}/events/${eventId}/attachments/`,
 ];
 
 export const useFetchEventAttachments = (
   {orgSlug, projectSlug, eventId}: FetchEventAttachmentParameters,
-  options: Partial<UseQueryOptions<FetchEventAttachmentResponse>> = {}
+  options: Partial<UseApiQueryOptions<FetchEventAttachmentResponse>> = {}
 ) => {
   const organization = useOrganization();
   return useApiQuery<FetchEventAttachmentResponse>(

+ 2 - 2
static/app/actionCreators/prompts.tsx

@@ -1,5 +1,5 @@
 import type {Client} from 'sentry/api';
-import {QueryKey, useApiQuery} from 'sentry/utils/queryClient';
+import {ApiQueryKey, useApiQuery} from 'sentry/utils/queryClient';
 
 type PromptsUpdateParams = {
   /**
@@ -92,7 +92,7 @@ export const makePromptsCheckQueryKey = ({
   feature,
   organizationId,
   projectId,
-}: PromptCheckParams): QueryKey => [
+}: PromptCheckParams): ApiQueryKey => [
   '/prompts-activity/',
   {query: {feature, organization_id: organizationId, project_id: projectId}},
 ];

+ 5 - 5
static/app/components/events/interfaces/crashContent/exception/useSourceMapDebug.tsx

@@ -4,10 +4,10 @@ import uniqBy from 'lodash/uniqBy';
 import type {ExceptionValue, Frame, Organization} from 'sentry/types';
 import {defined} from 'sentry/utils';
 import {
-  QueryKey,
+  ApiQueryKey,
   useApiQuery,
+  UseApiQueryOptions,
   useQueries,
-  UseQueryOptions,
 } from 'sentry/utils/queryClient';
 import useApi from 'sentry/utils/useApi';
 
@@ -83,7 +83,7 @@ const sourceMapDebugQuery = ({
   eventId,
   frameIdx,
   exceptionIdx,
-}: UseSourceMapDebugProps): QueryKey => [
+}: UseSourceMapDebugProps): ApiQueryKey => [
   `/projects/${orgSlug}/${projectSlug}/events/${eventId}/source-map-debug/`,
   {
     query: {
@@ -105,7 +105,7 @@ export type StacktraceFilenameQuery = {filename: string; query: UseSourceMapDebu
 
 export function useSourceMapDebug(
   props?: UseSourceMapDebugProps,
-  options: Partial<UseQueryOptions<SourceMapDebugResponse>> = {}
+  options: Partial<UseApiQueryOptions<SourceMapDebugResponse>> = {}
 ) {
   return useApiQuery<SourceMapDebugResponse>(props ? sourceMapDebugQuery(props) : [''], {
     staleTime: Infinity,
@@ -125,7 +125,7 @@ export function useSourceMapDebugQueries(props: UseSourceMapDebugProps[]) {
     retry: false,
   };
   return useQueries({
-    queries: props.map<UseQueryOptions<SourceMapDebugResponse>>(p => {
+    queries: props.map<UseApiQueryOptions<SourceMapDebugResponse>>(p => {
       const key = sourceMapDebugQuery(p);
       return {
         queryKey: sourceMapDebugQuery(p),

+ 3 - 3
static/app/components/events/interfaces/frame/useStacktraceLink.tsx

@@ -1,5 +1,5 @@
 import type {Event, Frame, StacktraceLinkResult} from 'sentry/types';
-import {QueryKey, useApiQuery, UseQueryOptions} from 'sentry/utils/queryClient';
+import {ApiQueryKey, useApiQuery, UseApiQueryOptions} from 'sentry/utils/queryClient';
 
 interface UseStacktraceLinkProps {
   event: Event;
@@ -12,11 +12,11 @@ const stacktraceLinkQueryKey = (
   orgSlug: string,
   projectSlug: string | undefined,
   query: any
-): QueryKey => [`/projects/${orgSlug}/${projectSlug}/stacktrace-link/`, {query}];
+): ApiQueryKey => [`/projects/${orgSlug}/${projectSlug}/stacktrace-link/`, {query}];
 
 function useStacktraceLink(
   {event, frame, orgSlug, projectSlug}: UseStacktraceLinkProps,
-  options: Partial<UseQueryOptions<StacktraceLinkResult>> = {}
+  options: Partial<UseApiQueryOptions<StacktraceLinkResult>> = {}
 ) {
   const query = {
     file: frame.filename,

+ 30 - 20
static/app/utils/queryClient.tsx

@@ -8,13 +8,16 @@ type QueryKeyEndpointOptions = {
   query?: Record<string, any>;
 };
 
-export type QueryKey =
+export type ApiQueryKey =
   | readonly [url: string]
   | readonly [url: string, options: QueryKeyEndpointOptions];
 
-interface UseQueryOptions<TQueryFnData, TError = RequestError, TData = TQueryFnData>
-  extends Omit<
-    reactQuery.UseQueryOptions<TQueryFnData, TError, TData, QueryKey>,
+export interface UseApiQueryOptions<
+  TQueryFnData,
+  TError = RequestError,
+  TData = TQueryFnData
+> extends Omit<
+    reactQuery.UseQueryOptions<TQueryFnData, TError, TData, ApiQueryKey>,
     'queryKey' | 'queryFn'
   > {
   /**
@@ -35,6 +38,15 @@ interface UseQueryOptions<TQueryFnData, TError = RequestError, TData = TQueryFnD
   staleTime: number;
 }
 
+/**
+ * TODO(epurkhiser): Remove once getsentry references are updated
+ */
+export interface UseQueryOptions<
+  TQueryFnData,
+  TError = RequestError,
+  TData = TQueryFnData
+> extends UseApiQueryOptions<TQueryFnData, TError, TData> {}
+
 // Overrides to the default react-query options.
 // See https://tanstack.com/query/v4/docs/guides/important-defaults
 const DEFAULT_QUERY_CLIENT_CONFIG: QueryClientConfig = {
@@ -47,9 +59,9 @@ const DEFAULT_QUERY_CLIENT_CONFIG: QueryClientConfig = {
 
 function isQueryFn<TQueryFnData, TError, TData>(
   queryFnOrQueryOptions?:
-    | reactQuery.QueryFunction<TQueryFnData, QueryKey>
-    | UseQueryOptions<TQueryFnData, TError, TData>
-): queryFnOrQueryOptions is reactQuery.QueryFunction<TQueryFnData, QueryKey> {
+    | reactQuery.QueryFunction<TQueryFnData, ApiQueryKey>
+    | UseApiQueryOptions<TQueryFnData, TError, TData>
+): queryFnOrQueryOptions is reactQuery.QueryFunction<TQueryFnData, ApiQueryKey> {
   return typeof queryFnOrQueryOptions === 'function';
 }
 
@@ -69,8 +81,8 @@ function isQueryFn<TQueryFnData, TError, TData>(
  * );
  */
 function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
-  queryKey: QueryKey,
-  queryOptions: UseQueryOptions<TQueryFnData, TError, TData>
+  queryKey: ApiQueryKey,
+  queryOptions: UseApiQueryOptions<TQueryFnData, TError, TData>
 ): reactQuery.UseQueryResult<TData, TError>;
 /**
  * Example usage with custom query function:
@@ -82,16 +94,16 @@ function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
  * )
  */
 function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
-  queryKey: QueryKey,
-  queryFn: reactQuery.QueryFunction<TQueryFnData, QueryKey>,
-  queryOptions?: UseQueryOptions<TQueryFnData, TError, TData>
+  queryKey: ApiQueryKey,
+  queryFn: reactQuery.QueryFunction<TQueryFnData, ApiQueryKey>,
+  queryOptions?: UseApiQueryOptions<TQueryFnData, TError, TData>
 ): reactQuery.UseQueryResult<TData, TError>;
 function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
-  queryKey: QueryKey,
+  queryKey: ApiQueryKey,
   queryFnOrQueryOptions:
-    | reactQuery.QueryFunction<TQueryFnData, QueryKey>
-    | UseQueryOptions<TQueryFnData, TError, TData>,
-  queryOptions?: UseQueryOptions<TQueryFnData, TError, TData>
+    | reactQuery.QueryFunction<TQueryFnData, ApiQueryKey>
+    | UseApiQueryOptions<TQueryFnData, TError, TData>,
+  queryOptions?: UseApiQueryOptions<TQueryFnData, TError, TData>
 ): reactQuery.UseQueryResult<TData, TError> {
   // XXX: We need to set persistInFlight to disable query cancellation on unmount.
   // The current implementation of our API client does not reject on query
@@ -101,7 +113,7 @@ function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
 
   const [path, endpointOptions] = queryKey;
 
-  const defaultQueryFn: reactQuery.QueryFunction<TQueryFnData, QueryKey> = () =>
+  const defaultQueryFn: reactQuery.QueryFunction<TQueryFnData, ApiQueryKey> = () =>
     api.requestPromise(path, {
       method: 'GET',
       query: endpointOptions?.query,
@@ -121,7 +133,5 @@ function useApiQuery<TQueryFnData, TError = RequestError, TData = TQueryFnData>(
 // eslint-disable-next-line import/export
 export * from '@tanstack/react-query';
 
-const useQuery = useApiQuery;
-
 // eslint-disable-next-line import/export
-export {DEFAULT_QUERY_CLIENT_CONFIG, useApiQuery, useQuery, UseQueryOptions};
+export {DEFAULT_QUERY_CLIENT_CONFIG, useApiQuery};

+ 3 - 3
static/app/utils/useCommitters.tsx

@@ -1,5 +1,5 @@
 import type {Committer} from 'sentry/types';
-import {QueryKey, useApiQuery, UseQueryOptions} from 'sentry/utils/queryClient';
+import {ApiQueryKey, useApiQuery, UseApiQueryOptions} from 'sentry/utils/queryClient';
 
 import useOrganization from './useOrganization';
 
@@ -16,11 +16,11 @@ const makeCommittersQueryKey = (
   orgSlug: string,
   projectSlug: string,
   eventId: string
-): QueryKey => [`/projects/${orgSlug}/${projectSlug}/events/${eventId}/committers/`];
+): ApiQueryKey => [`/projects/${orgSlug}/${projectSlug}/events/${eventId}/committers/`];
 
 function useCommitters(
   {eventId, projectSlug}: UseCommittersProps,
-  options: Partial<UseQueryOptions<CommittersResponse>> = {}
+  options: Partial<UseApiQueryOptions<CommittersResponse>> = {}
 ) {
   const org = useOrganization();
   return useApiQuery<CommittersResponse>(

+ 2 - 2
static/app/views/issueList/queries/useFetchSavedSearchesForOrg.tsx

@@ -1,5 +1,5 @@
 import {SavedSearch} from 'sentry/types';
-import {useApiQuery, UseQueryOptions} from 'sentry/utils/queryClient';
+import {useApiQuery, UseApiQueryOptions} from 'sentry/utils/queryClient';
 
 type FetchSavedSearchesForOrgParameters = {
   orgSlug: string;
@@ -14,7 +14,7 @@ export const makeFetchSavedSearchesForOrgQueryKey = ({
 
 export const useFetchSavedSearchesForOrg = (
   {orgSlug}: FetchSavedSearchesForOrgParameters,
-  options: Partial<UseQueryOptions<FetchSavedSearchesForOrgResponse>> = {}
+  options: Partial<UseApiQueryOptions<FetchSavedSearchesForOrgResponse>> = {}
 ) => {
   return useApiQuery<FetchSavedSearchesForOrgResponse>(
     makeFetchSavedSearchesForOrgQueryKey({orgSlug}),