vue-graphql-models
Universal library which helps to build OOP-driven GraphQL based models for Vue components. Influenced by Laravel Eloquent Models & Collections.
2,831
7
| Install | |
|---|---|
npm install vue-graphql-models@2.4.5 |
|
| Latest Version: | 2.4.5 |
| Vue: | 2 |
| License: | MIT |
| Last Updated: | Oct 2, 2019 |
| Links: | GitHub · npm |
Maintainer: matrunchyk
Vue GraphQL Models
Universal library which helps to build OOP-driven GraphQL based models for Vue components. Influenced by Laravel Eloquent Models & Collections.
Note. If you looking for v1 of this library, switch to a relevant branch.
Features
BaseModelis a class which acts as a base entity for your models extending this class.- Full encapsulation of GraphQL queries & mutations. No need to call them manually, all you need is to call you Model's methods.
- All arrays retrieved from GraphQL will be hydrated with respectful collections of models.
- Supports lazy-loading of GraphQL documents.
- Supports events & hooks for customization.
Internally:
- Webpack 4 based.
- ES6 as a source.
- Exports in a umd format so library works everywhere.
- ES6 test setup with Mocha and Chai.
- Linting with ESLint.
Installation
npm i vue-graphql-models -S
or
yarn add vue-graphql-models
Configuration
import VueGraphqlModels from 'vue-graphql-models';
Vue.use(VueGraphqlModels);
Documentation
Basic Usage
1. Define your model:
import { BaseModel } from 'vue-graphql-models';
export default class Fruit extends BaseModel {
// Your additional logic, if needed
// ...or just empty class
}
2. Use it in your component:
<template>
<ul>
<li v-if="model.loading">Loading...</li>
<li v-else-if="model.error">Loading Failed!</li>
<li v-else v-for="(item, index) in model.results.all()" :key="index">
<p>Name: {{ item.name }}</p>
<p>Color: {{ item.color }}</p>
</li>
</ul>
</template>
<script>
import Fruit from '@/models/Fruit';
export default {
data: () => ({
model: new Fruit(),
}),
created() {
this.model.get();
},
}
</script>
Contribution
Feel free to submit your pull-requests, ideas, proposals and bug reports!
TODOs:
- Add dynamic query/mutation building based on model attributes w/o need to create
.graphqlfiles at all - Make collections optional to make library more lightweight
- Rewrite to TypeScript
- Add subscriptions & events example
- Write more tests & coverage support
- Add model versioning support
- Add a configurable operation confirmation when performing some risky operations. For example, automatically display a delete confirmation component when executing
.delete()method.
Related Packages
vue-oop
A library based on Model-Repository patterns for Vue components. Usable for Grap...
3,271
17
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 2.4.5 | ^2.6.2 | MIT | |
| 2.4.4 | ^2.6.2 | MIT | |
| 2.4.3 | ^2.6.2 | MIT | |
| 2.4.2 | ^2.6.2 | MIT | |
| 2.4.1 | ^2.5.17 | MIT | |
| 2.4.0 | ^2.5.17 | MIT | |
| 2.3.5 | ^2.5.17 | MIT | |
| 2.3.4 | ^2.5.17 | MIT | |
| 2.3.3 | ^2.5.17 | MIT | |
| 2.3.2 | ^2.5.17 | MIT | |
| 2.3.1 | ^2.5.17 | MIT | |
| 2.2.1 | ^2.5.17 | MIT | |
| 2.2.0 | ^2.5.17 | MIT | |
| 2.1.4 | ^2.5.17 | MIT | |
| 2.1.3 | ^2.5.17 | MIT | |
| 2.1.2 | ^2.5.17 | MIT | |
| 2.1.1 | ^2.5.17 | MIT | |
| 2.1.0 | ^2.5.17 | MIT | |
| 2.0.1 | ^2.5.17 | MIT | |
| 2.0.0 | ^2.5.17 | MIT | |
| 1.12.3 | ^2.5.17 | MIT | |
| 1.12.2 | ^2.5.17 | MIT | |
| 1.12.1 | ^2.5.17 | MIT | |
| 1.12.0 | ^2.5.17 | MIT | |
| 1.11.5 | ^2.5.17 | MIT | |
| 1.11.4 | ^2.5.17 | MIT | |
| 1.11.3 | ^2.5.17 | MIT | |
| 1.11.2 | ^2.5.17 | MIT | |
| 1.11.1 | ^2.5.17 | MIT | |
| 1.11.0 | ^2.5.17 | MIT |
Showing the latest 30 of 104. See every release on npm
Pre-releases (1)
| Version | Released | Vue | License |
|---|---|---|---|
| 3.0.0-alpha | ^2.6.2 | MIT |