Skip to content

useLazyQuery, load and refetch execute together after the first load execution with the same variable #1580

Open
@haaah

Description

@haaah

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions