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

feat(vue-query): useQuery support ref args #5027

Conversation

aa900031
Copy link
Contributor

useMutation is support ref args already, but useQuery is not. so I set useQuery every arguments with MaybeRef just like useMutation

@vercel
Copy link

vercel bot commented Feb 23, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
query ⬜️ Ignored (Inspect) Visit Preview Sep 2, 2023 3:44pm

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 23, 2023

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 1062400:

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

@aa900031
Copy link
Contributor Author

Hi @DamianOsipiuk! Please check this PR, Welcome to discussion. Thank you.

@nx-cloud
Copy link

nx-cloud bot commented Aug 25, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 1062400. 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 2 targets

Sent with 💌 from NxCloud.

| QueryFunction<TQueryFnData, UnwrapRef<TQueryKey>>
| UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey> = {},
arg3: UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey> = {},
| MaybeRef<QueryFunction<TQueryFnData, UnwrapRef<TQueryKey>>>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if setting the type of queryFn as MaybeRef is a wise choice. One reason is that it might cause more conflicts when users upgrade to v5.

Do you have any thoughts on this?

Copy link
Contributor Author

@aa900031 aa900031 Aug 25, 2023

Choose a reason for hiding this comment

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

I agree that is not wise choice too, but currently mutationFn type is already as MaybeRef

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I check parseQueryArgs again, I've realized that it doesn't support queryFn as a MaybeRef. I'll have to remove it in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

const plainArg1 = unref(arg1)
const plainArg2 = unref(arg2)
const plainArg3 = unref(arg3)

Currently, it should be possible to support queryFn as a ref. Regarding the transition to v5, I'm not sure if I'm overthinking it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you're right !

However, I've also noticed another thing, it ensures that queryFn is a function in here:

>]: Property extends 'queryFn'
? QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
UnwrapRef<TQueryKey>
>[Property]

Since it's being handled here, should follow suit as well?

Copy link
Contributor Author

@aa900031 aa900031 Aug 26, 2023

Choose a reason for hiding this comment

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

I just noticed that the task aren't passing. I found that in src/__tests__/useQuery.test.ts at line 262, it's passing a ref to queryFn. It looks like we should reintroduce MaybeRef in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's the case, the types here might not be quite accurate, right? 🤯

>]: Property extends 'queryFn'
? QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryData,
UnwrapRef<TQueryKey>
>[Property]

It would be nice to have feedback from @DamianOsipiuk to know which is expect.

Copy link
Contributor

Choose a reason for hiding this comment

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

Although in theory queryFn is an option like any other, so it should be properly handled when it's changed to another one, I would strongly discourage it.
So if types currently do not allow it, let's leave it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DamianOsipiuk Thank you for comment, we don't change any queryFn type currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DamianOsipiuk Please merge this PR, this is important for use queryOptions as component props ex:

const Comp = defineComponent({
  props: {
    queryOptions: Object,
  },
  setup: (props) => {
    return useQuery(
      computed(() => ({
        ...props.queryOptions,
        queryFn: () => {
           // ...
        }
      }))
    )
  }
})

@codecov-commenter
Copy link

Codecov Report

Patch coverage is 100.00% of modified lines.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Files Changed Coverage
packages/vue-query/src/useInfiniteQuery.ts ø
packages/vue-query/src/useBaseQuery.ts 100.00%
packages/vue-query/src/useQuery.ts 100.00%

📢 Thoughts on this report? Let us know!.

@DamianOsipiuk DamianOsipiuk merged commit d11280e into TanStack:main Sep 7, 2023
7 checks passed
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.

5 participants