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

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

Open
mathieuCatapulpe opened this issue Mar 26, 2024 · 2 comments
Open
Labels

Comments

@mathieuCatapulpe
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v18.16.0
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.9.1
  • Package Manager: yarn@1.22.21
  • Builder: -
  • User Config: app, css, build, components, imports, modules, ssr, preset, routeRules, apollo, vite, runtimeConfig, sitemap, optimization
  • Runtime Modules: @nuxtjs/tailwindcss@6.11.4, @nuxtjs/apollo@5.0.0-alpha.13, @vueuse/nuxt@9.13.0, @pinia/nuxt@0.4.11, nuxt-swiper@1.2.2, nuxt-lodash@2.5.3, nuxt-simple-sitemap@2.7.0
  • Build Modules: -

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 :

  • trigger the graphql query onMounted()
  • use useQuery and useAsyncQuery
  • running code on prod and local server using nuxt dev
  • adding prefetch : false parameter to the query

Logs

No response

@atenazr
Copy link

atenazr commented May 10, 2024

i have this issue too!

@toknT
Copy link

toknT commented Aug 20, 2024

😭 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;
    }
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants