Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update dependency @rtk-query/graphql-request-base-query to v2.3.1 #555

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Jan 1, 2024

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
@rtk-query/graphql-request-base-query 2.2.0 -> 2.3.1 age adoption passing confidence

Release Notes

reduxjs/redux-toolkit (@​rtk-query/graphql-request-base-query)

v2.3.1

Compare Source

v2.3.0

Compare Source

This feature release adds a new RTK Query upsertQueryEntries util to batch-upsert cache entries more efficiently, passes through additional values for use in prepareHeaders, and exports additional TS types around query options and selectors.

Changelog

upsertQueryEntries

RTK Query already had an upsertQueryData thunk that would upsert a single cache entry. However, some users wanted to upsert many cache entries (potentially hundreds or thousands), and found that upsertQueryData had poor performance in those cases. This is because upsertQueryData runs the full async request handling sequence, including dispatching both pending and fulfilled actions, each of which run the main reducer and update store subscribers. That means there's 2N store / UI updates per item, so upserting hundreds of items becomes extremely perf-intensive.

RTK Query now includes an api.util.upsertQueryEntries action that is meant to handle the batched upsert use case more efficiently. It's a single synchronous action that accepts an array of many {endpointName, arg, value} entries to upsert. This results in a single store update, making this vastly better for performance vs many individual upsertQueryData calls.

We see this as having two main use cases. The first is prefilling the cache with data retrieved from storage on app startup (and it's worth noting that upsertQueryEntries can accept entries for many different endpoints as part of the same array).

The second is to act as a "pseudo-normalization" tool. RTK Query is not a "normalized" cache. However, there are times when you may want to prefill other cache entries with the contents of another endpoint, such as taking the results of a getPosts list endpoint response and prefilling the individual getPost(id) endpoint cache entries, so that components that reference an individual item endpoint already have that data available.

Currently, you can implement the "pseudo-normalization" approach by dispatching upsertQueryEntries in an endpoint lifecycle, like this:

const api = createApi({
  endpoints: (build) => ({
    getPosts: build.query<Post[], void>({
      query: () => '/posts',
      async onQueryStarted(_, { dispatch, queryFulfilled }) {
        const res = await queryFulfilled
        const posts = res.data

        // Pre-fill the individual post entries with the results
        // from the list endpoint query
        dispatch(
          api.util.upsertQueryEntries(
            posts.map((post) => ({
              endpointName: 'getPost',
              arg: { id: post.id },
              value: post,
            })),
          ),
        )
      },
    }),
    getPost: build.query<Post, Pick<Post, 'id'>>({
      query: (post) => `post/${post.id}`,
    }),
  }),
})

Down the road we may add a new option to query endpoints that would let you provide the mapping function and have it automatically update the corresponding entries.

For additional comparisons between upsertQueryData and upsertQueryEntries, see the upsertQueryEntries API reference.

prepareHeaders Options

The prepareHeaders callback for fetchBaseQuery now receives two additional values in the api argument:

  • arg: the URL string or FetchArgs object that was passed in to fetchBaseQuery for this endpoint
  • extraOptions: any extra options that were provided to the base query
Additional TS Types

We've added a TypedQueryStateSelector type that can be used to pre-type selectors for use with selectFromResult:

const typedSelectFromResult: TypedQueryStateSelector<
  PostsApiResponse,
  QueryArgument,
  BaseQueryFunction,
  SelectedResult
> = (state) => ({ posts: state.data?.posts ?? EMPTY_ARRAY })

function PostsList() {
  const { posts } = useGetPostsQuery(undefined, {
    selectFromResult: typedSelectFromResult,
  })
}

We've also exported several additional TS types around base queries and tag definitions.

What's Changed

Full Changelog: reduxjs/redux-toolkit@v2.2.8...v2.3.0


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot added the dependencies label Jan 1, 2024
Copy link

changeset-bot bot commented Jan 1, 2024

⚠️ No Changeset found

Latest commit: 5cd769d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from 6f77b07 to 85d1e29 Compare January 2, 2024 11:22
@renovate renovate bot changed the title chore(deps): update dependency @rtk-query/graphql-request-base-query to v2.3.0 chore(deps): update dependency @rtk-query/graphql-request-base-query to v2.3.1 Jan 2, 2024
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from 85d1e29 to 3db5401 Compare January 24, 2024 14:29
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch 2 times, most recently from 2023fe1 to 2770919 Compare February 15, 2024 01:05
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from 2770919 to 7fcf271 Compare March 21, 2024 04:46
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from 7fcf271 to 678ad22 Compare April 1, 2024 00:31
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from 678ad22 to 926ad47 Compare May 9, 2024 04:00
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from 926ad47 to caa329e Compare May 16, 2024 21:04
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from caa329e to c923503 Compare June 29, 2024 16:43
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from c923503 to 7a955b1 Compare July 27, 2024 21:18
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch 2 times, most recently from 0315d24 to c0c7eda Compare October 15, 2024 01:17
@renovate renovate bot force-pushed the renovate/rtk-query-graphql-request-base-query-2.x branch from c0c7eda to 5cd769d Compare November 29, 2024 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant