Nuxt apollo TypeError: Cannot read property 'nodes' of undefined

39 Views Asked by At

I am using NuxtJS Vue-apollo to get GraphQL data from WordPress with CPTs.

There are several pages in NuxtJS which respectively lists posts, CPT1 and CPT2. I can display posts from all just fine, if I reload the page. However if i go from the page which lists posts to CPT1 or any other combination i get the following error TypeError: Cannot read property 'nodes' of undefined.

The first page can list the posts even if I go back, while all others get the error. The queries looks like this:

query queryPosts {
  posts {
    nodes {
      id
      title
      modified
      date
      slug
      uri
      featuredImage {
        node {
          id
          sourceUrl(size: THUMBNAIL)
          altText
        }
      }
    }
  }
}

And:

query queryCPT1 {
cpt1 {
    nodes {
      id
      title(format: RENDERED)
      uri
      problemer { <- this is an ACF field
        cardTitle
        cardImage {
          id
          sourceUrl(size: LARGE)
        }
      }
    }
  }
}

I have tried displaying the JSON data raw on the page, and that works. But if i try to specify anything inside the result JSON i get the error.

How can I fix this?

0

There are 0 best solutions below