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

Final RTKQ alpha feedback, fixes, and tweaks #1023

Closed
markerikson opened this issue Apr 26, 2021 · 10 comments
Closed

Final RTKQ alpha feedback, fixes, and tweaks #1023

markerikson opened this issue Apr 26, 2021 · 10 comments
Milestone

Comments

@markerikson
Copy link
Collaborator

Gotta resolve any issues that get reported during the alpha, and apply any final changes left over from the old repo.

@markerikson markerikson added this to the 1.6 milestone Apr 26, 2021
@mgcrea
Copy link

mgcrea commented Apr 27, 2021

Can't wait to test RTK-Query in my new projects!

Minor note, in the changelog the import path is import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/react' when it looks like it should be import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'.

@phryneas
Copy link
Member

@mgcrea Thanks, updated it.

@markerikson
Copy link
Collaborator Author

Yeah, we need to go through and add visibility attributes to all types so we stop getting extraction warnings.

@markerikson
Copy link
Collaborator Author

Running list of merged PRs since alpha.2 for reference:

@phryneas
Copy link
Member

phryneas commented May 15, 2021

just some minor tweaks 😆

Still missing on that list:

  • feature: allow using skipSymbol as arg in hooks  #1056 allow using skipSymbol as arg in hooks
  • add a merge (or mergeWithLastResult option to endpoints)
  • add a docs page w/ an example for infinite scrolling (actually, without using merge, that's only gonna be useful in a "streaming" context)
  • add visibility attributes to all types and decide what is public and what is internal

And then I think I'm actually really out of ideas on what else to add.

@bravew
Copy link

bravew commented May 27, 2021

First of all, excellent functionalities for RTK query, start refactoring our codes by adopting alpha.2, can't wait the official release.
A quick question ,Is there any way to change baseUrl after calling createApi?
In our app we allow user to change the server address which is stored in the redux state, and will be used in following REST API call. It seems that baseUrl for RTKQ can't be modified after initialization.
Thanks!

@StefanBRas
Copy link
Contributor

@bravew : phryneas mentioned on Discord that this could be done by wrapping baseQuery, as that have access to getState. I had a similiar usecase, where i wanted to add a projectId to the url. Here is an (untested, but hopefully working) example:

import { fetchBaseQuery } from '@rtk-incubator/rtk-query';
import { createApi } from '@rtk-incubator/rtk-query/react';

const baseQuery = fetchBaseQuery({
  baseUrl: 'http://localhost:8000/'
});

const wrappedBaseQuery = (
  ...[args, api, extraOptions]: Parameters<typeof baseQuery>
) => {
  const partialUrl = typeof (args) === 'string' ? args : args.url
  const projectId = (api.getState() as any).auth.projectId // circular reference if as RootState 
  const url = `project/${projectId}/${partialUrl}`
  const newArgs = typeof (args) === 'string' ? url : { ...args, url }
  return baseQuery(newArgs, api, extraOptions)
}

export const api = createApi({
  baseQuery: wrappedBaseQuery,
...

(Note that I haven't updated to next RTK, so i'm using the old imports)

@bravew
Copy link

bravew commented May 28, 2021

@StefanBRas , Thanks a lot , your code provides the last piece of our puzzle.

@markerikson
Copy link
Collaborator Author

@Shrugsy that snippet seems worth adding to "Customizing Queries"

@markerikson
Copy link
Collaborator Author

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants