Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
r3-yamauchi committed Nov 2, 2020
1 parent 533d76a commit 93e4a13
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 103 deletions.
3 changes: 3 additions & 0 deletions .graphqlconfig.yml
Expand Up @@ -10,3 +10,6 @@ projects:
codeGenTarget: javascript
generatedFileName: ''
docsFilePath: src/graphql
extensions:
amplify:
version: 3
1 change: 1 addition & 0 deletions amplify/backend/api/amplifydsvue/schema.graphql
@@ -1,6 +1,7 @@
type Chatty @model {
id: ID!
user: String!
rate: Int!
message: String!
createdAt: AWSDateTime
}
18 changes: 14 additions & 4 deletions src/HelloWorld.vue
@@ -1,12 +1,13 @@
<template>
<div>
<form v-on:submit.prevent>
<input v-model="form.rate" />
<input v-model="form.message" />
<button @click="sendMessage">Send</button>
</form>

<div v-for="message of sorted" :key="message.id">
<div>{{ message.message }} {{ message.user }} - {{ message.createdAt }}</div>
<div>{{ message.rate }} {{ message.message }} {{ message.user }} - {{ message.createdAt }}</div>
</div>

<button @click="allDel">Delete all messages.</button>
Expand All @@ -15,9 +16,17 @@
</template>
<script>
import { Auth } from "aws-amplify";
import { DataStore, Predicates } from "@aws-amplify/datastore";
import { DataStore, Predicates, syncExpression } from "@aws-amplify/datastore";
import { Chatty } from "./models";
DataStore.configure({
syncExpressions: [
syncExpression(Chatty, () => {
return (c) => c.rate('gt', 5).rate('lt', 7);
}),
]
});
export default {
name: 'app',
data() {
Expand Down Expand Up @@ -47,9 +56,10 @@ export default {
},
methods: {
sendMessage() {
const { message } = this.form
if (!message) return;
const { rate, message } = this.form
if (!rate || !message) return;
DataStore.save(new Chatty({
rate: Number(rate),
user: this.user.username,
message: message,
createdAt: new Date().toISOString()
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/mutations.js
Expand Up @@ -9,6 +9,7 @@ export const createChatty = /* GraphQL */ `
createChatty(input: $input, condition: $condition) {
id
user
rate
message
createdAt
_version
Expand All @@ -26,6 +27,7 @@ export const updateChatty = /* GraphQL */ `
updateChatty(input: $input, condition: $condition) {
id
user
rate
message
createdAt
_version
Expand All @@ -43,6 +45,7 @@ export const deleteChatty = /* GraphQL */ `
deleteChatty(input: $input, condition: $condition) {
id
user
rate
message
createdAt
_version
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/queries.js
Expand Up @@ -17,6 +17,7 @@ export const syncChatties = /* GraphQL */ `
items {
id
user
rate
message
createdAt
_version
Expand All @@ -34,6 +35,7 @@ export const getChatty = /* GraphQL */ `
getChatty(id: $id) {
id
user
rate
message
createdAt
_version
Expand All @@ -53,6 +55,7 @@ export const listChattys = /* GraphQL */ `
items {
id
user
rate
message
createdAt
_version
Expand Down

0 comments on commit 93e4a13

Please sign in to comment.