Skip to content
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a415417
update docs to include switch for CLI and existing resources when add…
cwomack Mar 8, 2023
fdf08a6
fix flutter page with proper "existing resources" code sample
cwomack Mar 8, 2023
2bae1b8
fix to file type and minor visual improvement of code sample
cwomack Mar 8, 2023
1170622
add preamble after "Set Up Backend Resources"
cwomack Mar 8, 2023
8ad0e84
add back in the 'Identify User' title/reference in directory.js (out …
cwomack Mar 8, 2023
4d5789d
Updates to remove config/dependencies within Blockswitcher, additiona…
cwomack Mar 9, 2023
462b3c4
space added for spell check error
cwomack Mar 9, 2023
a7ee8f0
New block add for 3 options (2 CLI and 1 Manual config) for Auth back…
cwomack Mar 14, 2023
b3bf372
Merge branch 'aws-amplify:main' into main
cwomack Mar 14, 2023
4de15d3
Merge branch 'main' of github.com:cwomack/docs
cwomack Mar 14, 2023
1177dca
Further refinement of blocks and verbiage. Add 3rd Manual Config bloc…
cwomack Mar 17, 2023
246b8db
Merge branch 'aws-amplify:main' into main
cwomack Mar 17, 2023
d4cc639
Merge branch 'main' of github.com:cwomack/docs
cwomack Mar 17, 2023
8276a41
fixes to create new fragments for Flutter/iOS/Android pages
cwomack Mar 17, 2023
cec6d79
add change to js preamble
cwomack Mar 17, 2023
5df7194
fixes to links that navigating to wrong platform, general feedback fr…
cwomack Mar 28, 2023
d8a949a
Merge branch 'aws-amplify:main' into main
cwomack Mar 28, 2023
7f77a59
Merge branch 'main' of github.com:cwomack/docs
cwomack Mar 28, 2023
da4809d
Revert callouts
cwomack Mar 28, 2023
417853b
remove a comma that leads to invalid JSON string
cwomack Mar 28, 2023
c188f58
revert "jsx" to "dart" for code block
cwomack Mar 28, 2023
d980f11
fixes to block switcher links, updates to text, fragments for JS and RN
cwomack Mar 29, 2023
0634b49
Merge branch 'main' of github.com:cwomack/docs
cwomack Mar 29, 2023
137e93e
fixes that should mimic closed PR #5307, but not include unecessary f…
cwomack Mar 29, 2023
caaac4b
Update src/fragments/lib/auth/js/getting-started-steps-basic-auth-rea…
abdallahshaban557 Mar 29, 2023
19e1981
remove duplicated "amazon-cognito-identity-js"
cwomack Mar 29, 2023
b418c4d
Merge branch 'aws-amplify:main' into main
cwomack Mar 31, 2023
a3440b4
Merge branch 'main' of github.com:cwomack/docs
cwomack Mar 31, 2023
c43d67c
Add Studio option for block switcher within Auth > Getting Started pages
cwomack Mar 31, 2023
e74ad8a
minor changes to block order and updates to Studio block text
cwomack Apr 5, 2023
ea44b99
Update src/fragments/lib/auth/android/getting_started/50_configureBac…
cwomack Apr 12, 2023
21a3381
Update src/fragments/lib/auth/js/getting-started-set-up-backend-resou…
cwomack Apr 12, 2023
55b1813
Update src/fragments/lib/auth/js/getting_started/10_setUpBackendResou…
cwomack Apr 12, 2023
adcbef8
Merge branch 'aws-amplify:main' into main
cwomack Apr 14, 2023
11d2afc
Merge branch 'aws-amplify:main' into main
cwomack Apr 14, 2023
a96e670
updates to Auth block names, fix to React Native docs for Social Auth…
cwomack Apr 14, 2023
08da5b6
add update to Android
cwomack Apr 14, 2023
d2d891d
Updates to preamble wording to include additional options.
cwomack Apr 14, 2023
5201fd0
going with option #3
cwomack Apr 14, 2023
a487354
Merge branch 'aws-amplify:main' into main
cwomack Apr 25, 2023
b500794
Merge branch 'aws-amplify:main' into main
cwomack Apr 25, 2023
c558f79
update file reference for Angular tutorial, add what the final code b…
cwomack Apr 25, 2023
d7d27ed
remove yarn.lock
cwomack Apr 26, 2023
0682b98
update GraphQL Schema example to eliminate tutorial errors
cwomack Apr 26, 2023
4adfe36
Merge branch 'aws-amplify:main' into main
cwomack Apr 26, 2023
9d8c265
Merge branch 'aws-amplify:main' into main
cwomack Apr 26, 2023
d4569c7
fix merge conflict
katieklein May 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 71 additions & 8 deletions src/fragments/start/getting-started/angular/data-model.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ or continue
The generated schema is for a Todo app. Replace the GraphQL schema at `amplify/backend/api/RestaurantAPI/schema.graphql` with the following:

```graphql
type Restaurant @model {
type Restaurant @model @auth(rules: [{ allow: public }]){
id: ID!
name: String!
description: String!
city: String!
}
}
```

You'll notice a directive on the `Restaurant` type of `@model`. This directive is part of Amplify's [GraphQL transformer](/cli/graphql/data-modeling) functionality.

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.
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. In the example schema above, the `@model` directive is part of Amplify's [GraphQL transformer](/cli/graphql/data-modeling) functionality and the `@auth` directive determines what [authorization rules](/cli/graphql/authorization-rules/) to apply.

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

Expand Down Expand Up @@ -220,7 +218,7 @@ Next, add a form that will be used for creating restaurants. Add the following t
</div>
```

Next, update your `RestaurantsComponent` class so that it will list all restaurants in the database when the app starts. To do so, implement [OnInit](https://angular.io/api/core/OnInit) add a `ListRestaurants` query in `src/app/restaurants/restaurants.component.ts`. Store the query results in an array.
Next, update your `RestaurantsComponent` class so that it will list all restaurants in the database when the app starts. To do so, implement [OnInit](https://angular.io/api/core/OnInit) and add a `ListRestaurants` query in `src/app/restaurants/restaurants.component.ts`. Store the query results in an array.

```typescript
import { Component, OnInit } from '@angular/core';
Expand Down Expand Up @@ -277,7 +275,7 @@ Add the following to your `src/app/restaurants/restaurants.component.html` to di
</div>
```

To subscribe to realtime data, declare a subscription class variable and update `ngOnInit` in `src/app/app.component.ts`. When the app starts, this code will set up a subscription. The subscription will update the `restaurants` array when new events are received (when a new restaurant is created):
To subscribe to realtime data, declare a subscription class variable and update `ngOnInit` in `src/app/restaurants.component.ts`. When the app starts, this code will set up a subscription. The subscription will update the `restaurants` array when new events are received (when a new restaurant is created):

```typescript
/** Subscription type will be inferred from this library */
Expand All @@ -303,7 +301,7 @@ async ngOnInit() {
}
```

Finally, unsubscribe from the subscription when the component is destroyed. Import and add `OnDestroy` in `src/app/app.component.ts`:
Finally, unsubscribe from the subscription when the component is destroyed. Import and add `OnDestroy` in `src/app/restaurants.component.ts`:

```typescript
import { Component, OnDestroy, OnInit } from '@angular/core';
Expand All @@ -317,6 +315,71 @@ export class AppComponent implements OnInit, OnDestroy {
this.subscription = null;
}
```
The final `restaurants.component.ts` file should look like the following:

```typescript
import { Component, OnInit, OnDestroy } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { APIService, Restaurant } from '../API.service';

/** Subscription type will be inferred from this library */
import { ZenObservable } from 'zen-observable-ts';

@Component({
selector: 'app-restaurants',
templateUrl: './restaurants.component.html',
styleUrls: ['./restaurants.component.css']
})
export class RestaurantsComponent implements OnInit, OnDestroy {
public createForm: FormGroup;

/* declare restaurants variable */
public restaurants: Array<Restaurant> = [];
/** Declare subscription variable */
private subscription: ZenObservable.Subscription | null = null;

constructor(private api: APIService, private fb: FormBuilder) {
this.createForm = this.fb.group({
name: ['', Validators.required],
description: ['', Validators.required],
city: ['', Validators.required]
});
}

async ngOnInit() {
this.api.ListRestaurants().then(event => {
this.restaurants = event.items as Restaurant[];
});

/* subscribe to new restaurants being created */
this.subscription = this.api.OnCreateRestaurantListener().subscribe(
(event: any) => {
const newRestaurant = event.value.data.onCreateRestaurant;
this.restaurants = [newRestaurant, ...this.restaurants];
}
);
}

ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
this.subscription = null;
}

public onCreate(restaurant: Restaurant) {
this.api
.CreateRestaurant(restaurant)
.then((event) => {
console.log('item created!');
this.createForm.reset();
})
.catch((e) => {
console.log('error creating restaurant...', e);
});
}
}
```

Next, run the app:

Expand Down