Skip to content

Commit 651aa1a

Browse files
committed
Add TableOfContents.vue with first query
1 parent 1eb0883 commit 651aa1a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

Diff for: src/App.vue

+6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
<template>
22
<img alt="Vue logo" src="./assets/logo.png" />
33
<h1>The GraphQL Guide</h1>
4+
<TableOfContents />
45
</template>
56

67
<script>
78
import { ApolloClient, InMemoryCache } from '@apollo/client/core'
89
import { DefaultApolloClient } from '@vue/apollo-composable'
910
import { provide } from 'vue'
1011
12+
import TableOfContents from './components/TableOfContents.vue'
13+
1114
const client = new ApolloClient({
1215
uri: 'https://api.graphql.guide/graphql',
1316
cache: new InMemoryCache()
1417
})
1518
1619
export default {
1720
name: 'App',
21+
components: {
22+
TableOfContents
23+
},
1824
setup() {
1925
provide(DefaultApolloClient, client)
2026
}

Diff for: src/components/TableOfContents.vue

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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>

0 commit comments

Comments
 (0)