reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.54k stars 1.14k forks source link

Exposing the FetchBaseQueryArgs type #4464

Closed WilsonCWong closed 2 weeks ago

WilsonCWong commented 3 weeks ago

Hello,

I recently upgraded from RTK Toolkit 1.9.7, and I noticed that because UMD build artifacts are no longer included, I could not import the FetchBaseQueryArgs like so:

import { FetchBaseQueryArgs } from '@reduxjs/toolkit/dist/query/fetchBaseQuery';

My use case for this is that I have implemented a custom version of fetchBaseQuery at my company that dynamically constructs the URL through various customizable callbacks and options to help us target different projects and environments through our microservices. It looks something like this:

export const fetchDynamicBaseQuery = (
  fetchBaseQueryArgs: FetchBaseQueryArgs,
  options?: DynamicBaseQueryOptions,
): BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, ExtraOptions> => {
  return async (args, api, extraOptions) => {
    const { baseUrl, ...rest } = fetchBaseQueryArgs;

    let finalBaseUrl = baseUrl;

    // Doing stuff here...

    const rawBaseQuery = fetchBaseQuery({ baseUrl: finalBaseUrl, ...rest });
    return rawBaseQuery(args, api, extraOptions);
  };

Would it be possible to expose this type again? Also open to alternative ways of doing this, but this approach has worked well so far.

markerikson commented 3 weeks ago

As a general rule, any time you may have been importing from /dist/ that's accessing internals and it wasn't intentionally exposed :)

That said, we currently do:

export { fetchBaseQuery } from './fetchBaseQuery'
export type {
  FetchBaseQueryError,
  FetchBaseQueryMeta,
  FetchArgs,
} from './fetchBaseQuery'

and I can't think of a reason not to export FetchBaseQueryArgs here.

File a PR to add that?

WilsonCWong commented 3 weeks ago

PR filed! 😃

EskiMojo14 commented 1 week ago

released in v2.2.6 😄

glasody commented 4 days ago

came looking for this, wasn't disappointed. Thank you!