├── .browserslistrc
├── .gitignore
├── README.md
├── babel.config.js
├── package.json
├── postcss.config.js
├── public
├── favicon.ico
└── index.html
├── src
├── App.vue
├── assets
│ └── logo.png
├── components
│ └── ListItem.vue
├── graphql
│ └── queries.js
├── main.js
└── resolvers.js
└── yarn.lock
/.browserslistrc:
--------------------------------------------------------------------------------
1 | > 1%
2 | last 2 versions
3 | not ie <= 8
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 | # local env files
6 | .env.local
7 | .env.*.local
8 |
9 | # Log files
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 |
14 | # Editor directories and files
15 | .idea
16 | .vscode
17 | *.suo
18 | *.ntvs*
19 | *.njsproj
20 | *.sln
21 | *.sw?
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vue-todo-apollo
2 |
3 | ## Project setup
4 | ```
5 | yarn install
6 | ```
7 |
8 | ### Compiles and hot-reloads for development
9 | ```
10 | yarn run serve
11 | ```
12 |
13 | ### Compiles and minifies for production
14 | ```
15 | yarn run build
16 | ```
17 |
18 | ### Run your tests
19 | ```
20 | yarn run test
21 | ```
22 |
23 | ### Lints and fixes files
24 | ```
25 | yarn run lint
26 | ```
27 |
28 | ### Customize configuration
29 | See [Configuration Reference](https://cli.vuejs.org/config/).
30 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | '@vue/app'
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-todo-apollo",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "serve": "vue-cli-service serve",
7 | "build": "vue-cli-service build"
8 | },
9 | "dependencies": {
10 | "@fortawesome/fontawesome-free": "^5.8.1",
11 | "apollo-boost": "^0.3.1",
12 | "core-js": "^2.6.5",
13 | "graphql": "^14.2.1",
14 | "node-sass": "^4.11.0",
15 | "sass-loader": "^7.1.0",
16 | "shortid": "^2.2.14",
17 | "vue": "^2.6.10",
18 | "vue-apollo": "^3.0.0-beta.28"
19 | },
20 | "devDependencies": {
21 | "@vue/cli-plugin-babel": "^3.6.0",
22 | "@vue/cli-service": "^3.6.0",
23 | "vue-template-compiler": "^2.5.21"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: {
3 | autoprefixer: {}
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NataliaTepluhina/vue-apollo-todo/4abbf38d24effb726fb9152bef981c79d4882db8/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | vue-todo-apollo
9 |
10 |
11 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
ToDo List
4 |
5 |
6 |
9 |
10 |
11 |
18 |
19 |
20 |
21 |
22 |
72 |
73 |
113 |
--------------------------------------------------------------------------------
/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NataliaTepluhina/vue-apollo-todo/4abbf38d24effb726fb9152bef981c79d4882db8/src/assets/logo.png
--------------------------------------------------------------------------------
/src/components/ListItem.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
{{content.text}}
5 |
6 |
10 |
13 |
14 |
15 |
16 |
17 |
33 |
34 |
61 |
--------------------------------------------------------------------------------
/src/graphql/queries.js:
--------------------------------------------------------------------------------
1 | import gql from 'graphql-tag';
2 |
3 | export const todoItemsQuery = gql`
4 | {
5 | todoItems @client {
6 | id
7 | text
8 | done
9 | }
10 | }
11 | `;
12 |
13 | export const checkItemMutation = gql`
14 | mutation($id: ID!) {
15 | checkItem(id: $id) @client
16 | }
17 | `;
18 |
19 | export const addItemMutation = gql`
20 | mutation($text: String!) {
21 | addItem(text: $text) @client {
22 | id
23 | text
24 | done
25 | }
26 | }
27 | `;
28 |
29 | export const deleteItemMutation = gql`
30 | mutation($id: ID!) {
31 | deleteItem(id: $id) @client
32 | }
33 | `;
34 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import ApolloClient from 'apollo-boost';
3 | import { InMemoryCache } from 'apollo-cache-inmemory';
4 | import '@fortawesome/fontawesome-free/css/all.css';
5 | import VueApollo from 'vue-apollo';
6 | import App from './App.vue';
7 | import { typeDefs, resolvers } from './resolvers';
8 |
9 | Vue.use(VueApollo);
10 |
11 | Vue.config.productionTip = false;
12 |
13 | const cache = new InMemoryCache();
14 |
15 | const apolloClient = new ApolloClient({
16 | cache,
17 | resolvers,
18 | typeDefs,
19 | });
20 |
21 | cache.writeData({
22 | data: {
23 | todoItems: [
24 | {
25 | __typename: 'Item',
26 | id: 'dqdBHJGgjgjg',
27 | text: 'test',
28 | done: true,
29 | },
30 | ],
31 | },
32 | });
33 |
34 | const apolloProvider = new VueApollo({
35 | defaultClient: apolloClient,
36 | });
37 |
38 | new Vue({
39 | render: h => h(App),
40 | apolloProvider,
41 | }).$mount('#app');
42 |
--------------------------------------------------------------------------------
/src/resolvers.js:
--------------------------------------------------------------------------------
1 | import gql from 'graphql-tag';
2 | import shortid from 'shortid';
3 | import { todoItemsQuery } from './graphql/queries';
4 |
5 | export const typeDefs = gql`
6 | extend type Item {
7 | id: ID!
8 | text: String!
9 | done: Boolean!
10 | }
11 |
12 | extend type Mutation {
13 | changeItem(id: ID!): Boolean
14 | deleteItem(id: ID!): Boolean
15 | addItem(text: String!): Item
16 | }
17 | `;
18 |
19 | export const resolvers = {
20 | Mutation: {
21 | checkItem: (_, { id }, { cache }) => {
22 | const data = cache.readQuery({ query: todoItemsQuery });
23 | const currentItem = data.todoItems.find(item => item.id === id);
24 | currentItem.done = !currentItem.done;
25 | cache.writeQuery({ query: todoItemsQuery, data });
26 | return currentItem.done;
27 | },
28 |
29 | addItem: (_, { text }, { cache }) => {
30 | const data = cache.readQuery({ query: todoItemsQuery });
31 | const newItem = {
32 | __typename: 'Item',
33 | id: shortid.generate(),
34 | text,
35 | done: false,
36 | };
37 | data.todoItems.push(newItem);
38 | cache.writeQuery({ query: todoItemsQuery, data });
39 | return newItem;
40 | },
41 |
42 | deleteItem: (_, { id }, { cache }) => {
43 | const data = cache.readQuery({ query: todoItemsQuery });
44 | const currentItem = data.todoItems.find(item => item.id === id);
45 | data.todoItems.splice(data.todoItems.indexOf(currentItem), 1);
46 | cache.writeQuery({ query: todoItemsQuery, data });
47 | return true;
48 | },
49 | },
50 | };
51 |
--------------------------------------------------------------------------------