Skip to content

Commit

Permalink
feat: remove automatically inspect primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoliao666 committed Oct 12, 2023
1 parent 400d7f8 commit ba16dc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/createBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,12 @@ type QueryBaseHookOptions = Omit<
variables?: any
}

const existedPrimaryKeys = new Set<string>()

export const createBaseQuery = (
defaultOptions: any,
useRQHook: (options: any, queryClient?: any) => any,
overrideOptions?: QueryBaseHookOptions
): any => {
const {
primaryKey,
queryFn,
queryKeyHashFn,
getPreviousPageParam,
getNextPageParam,
initialPageParam,
} = defaultOptions as CreateBaseQueryOptions

if (process.env.NODE_ENV !== 'production') {
if (existedPrimaryKeys.has(primaryKey)) {
console.error(`[Bug] Duplicated primaryKey: ${primaryKey}`)
} else {
existedPrimaryKeys.add(primaryKey)
}

// @ts-ignore
if (defaultOptions.useDefaultOptions) {
console.error(
Expand All @@ -52,6 +35,15 @@ export const createBaseQuery = (
}
}

const {
primaryKey,
queryFn,
queryKeyHashFn,
getPreviousPageParam,
getNextPageParam,
initialPageParam,
} = defaultOptions as CreateBaseQueryOptions

const getPrimaryKey = () => primaryKey

const getKey = (variables?: any) => getQueryKey(primaryKey, variables)
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const suspenseOptions = {
enabled: true,
suspense: true,
throwOnError: true,
// Compatible with ReactQuery v4
useErrorBoundary: true,
}

Expand Down

0 comments on commit ba16dc2

Please sign in to comment.