File tree 2 files changed +47
-0
lines changed
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<img alt =" Vue logo" src =" ./assets/logo.png" />
3
3
<h1 >The GraphQL Guide</h1 >
4
+ <TableOfContents />
4
5
</template >
5
6
6
7
<script >
7
8
import { ApolloClient , InMemoryCache } from ' @apollo/client/core'
8
9
import { DefaultApolloClient } from ' @vue/apollo-composable'
9
10
import { provide } from ' vue'
10
11
12
+ import TableOfContents from ' ./components/TableOfContents.vue'
13
+
11
14
const client = new ApolloClient ({
12
15
uri: ' https://api.graphql.guide/graphql' ,
13
16
cache: new InMemoryCache ()
14
17
})
15
18
16
19
export default {
17
20
name: ' App' ,
21
+ components: {
22
+ TableOfContents
23
+ },
18
24
setup () {
19
25
provide (DefaultApolloClient, client)
20
26
}
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div v-if =" loading" >Loading...</div >
3
+
4
+ <div v-else-if =" error" >Error: {{ error.message }}</div >
5
+
6
+ <ul >
7
+ <li v-for =" chapter of chapters" :key =" chapter.id" >
8
+ {{
9
+ chapter.number ? `${chapter.number}. ${chapter.title}` : chapter.title
10
+ }}
11
+ </li >
12
+ </ul >
13
+ </template >
14
+
15
+ <script >
16
+ import { gql } from ' @apollo/client/core'
17
+ import { useQuery , useResult } from ' @vue/apollo-composable'
18
+
19
+ export default {
20
+ name: ' TableOfContents' ,
21
+ setup () {
22
+ const { result , loading , error } = useQuery (gql `
23
+ query ChapterList {
24
+ chapters {
25
+ id
26
+ number
27
+ title
28
+ }
29
+ }
30
+ ` )
31
+
32
+ const chapters = useResult (result, [])
33
+
34
+ return {
35
+ loading,
36
+ error,
37
+ chapters
38
+ }
39
+ }
40
+ }
41
+ </script >
You can’t perform that action at this time.
0 commit comments