Missing movies attribute on result Vue GraphQL

倖福魔咒の 提交于 2021-02-11 12:37:47

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/56723183/missing-movies-attribute-on-result-vue-graphql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!