Skip to content

Commit 98a679a

Browse files
committed
More docs
1 parent 02a2d04 commit 98a679a

File tree

10 files changed

+517
-83
lines changed

10 files changed

+517
-83
lines changed

docs/.vuepress/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ themeConfig:
2525
- /guide/persist/
2626
- /guide/push/
2727
- /guide/destroy/
28+
- /guide/custom-mutations/
2829
- /guide/relationships/
2930
- /guide/eager-loading/
30-
- /guide/skipping-fields/
31+
- /guide/virtual-fields/
3132
- /guide/meta-fields/

docs/guide/README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,38 @@ The following table lists all actions and what they do:
2323

2424
CRUD | Vuex Only | Persist to GraphQL API
2525
--| -- | --
26-
**R**EAD | getters['find'] & getters['findAll'] | dispatch('fetch')
27-
**C**REATE | dispatch('create') | dispatch('persist')
28-
**U**PDATE | dispatch('save') | dispatch('push')
29-
**D**ELETE | dispatch('delete') | dispatch('destroy')
26+
**R**EAD | getters['find'] & getters['findAll'] | [dispatch('fetch')](/guide/fetch)
27+
**C**REATE | dispatch('create') | [dispatch('persist')](/guide/persist)
28+
**U**PDATE | dispatch('save') | [dispatch('push')](/guide/push)
29+
**D**ELETE | dispatch('delete') | [dispatch('destroy')](/guide/destroy)
3030

3131
See the example below to get an idea of how this plugin interacts with Vuex-ORM.
3232

3333

34+
35+
3436
## Example usage
3537

3638
After [installing](/guide/setup) this plugin you can load data in your component:
3739

3840
```vue
3941
<template>
40-
<ul>
41-
<li v-for="user in users" :key="user.name">{{user.name}}</li>
42-
</ul>
42+
<ul>
43+
<li v-for="user in users" :key="user.name">{{user.name}}</li>
44+
</ul>
4345
</template>
4446
4547
4648
<script>
47-
export default {
48-
computed: {
49-
users: () => store.getters['entities/users/all']()
50-
},
51-
52-
created() {
53-
this.$store.dispatch('entities/users/fetch');
54-
}
49+
export default {
50+
computed: {
51+
users: () => store.getters['entities/users/all']()
52+
},
53+
54+
created() {
55+
this.$store.dispatch('entities/users/fetch');
5556
}
57+
}
5658
</script>
5759
```
5860

docs/guide/custom-mutations/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Custom Mutations
2+
3+
[[toc]]
4+
5+
6+
Along with the CRUD mutations you may want to send custom GraphQL mutations. We support this via the `mutate` action:
7+
8+
```javascript
9+
Post.dispatch('mutate', { mutation: 'upvotePost', id: post.id });
10+
```
11+
12+
As you can see you have to privide the mutation name and any further arguments you want to pass. In this case we send
13+
the post id, but this could be anything. This generates the following query:
14+
15+
16+
```graphql
17+
mutation UpvotePost($id: ID!) {
18+
upvotePost(post: $id) {
19+
id
20+
userId
21+
content
22+
title
23+
24+
user {
25+
id
26+
email
27+
}
28+
}
29+
}
30+
```
31+
32+
Variables:
33+
34+
```json
35+
{
36+
"id": 42
37+
}
38+
```
39+
40+
Like for all other operations, all records which are returned replace the respective existing records in the Vuex-ORM
41+
database.
42+
43+
44+
::: danger
45+
**TODO**
46+
47+
- Example code
48+
:::

docs/guide/destroy/README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@
22

33
[[toc]]
44

5+
Last thing you can do with a record is to delete it on the server after deleting (`delete` action) it on the client via
6+
Vuex-ORM. For this use case we have the `destroy` action.
7+
8+
Via calling
9+
10+
```javascript
11+
Post.dispatch('destroy', { id: post.id });
12+
```
13+
14+
the following GraphQL query is generated:
15+
16+
17+
```graphql
18+
mutation DeletePost($id: ID!) {
19+
deletePost(id: $id) {
20+
id
21+
}
22+
}
23+
```
24+
25+
Variables:
26+
27+
```json
28+
{
29+
"id": 42
30+
}
31+
```
32+
33+
534
::: danger
6-
TODO
35+
**TODO**
36+
37+
- Example code
738
:::
39+

docs/guide/fetch/README.md

Lines changed: 73 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,30 @@ This produces the following GraphQL query:
1313

1414
```graphql
1515
query 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:
4549
const 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 });
5871
This 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

docs/guide/persist/README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,57 @@
22

33
[[toc]]
44

5+
6+
After creating a new record via Vuex-ORM you may want to save it to your server via GraphQL. For this use case we have
7+
the `persist` action.
8+
9+
Via calling
10+
11+
```javascript
12+
Post.dispatch('persist', { id: post.id });
13+
```
14+
15+
the post record is send to the GraphQL by generating the following query:
16+
17+
18+
```graphql
19+
mutation CreatePost($post: PostInput!) {
20+
createPost(post: $post) {
21+
id
22+
userId
23+
content
24+
title
25+
26+
user {
27+
id
28+
email
29+
}
30+
}
31+
}
32+
```
33+
34+
Variables:
35+
36+
```json
37+
{
38+
"post": {
39+
"id": 42,
40+
"userId": 15,
41+
"content": "Lorem Ipsum dolor sit amet",
42+
"title": "Example Post",
43+
"user": {
44+
"id": 15,
45+
"email": "[email protected]"
46+
}
47+
}
48+
}
49+
```
50+
51+
Like when pushing, all records which are returned replace the respective existing records in the Vuex-ORM database.
52+
53+
554
::: danger
6-
TODO
55+
**TODO**
56+
57+
- Example code
758
:::

0 commit comments

Comments
 (0)