Skip to content

Commit d26ca9d

Browse files
committed
Docs
1 parent 580eec7 commit d26ca9d

File tree

16 files changed

+197
-128
lines changed

16 files changed

+197
-128
lines changed

README.md

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -8,136 +8,12 @@ This [Vuex-ORM](https://github.com/vuex-orm/vuex-orm) plugin uses the
88
[apollo-client](https://www.apollographql.com/client/) to let you sync your Vuex state with
99
a [GraphQL API](http://graphql.org/)
1010

11-
**Warning:** This is a early version of the plugin, use with care.
12-
1311

1412
## Documentation
1513

1614
https://vuex-orm.github.io/vuex-orm-apollo/
1715

1816

19-
## Usage
20-
21-
```bash
22-
$ yarn add @vuex-orm/plugin-apollo
23-
```
24-
25-
or
26-
27-
```bash
28-
$ npm install --save @vuex-orm/plugin-apollo
29-
```
30-
31-
Add this after registering your models to the database:
32-
33-
```javascript
34-
import installVuexORMApollo from '@vuex-orm/plugin-apollo';
35-
VuexORM.use(installVuexORMApollo, { database: database });
36-
```
37-
38-
In your component:
39-
40-
```vue
41-
<template>
42-
<ul>
43-
<li v-for="user in users" :key="user.name">{{user.name}}</li>
44-
</ul>
45-
</template>
46-
47-
48-
<script>
49-
export default {
50-
computed: {
51-
users: () => store.getters['entities/users/all']()
52-
},
53-
54-
created() {
55-
this.$store.dispatch('entities/users/fetch');
56-
}
57-
}
58-
</script>
59-
```
60-
61-
62-
## Possible options:
63-
64-
- `database` (required): The Vuex-ORM database.
65-
- `url` (optional, default: '/graphql'): The URL to the graphql api. Will be passed to apollo-client.
66-
- `debug` (optional, default: false): Set to true to activate the debug logging.
67-
68-
69-
## API
70-
71-
While using Vuex-ORM you have to distinct between two types of operations:
72-
73-
- Vuex operations: Retrieve or save data from or to Vuex
74-
- Persistence operations: Load or persist data from Vuex to the GraphQL API
75-
76-
The following table lists all operations you can use and what they to:
77-
78-
CRUD | Vuex Only | Persist to GraphQL API
79-
--| -- | --
80-
**R**EAD | getters['find'] & getters['findAll'] | dispatch('fetch')
81-
**C**REATE | dispatch('create') | dispatch('persist')
82-
**U**PDATE | dispatch('save') | dispatch('push')
83-
**D**ELETE | dispatch('delete') | dispatch('destroy')
84-
85-
86-
## Eager Loading
87-
88-
All `belongsTo` and `hasOne` related entities are eager loaded when fetch is called. All other related entities have to
89-
be added to a static field in the model called `eagerLoad` to have them eagerly loaded with fetch.
90-
91-
Example:
92-
93-
```javascript
94-
class User extends Model {
95-
static entity = 'users';
96-
static eagerLoad = ['posts'];
97-
98-
static fields () {
99-
return {
100-
id: this.attr(null),
101-
name: this.attr(''),
102-
103-
posts: this.hasMany(Post, 'userId')
104-
}
105-
}
106-
}
107-
```
108-
109-
110-
## Caching
111-
112-
Apollo-Client caches same queries. To bypass caching set the second param of the `fetch` action to `true`:
113-
114-
```
115-
User.dispatch('fetch', { filter: { id: 42 }, bypassCache: true });
116-
```
117-
118-
119-
120-
## Schema expectations
121-
122-
This plugin has an opinion how the GraphQL API schema should look like:
123-
124-
- Query for multiple records is plural camelCase: `blogPosts`
125-
- Mutations begin with the verb (`create`, `update`, `delete`) and the camelCased entity: `createBlogPost` for example.
126-
- The create mutation expects the new record as argument
127-
- The update mutation expects two arguments: The ID and the new record
128-
- The delete mutation expects the record ID to delete
129-
- Multiple records are within a `nodes` object and filtered by a `filter` argument.
130-
131-
You can see query examples in the [project wiki](https://github.com/vuex-orm/vuex-orm-apollo/wiki/Example-Queries).
132-
133-
134-
## Special record properties
135-
136-
This plugin adds a special property to your models: `$isPersisted`, which represents if this record is persisted on
137-
the server. It's true for all records except newly created ones.
138-
139-
140-
14117
## Contribution
14218

14319
To test this plugin in your existing project, you can use `yarn link` functionality. Run `yarn link` in your local

docs/.vuepress/config.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
title: Vuex-ORM Apollo Plugin Documentation
2-
description:
1+
title: 'Vuex-ORM Apollo Plugin'
2+
description: 'Vue + Vuex-ORM + GraphQL = <3'
33

44
base: '/vuex-orm-apollo/'
5+
6+
themeConfig:
7+
nav:
8+
- text: Home
9+
link: /
10+
11+
- text: Guide
12+
link: /guide/
13+
14+
- text: Vuex-ORM
15+
link: https://vuex-orm.github.io/vuex-orm/
16+
17+
- text: GitHub
18+
link: https://github.com/vuex-orm/vuex-orm-apollo
19+
20+
sidebar:
21+
- ['/guide/', 'Introduction']
22+
- /guide/setup/
23+
- /guide/graphql/
24+
- /guide/fetch/
25+
- /guide/persist/
26+
- /guide/push/
27+
- /guide/destroy/
28+
- /guide/relationships/
29+
- /guide/eager-loading/
30+
- /guide/skipping-fields/
31+
- /guide/meta-fields/

docs/.vuepress/dist/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<link rel="stylesheet" href="/vuex-orm-apollo/assets/css/1.styles.9c82df48.css">
1212
</head>
1313
<body>
14-
<div id="app" data-server-rendered="true"><div class="theme-container"><div class="content"><h1>404</h1><blockquote>Looks like we've got some broken links.</blockquote></div></div></div>
14+
<div id="app" data-server-rendered="true"><div class="theme-container"><div class="content"><h1>404</h1><blockquote>How did we get here?</blockquote></div></div></div>
1515
<script src="/vuex-orm-apollo/assets/js/app.98a767d9.js" defer></script>
1616
</body>
1717
</html>
19.5 KB
Loading

docs/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
# Hello VuePress
1+
---
2+
home: true
3+
heroImage: /logo-vuex-orm.png
4+
actionText: Get Started →
5+
actionLink: /guide/
6+
features:
7+
- title: GraphQL
8+
details: This Vuex-ORM plugin uses the apollo-client to let you sync your Vuex-ORM state with a GraphQL API
9+
- title: Vuex-ORM
10+
details: The plugin keeps up with the API and design of Vuex-ORM with full reactivity.
11+
- title: No boilerplate
12+
details: Setup and usage of this plugin is kept as simple as possible, no clutter in your components.
13+
footer: MIT Licensed
14+
---

docs/guide/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Introduction
2+
3+
This [Vuex-ORM](https://github.com/vuex-orm/vuex-orm) plugin uses the
4+
[apollo-client](https://www.apollographql.com/client/) to let you sync your Vuex state with
5+
a [GraphQL API](http://graphql.org/).
6+
7+
::: warning
8+
This plugin is in BETA stage, please use with care.
9+
:::
10+
11+
12+
## Actions
13+
14+
While using Vuex-ORM with the Apollo plugin you have to distinct between two types of Vuex actions:
15+
16+
- Vuex-ORM actions: Retrieve data from or save data to Vuex (`Vue Component <--> Vuex Store`)
17+
- Persistence actions: Load data from or persist data to the GraphQL API (`Vuex Store <--> GraphQL Server`)
18+
19+
The following table lists all actions and what they to:
20+
21+
CRUD | Vuex Only | Persist to GraphQL API
22+
--| -- | --
23+
**R**EAD | getters['find'] & getters['findAll'] | dispatch('fetch')
24+
**C**REATE | dispatch('create') | dispatch('persist')
25+
**U**PDATE | dispatch('save') | dispatch('push')
26+
**D**ELETE | dispatch('delete') | dispatch('destroy')
27+
28+
See the example below to get an idea of how this plugin interacts with Vuex-ORM.
29+
30+
31+
## Example usage
32+
33+
After [installing](/guide/setup) this plugin you can load data in your component:
34+
35+
```vue
36+
<template>
37+
<ul>
38+
<li v-for="user in users" :key="user.name">{{user.name}}</li>
39+
</ul>
40+
</template>
41+
42+
43+
<script>
44+
export default {
45+
computed: {
46+
users: () => store.getters['entities/users/all']()
47+
},
48+
49+
created() {
50+
this.$store.dispatch('entities/users/fetch');
51+
}
52+
}
53+
</script>
54+
```
55+
56+
57+
## License
58+
59+
Vuex ORM Apollo is open-sourced software licensed under the
60+
[MIT license](https://github.com/phortx/vuex-orm-apollo/blob/master/LICENSE.md).

docs/guide/destroy/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# destroy
2+
3+
Hello.

docs/guide/eager-loading/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Eager Loading
2+
3+
All `belongsTo` and `hasOne` related entities are eager loaded when `fetch` is called. All other related entities have to
4+
be added to a static field in the model called `eagerLoad` to have them eagerly loaded with fetch.
5+
6+
Example:
7+
8+
```javascript
9+
class User extends Model {
10+
static entity = 'users';
11+
static eagerLoad = ['posts'];
12+
13+
static fields () {
14+
return {
15+
id: this.attr(null),
16+
name: this.attr(''),
17+
18+
posts: this.hasMany(Post, 'userId')
19+
}
20+
}
21+
}

docs/guide/fetch/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# fetch
2+
3+
::: danger
4+
TODO
5+
:::
6+
7+
8+
## Caching
9+
10+
Apollo-Client caches same queries. To bypass caching set the second param of the `fetch` action to `true`:
11+
12+
```
13+
User.dispatch('fetch', { filter: { id: 42 }, bypassCache: true });
14+
```

docs/guide/graphql/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# GraphQL Schema
2+
3+
This plugin has an opinion of how the GraphQL API schema should look like:
4+
5+
- Query for multiple records is plural camelCase: `blogPosts`
6+
- Mutations begin with the verb (`create`, `update`, `delete`) and the camelCased entity: `createBlogPost` for example.
7+
- The create mutation expects the new record as a input type argument
8+
- The update mutation expects two arguments: The ID and the new record as a input type
9+
- The delete mutation expects the record ID to delete
10+
- Multiple records are within a `nodes` object and filtered by a `filter` argument.

0 commit comments

Comments
 (0)