I am using vue 3 with composition api with apollo/client . I did everything from documentation but this is as far I could go.I provied a correct backend url and just cant figure it out.This is my code and I get a warning in the terminal
warning in ./node_modules/@vue/apollo-composable/dist/useQuery.js
and in the browser console I am getting this error.
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>