Feature/query options #5153
No description provided.
- 1
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit 07d6aa921c6c75458b21def05cee3dcd4af8331d:
Sandbox Source @tanstack/query-example-react-basic-typescript Configuration @tanstack/query-example-solid-basic-typescript Configuration @tanstack/query-example-svelte-basic Configuration @tanstack/query-example-vue-basic Configuration TkDodo reviewed
packages/react-query/src/useQuery.ts lines 11 to 31@@ -9,0 +10,21 @@10+export function queryOptions<11+ TQueryFnData = unknown,12+ TError = unknown,13+ TData = TQueryFnData,14+ TQueryKey extends QueryKey = QueryKey,15+>(16+ options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,17+): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>18+19+export function queryOptions<20+ TQueryFnData = unknown,21+ TError = unknown,22+ TData = TQueryFnData,23+ TQueryKey extends QueryKey = QueryKey,24+>(25+ options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,26+): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>27+28+export function queryOptions(options: unknown) {29+ return options30+}should we move this to the core, @DamianOsipiuk ?
The options are currently based on
UseQueryOptions, which only exists in react-query. I think each lib has their own impl overQueryObserverOptions🤔Yeah this would not work as in
Vuewe have to wrap every option as a possiblerefhttps://github.com/TanStack/query/blob/alpha/packages/vue-query/src/useQuery.ts#L16okay then let's let every framework export their own
queryOptions?Yes, i think that would be necessary.
Codecov Report#
Patch coverage has no change and project coverage change:
-0.23:warning:Comparison is base (
020645e) 90.83% compared to head (9c7123f) 90.60%.:exclamation: Current head 9c7123f differs from pull request most recent head 07d6aa9. Consider uploading reports for the commit 07d6aa9 to get more accurate results
:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more
Additional details and impacted files
@@ Coverage Diff @@ ## alpha #5153 +/- ## ========================================== - Coverage 90.83% 90.60% -0.23% ========================================== Files 29 29 Lines 807 809 +2 Branches 274 274 ========================================== Hits 733 733 - Misses 70 72 +2 Partials 4 4Impacted Files Coverage Δ packages/react-query/src/useQuery.ts 50.00% <0.00%> (-50.00%):arrow_down: :umbrella: View full report in Codecov by Sentry. :loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
- packages/react-query/src/useQuery.ts line 12@@ -7,3 +7,5 @@77 } from './types'88 import { useBaseQuery } from './useBaseQuery'9910+export function queryOptions<11+ TQueryFnData = unknown,
Since this is
queryspecific, we would need similar helper forinfinite,mutationandqueries?probably not necessary for mutations, but for infinite: yes
We don't even have the initialData overload for infiniteQuery 😅
I would add a separate helper in a follow-up. This is not breaking so we can add it at any time I think
☁️ Nx Cloud Report#
CI is running/has finished running commands for commit 2830d11be8994138453b31a7c9c66061102865a2. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this branch
🟥 Failed Commands nx run-many --target=test:lib --parallel=5✅ Successfully ran 4 targets nx run-many --target=test:lib --parallel=5nx run-many --target=test:eslint --parallel=5nx run-many --target=test:build --projects=rootnx run-many --target=test:types --parallel=5
Sent with 💌 from NxCloud.
☁️ Nx Cloud Report#
CI is running/has finished running commands for commit 07d6aa921c6c75458b21def05cee3dcd4af8331d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this branch
✅ Successfully ran 1 target
Sent with 💌 from NxCloud.
from testing this, it seems like
queryOptionsneeds to take the return type ofselectinto account?eg
export function fetchConfigOverridesQueryOptions(hostId: string, { suspense } = { suspense: false }) { return queryOptions({ queryKey: hostQueryKeys.configOverrides(hostId), queryFn: () => Hosts.getConfigOverrides(hostId), suspense, select: mapOverridesToForm, }); }where
export function mapOverridesToForm({ data: { overrides } }: Successful<Hosts.HostConfigOverrideResult>): FormData {means that I get this error with a vendorized version of this PR:
Type 'UndefinedInitialDataOptions<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, unknown, FormData, (string | readonly [...string[], "detail", string])[]>' is not assignable to type 'UseQueryOptionsForUseQueries<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, Error, { data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, (string | readonly [......[]])[]>'. Type 'UndefinedInitialDataOptions<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, unknown, FormData, (string | readonly [...string[], "detail", string])[]>' is not assignable to type 'Omit<UseQueryOptions<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, Error, { data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, (string | readonly [......[]])[]>, "placeholderData">'. Types of property 'refetchInterval' are incompatible. Type 'number | false | ((data: FormData | undefined, query: Query<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, unknown, { ...; }, (string | readonly [......[]])[]>) => number | false) | undefined' is not assignable to type 'number | false | ((data: { data: HostConfigOverrideResult; metadata?: Metadata | undefined; } | undefined, query: Query<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, Error, { ...; }, (string | readonly [......[]])[]>) => number | false) | undefined'. Type '(data: FormData | undefined, query: Query<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, unknown, { data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, (string | readonly [......[]])[]>) => number | false' is not assignable to type 'number | false | ((data: { data: HostConfigOverrideResult; metadata?: Metadata | undefined; } | undefined, query: Query<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, Error, { ...; }, (string | readonly [......[]])[]>) => number | false) | undefined'. Type '(data: FormData | undefined, query: Query<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, unknown, { data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, (string | readonly [......[]])[]>) => number | false' is not assignable to type '(data: { data: HostConfigOverrideResult; metadata?: Metadata | undefined; } | undefined, query: Query<{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }, Error, { ...; }, (string | readonly [......[]])[]>) => number | false'. Types of parameters 'data' and 'data' are incompatible. Type '{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; } | undefined' is not assignable to type 'FormData | undefined'. Type '{ data: HostConfigOverrideResult; metadata?: Metadata | undefined; }' is missing the following properties from type 'FormData': lighthouse, listen, tun, loggiThough this is only when passed to
useQueries!if I pass the configs inline,
const [{ data: savedData, isPending }, { data: featureFlags }] = useQueries({ queries: [ { queryKey: hostQueryKeys.configOverrides(hostId), queryFn: () => Hosts.getConfigOverrides(hostId), suspense: true, select: mapOverridesToForm, }, { queryKey: orgQueryKeys.featureFlags(), suspense: true, queryFn: ({ signal }) => Org.getFeatureFlags({ signal }), // 10 minutes staleTime: 600000, }, ], });they typecheck, except
signalis untypedhmm yeah, seems to be an issue with useQueries typings. can you file an issue?
made the issue, thx: https://github.com/TanStack/query/issues/5342
TkDodo merged this0e3f15b
TkDodo closed this
is the resolution for "useQueries" with this PR still tbd?
my issue got closed - idk whether there's plans to fix the useQueries types?
it's labelled as a known limitation
well, the second type error is covered by that, but the first problem in https://github.com/TanStack/query/pull/5153#issuecomment-1522517570 is that the output of the queryOptions function doesn't typecheck to useQueries. I'll wait to file an issue til I can try the prereleased version instead of my copy of this PR though.
Sign in to join this conversation.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment