@@ -13,26 +13,30 @@ This produces the following GraphQL query:
1313
1414``` graphql
1515query Comments {
16- comments {
16+ comments {
17+ nodes {
18+ id
19+ content
20+ postId
21+ userId
22+
23+ user {
1724 id
18- content
25+ email
26+ }
1927
28+ post {
29+ id
30+ content
31+ title
32+
2033 user {
21- id
22- email
23- }
24-
25- post {
26- id
27- content
28- title
29-
30- user {
31- id
32- email
33- }
34+ id
35+ email
3436 }
37+ }
3538 }
39+ }
3640}
3741```
3842
@@ -45,6 +49,15 @@ So using the regular Vuex-ORM getters should work out of the box now:
4549const comments = Comment .getters (' all' );
4650```
4751
52+ When fetching all returned records replace the respective existing records in the Vuex-ORM database.
53+
54+
55+ ## Fetching single record
56+
57+ ::: danger
58+ TODO
59+ :::
60+
4861
4962
5063## Filtering
@@ -58,27 +71,31 @@ Comment.dispatch('fetch', { postId: 15, deleted: false });
5871This will generate the following GraphQL query:
5972
6073``` graphql
61- query Comments ($postId : !ID , $deleted : !Boolean ) {
62- comments (filter : { postId : $postId , deleted : $deleted }) {
74+ query Comments ($postId : ID ! , $deleted : Boolean ! ) {
75+ comments (filter : { postId : $postId , deleted : $deleted }) {
76+ nodes {
77+ id
78+ content
79+ postId
80+ userId
81+
82+ user {
83+ id
84+ email
85+ }
86+
87+ post {
6388 id
6489 content
65-
90+ title
91+
6692 user {
67- id
68- email
69- }
70-
71- post {
72- id
73- content
74- title
75-
76- user {
77- id
78- email
79- }
93+ id
94+ email
8095 }
96+ }
8197 }
98+ }
8299}
83100```
84101
@@ -91,36 +108,36 @@ recommend the usage of async/await.
91108``` vue
92109<template>
93110 <div class="post" v-if="post">
94- <h1>{{ post.title }}</h1>
95- <p>{{ post.body }}</p>
111+ <h1>{{ post.title }}</h1>
112+ <p>{{ post.body }}</p>
96113 </div>
97114</template>
98115
99116<script>
100- export default {
101- // Use a computed property for the component state to keep it reactive
102- computed: {
103- post: () => Post.getters('find')(1)
104- },
105-
106- created () {
107- // fetch the data when the view is created and the data is
108- // already being observed
109- this.fetchData();
110- },
111-
112- watch: {
113- // call again the method if the route changes
114- '$route': 'fetchData'
115- },
116-
117- methods: {
118- // Loads the data from the server and stores them in the Vuex Store.
119- async fetchData () {
120- await Post.dispatch('fetch', { id: this.$route.params.id });
121- }
122- }
117+ export default {
118+ // Use a computed property for the component state to keep it reactive
119+ computed: {
120+ post: () => Post.getters('find')(1)
121+ },
122+
123+ created () {
124+ // fetch the data when the view is created and the data is
125+ // already being observed
126+ this.fetchData();
127+ },
128+
129+ watch: {
130+ // call again the method if the route changes
131+ '$route': 'fetchData'
132+ },
133+
134+ methods: {
135+ // Loads the data from the server and stores them in the Vuex Store.
136+ async fetchData () {
137+ await Post.dispatch('fetch', { id: this.$route.params.id });
138+ }
123139 }
140+ }
124141</script>
125142```
126143
0 commit comments