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

[WIP] feat: update @ngneat/query to use the newest @tanstack/query version #117

Closed
wants to merge 16 commits into from

Conversation

luii
Copy link
Contributor

@luii luii commented Oct 29, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Current behavior reflects still v4 of @tanstack/react-query's api style

Issue Number: #116

What is the new behavior?

New behavior reflects v5 of @tanstack/react-query's api style

  • Added the InfiniteData Interface (exported type from @tanstack/query-core) to the InfiniteQueryService return type to reflect what is actually being returned
  • TError now defaults to DefaultError (exported type from @tanstack/query-core) instead of unknown
  • Adjusted the shipped operators to reflect changes made by tanstack
  • Refactored the playground to the newest api changes
    • Removed @ngneat/subscribe as dependency to illustrate that the code can be used without it and used *ngIf and AsyncPipe instead

Does this PR introduce a breaking change?

[x] Yes
[ ] No
  • Update the version of @tanstack/react-query, @tanstack/query-core and @tanstack/react-query-devtools to the neweset version
  • Removed all overloads with the exception of the object params, from InfiniteQueryService, QueryService

Other information

luii added 6 commits October 29, 2023 17:10
... `@tanstack/react-query-devtools` version to `5.4.3`
Adjusts Types to reflect the new `@tanstack/react-query` (in v5)

BREAKING CHANGE: 🧨 Removed all overloads with the exception of the object style, like
`@tanstack/react-query` (in v5) now requires you to

✅ Closes: 116
@stackblitz
Copy link

stackblitz bot commented Oct 29, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@luii luii changed the title [WIP]: feat: Update [WIP] feat: update @ngneat/query to use the newest @tanstack/query version Oct 29, 2023
return buildQuery(
this.instance,
InfiniteQueryObserver as typeof QueryObserver,
parsedOptions
options as any
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NetanelBasal For now i typed this as any since i dont really know how to convert between them, maybe a bit help would be great.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need multiple overloads. See for example the svelte version:
https://github.com/TanStack/query/blob/v5.4.2/packages/svelte-query/src/createQuery.ts

return buildQuery(
this.instance,
QueryObserver,
parsedOptions
options as QueryOptions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this conversion, i'd say this one is not as bad as the infinite query one but still what would you say?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhhm, i think the links got mixed up, the createQuery overloads from the svelte adapter are the same, both have the initialData defined or undefined overload. was this intentionally?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should copy the same overload and only change the queryFn and return data

Copy link
Member

@NetanelBasal NetanelBasal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I recommend to see that the types and overloads are equal to one of the existing adapters such as svelte or vue js

package.json Outdated
"@ngneat/subscribe": "^3.0.2",
"@tanstack/react-query": "^4.12.0",
"@tanstack/react-query-devtools": "^4.12.0",
"@tanstack/react-query": "^5.4.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to use the react version anymore. You can do what he did here:

https://github.com/TanStack/query/pull/6195/files#diff-d3075a62994bf33ff94f30a28f5caac8e1128726d8df1dc70ae0df7b6c209918

return buildQuery(
this.instance,
InfiniteQueryObserver as typeof QueryObserver,
parsedOptions
options as any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need multiple overloads. See for example the svelte version:
https://github.com/TanStack/query/blob/v5.4.2/packages/svelte-query/src/createQuery.ts

return buildQuery(
this.instance,
QueryObserver,
parsedOptions
options as QueryOptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NetanelBasal
Copy link
Member

@luii I already starts the refactoring. Do you want to collaborate? I'm actually writing it from scratch. Already have the base query and infinity done.

@luii
Copy link
Contributor Author

luii commented Nov 4, 2023

@NetanelBasal oh okay, i havent seen that, sorry that i havent done anything since last week, i was really busy with work. if you have something i should do/can do, then yeah of course

@NetanelBasal
Copy link
Member

The question is how much time you have? because I want to close this version in two weeks most.

@luii
Copy link
Contributor Author

luii commented Nov 4, 2023

Only this week was rough, next and the week after that should be fine, if something comes up i will let you know in advance on the end of monday

@NetanelBasal
Copy link
Member

Cool, let me see what I can give you and I'll let you know. Thanks

@NetanelBasal
Copy link
Member

Hi,

These are the new changes:

  • queryFn is the same as the original function. To work with observables you can use the toPromise function. See the services.
  • We know expose as signal and and result$ observable
  • Changed mapResults to intersectResults and make it more aligned with combineLatest signature (i.e both array and object)

Missing things that you can do:

  • Add injectIsFetching and injectIsMutating ( use the new convention, see query)
  • Mutation API
  • Docs update
  • More examples in the playground

You can work on the next branch. LMK if it's ok and you can do it.

@luii luii deleted the feature/116-tanstack-query-v5-update branch November 7, 2023 19:12
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

Successfully merging this pull request may close these issues.

2 participants