@@ -26,31 +26,32 @@ npm install @vue3-apollo/core @apollo/client graphql
2626### 1. Create an Apollo Client
2727
2828``` ts
29- import { ApolloClient , InMemoryCache , HttpLink } from ' @apollo/client/core'
29+ import { ApolloClient , HttpLink , InMemoryCache } from ' @apollo/client/core'
3030
3131export const defaultClient = new ApolloClient ({
32- cache: new InMemoryCache (),
33- link: new HttpLink ({
32+ cache: new InMemoryCache (),
33+ link: new HttpLink ({
3434 // Example public GraphQL API
35- uri: ' https://graphqlplaceholder.vercel.app/graphql' ,
36- }),
35+ uri: ' https://graphqlplaceholder.vercel.app/graphql' ,
36+ }),
3737})
3838```
3939
4040### 2. Register the Plugin
4141
4242``` ts
43- import { createApp } from ' vue'
4443import { apolloPlugin } from ' @vue3-apollo/core'
45- import { defaultClient , analyticsClient } from ' ./apollo-clients'
44+ import { createApp } from ' vue'
45+
46+ import { analyticsClient , defaultClient } from ' ./apollo-clients'
4647
4748const app = createApp (App )
4849
4950app .use (apolloPlugin , {
50- clients: {
51- default: defaultClient ,
52- analytics: analyticsClient ,
53- },
51+ clients: {
52+ analytics: analyticsClient ,
53+ default: defaultClient ,
54+ },
5455})
5556```
5657
@@ -73,12 +74,16 @@ const GET_POSTS = gql`
7374 }
7475`
7576
76- const { result , loading, error } = useQuery(GET_POSTS)
77+ const { error , loading, result } = useQuery(GET_POSTS)
7778</script>
7879
7980<template>
80- <div v-if="loading">Loading...</div>
81- <div v-else-if="error">{{ error.message }}</div>
81+ <div v-if="loading">
82+ Loading...
83+ </div>
84+ <div v-else-if="error">
85+ {{ error.message }}
86+ </div>
8287 <ul v-else>
8388 <li v-for="post in result.posts" :key="post.id">
8489 <strong>{{ post.title }}</strong> — {{ post.body }}
@@ -108,7 +113,7 @@ You can register and switch between multiple clients:
108113
109114``` ts
110115const { result : analyticsData } = useQuery (ANALYTICS_QUERY , null , {
111- clientId: ' analytics' ,
116+ clientId: ' analytics' ,
112117})
113118```
114119
@@ -117,7 +122,7 @@ const { result: analyticsData } = useQuery(ANALYTICS_QUERY, null, {
117122All composables are fully typed, providing autocompletion and inference for query variables and responses.
118123
119124``` ts
120- const { result } = useQuery <{ posts: { id: string ; title: string }[] }>(GET_POSTS )
125+ const { result } = useQuery <{ posts: { id: string , title: string }[] }>(GET_POSTS )
121126```
122127
123128## 🧑💻 Contributing
@@ -141,4 +146,4 @@ pnpm dev:docs
141146- 🌐 [ Documentation] ( https://vue3-apollo.guen.dev/ )
142147- 💾 [ GitHub Repository] ( https://github.com/guendev/vue3-apollo )
143148- 📦 [ npm - @vue3-apollo/core ] ( https://www.npmjs.com/package/@vue3-apollo/core )
144- - 🧱 [ Nuxt Integration - @vue3-apollo/nuxt ] ( https://www.npmjs.com/package/@vue3-apollo/nuxt )
149+ - 🧱 [ Nuxt Integration - @vue3-apollo/nuxt ] ( https://www.npmjs.com/package/@vue3-apollo/nuxt )
0 commit comments