Skip to content

Commit 62d3395

Browse files
authored
Merge pull request aws-amplify#4711 from ErikCH/getting-started/vue
Updated Vue getting started guide
2 parents 1488456 + 4ff34f7 commit 62d3395

File tree

3 files changed

+157
-251
lines changed

3 files changed

+157
-251
lines changed

cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,8 @@
14721472
"myfunction",
14731473
"roadmap",
14741474
"infowindow",
1475-
"Libre's"
1475+
"Libre's",
1476+
"Pinia"
14761477
],
14771478
"flagWords": ["hte"]
14781479
}

src/fragments/start/getting-started/vue/data-model.mdx

Lines changed: 83 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Select the default values which are highlighted below:
6262

6363
The CLI should open this GraphQL schema in your text editor.
6464

65-
__amplify/backend/api/myapi/schema.graphql__
65+
**amplify/backend/api/myapi/schema.graphql**
6666

6767
```graphql
6868
type Todo @model {
@@ -72,13 +72,13 @@ type Todo @model {
7272
}
7373
```
7474

75-
The schema generated is for a Todo app. You'll notice a directive on the `Todo` type of `@model`. This directive is part of the [GraphQL transform](/cli/graphql/data-modeling) library of Amplify.
75+
The schema generated is for a Todo app. You'll notice a directive on the `Todo` type of `@model`. This directive is part of the [GraphQL transform](/cli/graphql/data-modeling) library of Amplify.
7676

7777
The GraphQL Transform Library provides custom directives you can use in your schema that allow you to do things like define data models, set up authentication and authorization rules, configure serverless functions as resolvers, and more.
7878

7979
A type decorated with the `@model` directive will scaffold out the database table for the type (Todo table), the schema for CRUD (create, read, update, delete) and list operations, and the GraphQL resolvers needed to make everything work together.
8080

81-
From the command line, press __enter__ to accept the schema and continue to the next steps.
81+
From the command line, press **enter** to accept the schema and continue to the next steps.
8282

8383
## Deploy your GraphQL API
8484

@@ -128,7 +128,7 @@ This will open your Amplify app project in the AWS service console. Choose the *
128128

129129
## Connect frontend to API
130130

131-
Next, open __App.vue__.
131+
Next, open **App.vue**.
132132

133133
### Writing data with GraphQL mutations
134134

@@ -138,38 +138,38 @@ To create a new todo in the database, use the `API.graphql()` operation with the
138138
<template>
139139
<div id="app">
140140
<h1>Todo App</h1>
141-
<input type="text" v-model="name" placeholder="Todo name">
142-
<input type="text" v-model="description" placeholder="Todo description">
141+
<input type="text" v-model="name" placeholder="Todo name" />
142+
<input type="text" v-model="description" placeholder="Todo description" />
143143
<button v-on:click="createTodo">Create Todo</button>
144144
</div>
145145
</template>
146146

147147
<script>
148-
import { API } from 'aws-amplify';
149-
import { createTodo } from './graphql/mutations';
150-
151-
export default {
152-
name: 'app',
153-
data() {
154-
return {
155-
name: '',
156-
description: ''
157-
}
158-
},
159-
methods: {
160-
async createTodo() {
161-
const { name, description } = this;
162-
if (!name || !description) return;
163-
const todo = { name, description };
164-
await API.graphql({
165-
query: createTodo,
166-
variables: {input: todo},
167-
});
168-
this.name = '';
169-
this.description = '';
148+
import { API } from 'aws-amplify';
149+
import { createTodo } from './graphql/mutations';
150+
151+
export default {
152+
name: 'app',
153+
data() {
154+
return {
155+
name: '',
156+
description: ''
157+
};
158+
},
159+
methods: {
160+
async createTodo() {
161+
const { name, description } = this;
162+
if (!name || !description) return;
163+
const todo = { name, description };
164+
await API.graphql({
165+
query: createTodo,
166+
variables: { input: todo }
167+
});
168+
this.name = '';
169+
this.description = '';
170+
}
170171
}
171-
}
172-
};
172+
};
173173
</script>
174174
```
175175

@@ -181,8 +181,8 @@ To display the data, update `App.vue` to list all the items in the database by i
181181
<template>
182182
<div id="app">
183183
<h1>Todo App</h1>
184-
<input type="text" v-model="name" placeholder="Todo name">
185-
<input type="text" v-model="description" placeholder="Todo description">
184+
<input type="text" v-model="name" placeholder="Todo name" />
185+
<input type="text" v-model="description" placeholder="Todo description" />
186186
<button v-on:click="createTodo">Create Todo</button>
187187
<div v-for="item in todos" :key="item.id">
188188
<h3>{{ item.name }}</h3>
@@ -192,44 +192,43 @@ To display the data, update `App.vue` to list all the items in the database by i
192192
</template>
193193

194194
<script>
195-
import { API } from 'aws-amplify';
196-
import { createTodo } from './graphql/mutations';
197-
import { listTodos } from './graphql/queries';
198-
199-
export default {
200-
name: 'App',
201-
async created() {
202-
this.getTodos();
203-
this.subscribe();
204-
},
205-
data() {
206-
return {
207-
name: '',
208-
description: '',
209-
todos: []
210-
}
211-
},
212-
methods: {
213-
async createTodo() {
214-
const { name, description } = this;
215-
if (!name || !description) return;
216-
const todo = { name, description };
217-
this.todos = [...this.todos, todo];
218-
await API.graphql({
219-
query: createTodo,
220-
variables: {input: todo},
221-
});
222-
this.name = '';
223-
this.description = '';
195+
import { API } from 'aws-amplify';
196+
import { createTodo } from './graphql/mutations';
197+
import { listTodos } from './graphql/queries';
198+
199+
export default {
200+
name: 'App',
201+
async created() {
202+
this.getTodos();
203+
},
204+
data() {
205+
return {
206+
name: '',
207+
description: '',
208+
todos: []
209+
};
224210
},
225-
async getTodos() {
226-
const todos = await API.graphql({
227-
query: listTodos
228-
});
229-
this.todos = todos.data.listTodos.items;
211+
methods: {
212+
async createTodo() {
213+
const { name, description } = this;
214+
if (!name || !description) return;
215+
const todo = { name, description };
216+
this.todos = [...this.todos, todo];
217+
await API.graphql({
218+
query: createTodo,
219+
variables: { input: todo }
220+
});
221+
this.name = '';
222+
this.description = '';
223+
},
224+
async getTodos() {
225+
const todos = await API.graphql({
226+
query: listTodos
227+
});
228+
this.todos = todos.data.listTodos.items;
229+
}
230230
}
231-
}
232-
}
231+
};
233232
</script>
234233
```
235234

@@ -239,28 +238,27 @@ Now if you wish to subscribe to data, import the `onCreateTodo` subscription and
239238

240239
```html
241240
<script>
242-
// other imports
243-
import { onCreateTodo } from './graphql/subscriptions';
244-
245-
export default {
246-
// other functions and properties
247-
created(){
248-
this.getTodos();
249-
this.subscribe();
250-
},
251-
methods: {
252-
// other methods
253-
subscribe() {
254-
API.graphql({ query: onCreateTodo })
255-
.subscribe({
241+
// other imports
242+
import { onCreateTodo } from './graphql/subscriptions';
243+
244+
export default {
245+
// other functions and properties
246+
created() {
247+
this.getTodos();
248+
this.subscribe();
249+
},
250+
methods: {
251+
// other methods
252+
subscribe() {
253+
API.graphql({ query: onCreateTodo }).subscribe({
256254
next: (eventData) => {
257255
let todo = eventData.value.data.onCreateTodo;
258-
if (this.todos.some(item => item.name === todo.name)) return; // remove duplications
256+
if (this.todos.some((item) => item.name === todo.name)) return; // remove duplications
259257
this.todos = [...this.todos, todo];
260258
}
261259
});
260+
}
262261
}
263-
}
264-
};
262+
};
265263
</script>
266264
```

0 commit comments

Comments
 (0)