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

useLazyQuery, load hook and refetch hook will execute together after the initial load hook was executed and second execution with the same variable #12137

Closed
haaah opened this issue Nov 18, 2024 · 5 comments

Comments

@haaah
Copy link

haaah commented Nov 18, 2024

Issue Description

The code is in vue.js.

I have created a composition function of car.

const {
    load: loadCarByPk,
    onResult: onResultCarByPk,
    onError: onErrorCarByPk,
    refetch: refetchCarByPk,
  } = useLazyQuery(CAR_BY_PK_DOCUMENT)

Created a button which execute the composite function. the input value is 1.

function onClickFire2() {
  let result = loadCarByPk(undefined, { id: inputId.value })

  console.log("loadCarByPk, result -> ", result)
  if (!result) {
    console.log("refetch")
    refetchCarByPk({ idList: inputId.value })
  }
}

Following is my onResult

onResultCarByPk((result) => {
  const { loading, data } = result
  if (!loading) {
    console.log("data -> ", data.car_by_pk)
  }
})

Link to Reproduction

Reproduction Steps

  1. Click on the button to trigger function. The following is my console.log()
loadCarByPk, result ->  Promise {<pending>}
data ->  {__typename: 'car', id: 1, name: 'Impreza WRX'}
  1. Click on the button second time to trigger the function again. The following is my console.log()
loadCarByPk, result ->  false
refetch
data ->  {__typename: 'car', id: 1, name: 'Impreza WRX'}
data ->  {__typename: 'car', id: 1, name: 'Impreza WRX'}

Expected behavior
By looking at the document
useLazyQuery

My expected behavior is that on the second time when I click the button, useLazyQuery return a false and we should only execute the refetch() as per the document

function fetchOrRefetch () {
  load() || refetch()
}

@apollo/client version

3.11.10

@haaah
Copy link
Author

haaah commented Nov 18, 2024

Although the code is in vue.js but I think the issues is within the load() hook, on second execution of the useLazyQuery() with the same variable if the load hook return false it shouldn't continue to execute the query and just let refetch hook do.

@phryneas
Copy link
Member

I'm sorry, but you might be in the wrong repo - this is the Apollo Client core.
While that is used by the hooks, I believe the hooks add quite a lot of logic around it, so you might want to talk to the Apollo Client Vue maintainers first.
Especially something like "the return value of load" does not seem like a concept we have in AC core.

@haaah
Copy link
Author

haaah commented Nov 26, 2024

thanks for pointing out. Will close the issue.

@haaah haaah closed this as completed Nov 26, 2024
Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using our Community Forum or Stack Overflow.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants