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 and refetch execute together after the first load execution with the same variable #1580

Open
haaah opened this issue Nov 6, 2024 · 2 comments

Comments

@haaah
Copy link

haaah commented Nov 6, 2024

Describe the bug
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)
  }
})

To Reproduce
Steps to reproduce the behavior:

  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 execute the refetch() as per the document

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

Versions
"vue": "^3.5.12",
"@vue/apollo-composable": "4.2.1",
"@apollo/client": "^3.11.8",

Additional context
Add any other context about the problem here.

@haaah
Copy link
Author

haaah commented Nov 13, 2024

I'm thinking that this issues should belongs to "@apollo/client" more than "@vue/apollo-composable"? since the issues lies on how the useLazyQuery() treat the second execution.

@haaah
Copy link
Author

haaah commented Nov 26, 2024

Apollo Client Issue
I have raised the same issue at apollo client but someone hinted that "return value from load hook" is not a core concept within apollo client.

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

1 participant