nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
955 stars 198 forks source link

Can't access result.value after successful query on first load #606

Open mathieuCatapulpe opened 8 months ago

mathieuCatapulpe commented 8 months ago

Environment

Describe the bug

After a successful query using either useAsyncQuery or useQuery I can console.log my result, but when trying to access result.value it returns null as shown in the example bellow

import fetchProgramme from "~/config/graphql/preview/programme.graphql"
    const { result } = useQuery(
        fetchProgramme ,
        {id: previewId},
    );

    console.log('result : ' , result)
    console.log('result.value : ' , result.value)

image

Expected behaviour

Being able to access result.value

Reproduction

No response

Additional context

Also tried :

Logs

No response

atenazr commented 6 months ago

i have this issue too!

toknT commented 3 months ago

:sob: same issue any update? Because useQuery fire onResult twice after refreshed page. You can edit like this

const pageSize = 11;
const page = ref(1)
const tableData = ref<PaginatedSystemSetting>(emptyPaginatedSystemSetting)
const { data, status } = await useLazyAsyncData(async () => {
  await handleCurrentPageChange(1);
})
const handleCurrentPageChange = async (val: number) => {
  page.value = val;
  useQuery<{ data: PaginatedSystemSetting }>(findAllQuery, {
    input: { page: page.value, perPage: pageSize },
  }, {
    fetchPolicy: 'network-only',
    prefetch: false,
  }).onResult((value) => {
    if (value.loading == false) {
      tableData.value = value.data.data;
    }
  });
}