Skip to content

onResult has *confusing* behavior #1593

@cndev123

Description

@cndev123

Describe the bug
The onResult hook of useQuery is called in a (for me) confusing manner. Its behavior is not documented.

// call without any non-default fetch-policy
const { onResult } = useQuery(query, ...);

onResult((...agrs) => console.log(args))

// when no result in cache and call goes to server, onResult is called twice
// 1st with no data prop, loading === true and partial == true
// 2nd with data prop, loading === false, partial === undefined

// when result in cache, onResult is only called once
// with data prop, loading === false, partial === undefined
// call without any non-default fetch-policy
const { onResult } = useQuery(query, ..., { fetchPolicy: "no-cache"});

onResult((...agrs) => console.log(args))

// onResult is only called once
// with data prop, loading  === false, partial === undefined
  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Versions
vue: 3.5.16
vue-apollo: 4.2.2
@apollo/client:3.13.8

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