【发布时间】:2021-04-27 06:05:54
【问题描述】:
我正在使用带有 apollo/client 的组合 api 的 vue 3。我从文档中做了所有事情,但这是我能做到的。我提供了一个正确的后端 url,只是无法弄清楚。这是我的代码,我在终端中收到警告
./node_modules/@vue/apollo-composable/dist/useQuery.js 中的警告
在浏览器控制台中我收到此错误。
Uncaught Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup.
<template>
<div class="hello">
working with graphql
</div>
</template>
<script>
import { useQuery,DefaultApolloClient } from "@vue/apollo-composable"
import { provide } from "vue"
import gql from "graphql-tag"
import {ApolloClient,createHttpLink,InMemoryCache,} from "@apollo/client/core"
const httpLink = createHttpLink({
uri: "http://localhost:3000/graphql",
})
const cache = new InMemoryCache()
const apolloClient = new ApolloClient({
link: httpLink,
cache,
})
export default {
name: "HelloWorld",
setup() {
provide(DefaultApolloClient, apolloClient)
const { result } = useQuery(gql`
query getPosts {
Post {
id
context
title}}`)
console.log(result)
},
}
</script>
【问题讨论】:
-
如果您在将 Quasar 与 Apollo 一起使用时遇到此错误,请参阅 stackoverflow.com/questions/70721226/…。
标签: node.js graphql apollo-client vuejs3 vue-apollo