Skip to content
This repository was archived by the owner on Jul 7, 2020. It is now read-only.

Commit 3e32f41

Browse files
author
Dustin Noyes
committed
adding appsync and logger
1 parent 106f5aa commit 3e32f41

File tree

8 files changed

+113
-202
lines changed

8 files changed

+113
-202
lines changed

.graphqlconfig.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
projects:
2+
vuesample1:
3+
schemaPath: src/graphql/schema.json
4+
includes:
5+
- src/graphql/**/*.js
6+
excludes:
7+
- ./amplify/**
8+
extensions:
9+
amplify:
10+
codeGenTarget: typescript
11+
generatedFileName: src/API.ts
12+
docsFilePath: src/graphql
13+
graphQLApiId: uo2zimgv7zcalm5aw3i7oi26ry
14+
endpoints:
15+
prod: >-
16+
https://6pe4kvx2dzghrfjye5pmfbnu7a.appsync-api.us-west-2.amazonaws.com/graphql

src/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import Menu from '@/components/Menu';
2424
2525
Vue.component('v-menu', Menu)
2626
27+
window.LOG_LEVEL = 'VERBOSE';
28+
2729
export default {
2830
name: 'app'
2931
}

src/notes/components/Note.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/>
3333
</svg>
3434
</div>
35-
<div :style="itemStyle.title">{{note.title}}</div>
35+
<div :style="itemStyle.title">{{todo.note}}</div>
3636
<div :style="itemStyle.remove" v-on:click="remove">x</div>
3737
</li>
3838
</template>
@@ -42,22 +42,22 @@ import { JS } from 'fsts'
4242
4343
export default {
4444
name: 'Note',
45-
props: ['note', 'theme'],
45+
props: ['todo', 'theme'],
4646
computed: {
47-
toggleOpacity: function() { return this.note.done? 1 : 0 },
47+
toggleOpacity: function() { return this.todo.done? 1 : 0 },
4848
itemStyle: function () {
49-
return this.note.done
49+
return this.todo.done
5050
? JS.deepAssign({}, this.theme.item, this.theme.item.done)
5151
: this.theme.item
5252
}
5353
},
5454
methods: {
5555
toggle() {
56-
this.$emit('toggle', this.note.id)
56+
this.$emit('toggle', this.todo)
5757
},
5858
remove() {
59-
if (this.note.done) {
60-
this.$emit('remove', this.note.id)
59+
if (this.todo.done) {
60+
this.$emit('remove', this.todo.id)
6161
}
6262
}
6363
}

src/notes/components/Notes.vue

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
<input
1818
:style="theme.input"
1919
autofocus
20-
v-model="title"
20+
v-model="note"
2121
v-on:keyup.enter="create"
2222
/>
2323
<ul :style="theme.list">
2424
<a-note
25-
v-for="note in notes"
26-
:key="note.id"
27-
:note="note"
25+
v-for="todo in todos"
26+
:key="todo.id"
27+
:todo="todo"
2828
:theme="theme"
2929
v-on:toggle="toggle"
3030
v-on:remove="remove"
@@ -47,53 +47,72 @@ import { JS } from 'fsts'
4747
4848
import AmplifyStore from '../../store/store'
4949
50-
import NotesStore from './persist'
50+
import { CreateTodo, ListTodos, UpdateTodo, DeleteTodo } from './persist/graphqlActions';
51+
5152
import NotesTheme from '../NotesTheme'
5253
import Note from './Note'
5354
5455
Vue.component('a-note', Note)
5556
56-
const logger = new Logger('NotesComp')
57-
5857
export default {
5958
name: 'Notes',
6059
data () {
6160
return {
6261
theme: NotesTheme || {},
63-
title: '',
62+
note: '',
63+
todos: [],
6464
filter: 'all',
65-
ts: 0 // for force refresh notes after actions
65+
logger: {},
66+
actions: {
67+
create: CreateTodo,
68+
list: ListTodos,
69+
update: UpdateTodo,
70+
delete: DeleteTodo,
71+
},
6672
}
6773
},
74+
created() {
75+
this.logger = new this.$Amplify.Logger('NOTES_component')
76+
this.$Amplify.API.graphql(this.$Amplify.graphqlOperation(this.actions.list, {}))
77+
.then((res) => {
78+
this.todos = res.data.listTodos.items;
79+
this.logger.info(`Todos successfully listed`, res)
80+
})
81+
.catch((e) => {
82+
this.logger.error(`Error listing Todos`, e)
83+
});
84+
},
6885
computed: {
69-
userId: function() { return AmplifyStore.state.userId },
70-
notesStore: function() { return new NotesStore(this.userId) },
71-
notes() {
72-
if (this.filter === 'active') {
73-
return this.notesStore.findAll({ done: true }, this.ts)
74-
}
75-
if (this.filter === 'completed') {
76-
return this.notesStore.findAll({ done: false }, this.ts)
77-
}
78-
return this.notesStore.findAll({}, this.ts)
79-
}
86+
userId: function() { return AmplifyStore.state.userId }
8087
},
8188
methods: {
82-
toggle(id) {
83-
logger.debug('toggle ' + id)
84-
this.notesStore.toggle(id)
85-
this.ts = new Date().getTime()
89+
toggle(todo) {
90+
this.$Amplify.API.graphql(this.$Amplify.graphqlOperation(this.actions.update, {id: todo.id, note: todo.note, done: !todo.done}))
91+
.then((res) => {
92+
todo.done = !todo.done
93+
this.logger.info(`Todo ${todo.id} done status toggled`, res)
94+
})
95+
.catch((e) => {
96+
this.logger.error(`Error toggling Todo ${todo.id} done status`, e)
97+
})
8698
},
8799
remove(id) {
88-
logger.debug('remove ' + id)
89-
this.notesStore.remove(id)
90-
this.ts = new Date().getTime()
100+
this.$Amplify.API.graphql(this.$Amplify.graphqlOperation(this.actions.delete, {id}))
101+
.then((res) => {
102+
this.logger.info(`Todo ${id} removed`, res)
103+
})
104+
.catch((e) => {
105+
this.logger.error(`Error removing Todo ${id}`, e)
106+
})
91107
},
92108
create() {
93-
logger.debug('create ' + this.title)
94-
this.notesStore.create(this.title)
95-
this.ts = new Date().getTime()
96-
this.title = ''
109+
this.$Amplify.API.graphql(this.$Amplify.graphqlOperation(this.actions.create, {note: this.note}))
110+
.then((res) => {
111+
this.logger.info(`Todo created`, res)
112+
})
113+
.catch((e) => {
114+
this.logger.error(`Error creating Todo`, e)
115+
})
97116
}
98117
}
99118
}

src/notes/components/persist/CacheStore.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/notes/components/persist/InMemoryStore.js

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const CreateTodo = `mutation createTodo($note: String!) {
2+
createTodo(input: {note: $note}) {
3+
id
4+
note
5+
}
6+
}`;
7+
8+
const ListTodos = `query {
9+
listTodos {
10+
items {
11+
id
12+
note
13+
done
14+
}
15+
}
16+
}`;
17+
18+
const UpdateTodo = `mutation updateTodo($id: ID!, $note: String, $done: Boolean) {
19+
updateTodo(input: {id: $id, note: $note, done: $done}) {
20+
id
21+
note
22+
done
23+
}
24+
}`;
25+
26+
const DeleteTodo = `mutation DeleteTodo($id: ID!) {
27+
deleteTodo(input: {id: $id}) {
28+
id
29+
}
30+
}
31+
`
32+
33+
export {
34+
CreateTodo,
35+
ListTodos,
36+
UpdateTodo,
37+
DeleteTodo
38+
}

src/notes/components/persist/index.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)