0

I am frontend developer so for the first time I got my hands on vue and graphql, I don’t know how exactly to deal with this error:

Missing getMovies attribute on result {movies: Array(20)}

Here is my code, and I can see the data is fetched successfully in the response on dev tools in chrome:

{"data":{"movies":[{"__typename":"Movie","id":11,"overview":

Here is the code:

<template>
  <div class="hello">
    <ul>
      <li v-for="movie in movies" :key="movie.id">{{movie.title}}</li>
    </ul>
  </div>
</template>

<script>
import gql from 'graphql-tag'
export default {
  name: 'HelloWorld',
  data(){
    return {
      movies: []
    }
  },
  apollo: {
    getMovies: {
      query: gql`
        query StarWars {
          movies(query: "Star Wars") {
            title
            overview
            poster_path
            id
          }
        }      
      `,
      result({data}){
        this.movies = data.movies
      }
    }
  },
  props: {
    msg: String
  }
}
</script>
Mario Ramos García
  • 755
  • 3
  • 8
  • 20

1 Answers1

0

Per this issue, your apollo property should have a matching data property, but in this case they are mismatched (one is named movies and getMovies). Change one or the other:

export default {
  name: 'HelloWorld',
  data(){
    return {
      movies: []
    }
  },
  apollo: {
    movies: {
      query: gql`
        query StarWars {
          movies(query: "Star Wars") {
            title
            overview
            poster_path
            id
          }
        }      
      `
    }
  },
  props: {
    msg: String
  }
}

Setting the data yourself inside result isn't necessary.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183