Vue Apollo 4不返回graphql查询结果

时间:2020-07-13 13:35:39

标签: vue.js graphql apollo-client quasar-framework vue-apollo

为了与version 4所示的组合api配合使用Vue阿波罗this tutorial,我们似乎无法从标准graphql查询中获得任何结果。

设置的一部分:

// src/boot/apollo.ts
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import { ApolloClient } from 'apollo-client'
import { DefaultApolloClient } from '@vue/apollo-composable'
import { provide } from '@vue/composition-api'

const httpLink = createHttpLink({ uri: "http://localhost:5000/graphql", })
const cache = new InMemoryCache()
const apolloClient = new ApolloClient({ link: httpLink, cache, })

export default ({ app }) => {
  app.setup = () => { provide(DefaultApolloClient, apolloClient) }
}

现在尝试使用一个完全有效的查询,该查询的确会在graphql游乐场中返回结果,而undefined则返回allAcounts

// src/pages/Index.vue
<template>
  <q-page padding>
    <h2 v-if="loading">Loading...</h2>
    <h4 v-else>Done loading</h4>
    <div v-for="account in allAccounts" :key="account.accountIdentifier">
      {{ account.accountIdentifier }}
    </div>
  </q-page>
</template>

<script lang="ts">
import { defineComponent, watch } from '@vue/composition-api'
import { useQuery, useResult } from '@vue/apollo-composable'
import gql from 'graphql-tag'

export default defineComponent({
  setup() {
    const allAccountsQuery = gql`
      query allAccounts {
        accounts {
          accountIdentifier
        }
      }
    `
    const { result, loading } = useQuery(allAccountsQuery)
    console.log('loading ', loading) // false
    console.log('result ', result)   // undefined
    const allAccounts = useResult(result)

    return { onClick, profile, allAccounts, loading }
  },
})
</script>

它仅返回Done loading,但不返回单个帐户。尽管可以通过graphql游乐场正确看到内容:

enter image description here

1 个答案:

答案 0 :(得分:0)

显然,这是一个known issue,其vue-apollo 4与高于"@vue/composition-api": "0.5.0"的任何版本都不兼容。因此,降级可以暂时解决此问题,直到vue-apollo 4将合并fix

yarn add @vue/composition-api@0.5.0