Skip to content

Commit d593c37

Browse files
authored
run data snippets through prettier, naming updates (#7827)
1 parent fadf3ca commit d593c37

File tree

3 files changed

+40
-53
lines changed
  • src/pages/[platform]/build-a-backend/data

3 files changed

+40
-53
lines changed

src/pages/[platform]/build-a-backend/data/connect-to-existing-data-sources/connect-external-ddb-table/index.mdx

+16-30
Original file line numberDiff line numberDiff line change
@@ -481,19 +481,18 @@ To delete your external DynamoDB table, you can navigate to the AppSync console
481481
[Reference](https://docs.aws.amazon.com/appsync/latest/devguide/js-resolver-reference-dynamodb.html#js-aws-appsync-resolver-reference-dynamodb-getitem) - The `GetItem` request lets you tell the AWS AppSync DynamoDB function to make a `GetItem` request to DynamoDB, and enables you to specify:
482482
483483
- The key of the item in DynamoDB
484-
485484
- Whether to use a consistent read or not
486485
487486
**Example:**
488487
489488
```js
490489
export function request(ctx) {
491-
const {foo, bar} = ctx.args
490+
const { foo, bar } = ctx.args;
492491
return {
493-
operation : "GetItem",
494-
key : util.dynamodb.toMapValues({foo, bar}),
495-
consistentRead : true
496-
}
492+
operation: 'GetItem',
493+
key: util.dynamodb.toMapValues({ foo, bar }),
494+
consistentRead: true
495+
};
497496
}
498497
```
499498
@@ -502,21 +501,20 @@ export function request(ctx) {
502501
[PutItem](https://docs.aws.amazon.com/appsync/latest/devguide/js-resolver-reference-dynamodb.html#js-aws-appsync-resolver-reference-dynamodb-putitem) - The `PutItem` request mapping document lets you tell the AWS AppSync DynamoDB function to make a `PutItem` request to DynamoDB, and enables you to specify the following:
503502
504503
- The key of the item in DynamoDB
505-
506504
- The full contents of the item (composed of key and attributeValues)
507-
508505
- Conditions for the operation to succeed
509506
510507
**Example:**
511508
512509
```js
513510
import { util } from '@aws-appsync/utils';
511+
514512
export function request(ctx) {
515-
const { foo, bar, ...values} = ctx.args
513+
const { foo, bar, ...values } = ctx.args;
516514
return {
517515
operation: 'PutItem',
518-
key: util.dynamodb.toMapValues({foo, bar}),
519-
attributeValues: util.dynamodb.toMapValues(values),
516+
key: util.dynamodb.toMapValues({ foo, bar }),
517+
attributeValues: util.dynamodb.toMapValues(values)
520518
};
521519
}
522520
```
@@ -526,15 +524,14 @@ export function request(ctx) {
526524
[UpdateItem](https://docs.aws.amazon.com/appsync/latest/devguide/js-resolver-reference-dynamodb.html#js-aws-appsync-resolver-reference-dynamodb-updateitem) - The `UpdateItem` request enables you to tell the AWS AppSync DynamoDB function to make a `UpdateItem` request to DynamoDB and allows you to specify the following:
527525
528526
- The key of the item in DynamoDB
529-
530527
- An update expression describing how to update the item in DynamoDB
531-
532528
- Conditions for the operation to succeed
533529
534530
**Example:**
535531
536532
```js
537533
import { util } from '@aws-appsync/utils';
534+
538535
export function request(ctx) {
539536
const { id } = ctx.args;
540537
return {
@@ -543,8 +540,8 @@ export function request(ctx) {
543540
update: {
544541
expression: 'ADD #voteField :plusOne, version :plusOne',
545542
expressionNames: { '#voteField': 'upvotes' },
546-
expressionValues: { ':plusOne': { N: 1 } },
547-
},
543+
expressionValues: { ':plusOne': { N: 1 } }
544+
}
548545
};
549546
}
550547
```
@@ -554,17 +551,17 @@ export function request(ctx) {
554551
[DeleteItem](https://docs.aws.amazon.com/appsync/latest/devguide/js-resolver-reference-dynamodb.html#js-aws-appsync-resolver-reference-dynamodb-deleteitem) - The `DeleteItem` request lets you tell the AWS AppSync DynamoDB function to make a `DeleteItem` request to DynamoDB, and enables you to specify the following:
555552
556553
- The key of the item in DynamoDB
557-
558554
- Conditions for the operation to succeed
559555
560556
**Example:**
561557
562558
```js
563559
import { util } from '@aws-appsync/utils';
560+
564561
export function request(ctx) {
565562
return {
566563
operation: 'DeleteItem',
567-
key: util.dynamodb.toMapValues({ id: ctx.args.id }),
564+
key: util.dynamodb.toMapValues({ id: ctx.args.id })
568565
};
569566
}
570567
```
@@ -574,17 +571,11 @@ export function request(ctx) {
574571
[Query](https://docs.aws.amazon.com/appsync/latest/devguide/js-resolver-reference-dynamodb.html#js-aws-appsync-resolver-reference-dynamodb-query) - The Query request object lets you tell the AWS AppSync DynamoDB resolver to make a Query request to DynamoDB, and enables you to specify the following:
575572
576573
- Key expression
577-
578574
- Which index to use
579-
580575
- Any additional filter
581-
582576
- How many items to return
583-
584577
- Whether to use consistent reads
585-
586578
- query direction (forward or backward)
587-
588579
- Pagination token
589580
590581
**Example:**
@@ -598,9 +589,9 @@ export function request(ctx) {
598589
operation: 'Query',
599590
query: {
600591
expression: 'ownerId = :ownerId',
601-
expressionValues: util.dynamodb.toMapValues({ ':ownerId': owner }),
592+
expressionValues: util.dynamodb.toMapValues({ ':ownerId': owner })
602593
},
603-
index: 'owner-index',
594+
index: 'owner-index'
604595
};
605596
}
606597
```
@@ -609,15 +600,10 @@ export function request(ctx) {
609600
[Scan](https://docs.aws.amazon.com/appsync/latest/devguide/js-resolver-reference-dynamodb.html#js-aws-appsync-resolver-reference-dynamodb-scan) - The `Scan` request lets you tell the AWS AppSync DynamoDB function to make a `Scan` request to DynamoDB, and enables you to specify the following:
610601
611602
- A filter to exclude results
612-
613603
- Which index to use
614-
615604
- How many items to return
616-
617605
- Whether to use consistent reads
618-
619606
- Pagination token
620-
621607
- Parallel scans
622608
623609
**Example:**

src/pages/[platform]/build-a-backend/data/mutate-data/index.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Before you begin, you will need:
4141

4242
You can create an item by first generating the Data client with your backend Data schema. Then you can add an item:
4343

44-
```js
44+
```ts
4545
import { generateClient } from 'aws-amplify/data';
4646
import { type Schema } from '../amplify/data/resource'
4747

@@ -238,7 +238,7 @@ Future<void> createTodo() async {
238238

239239
To update the item, use the `update` function:
240240

241-
```js
241+
```ts
242242
import { generateClient } from 'aws-amplify/data';
243243
import { type Schema } from '../amplify/data/resource';
244244

@@ -395,7 +395,7 @@ Future<void> deleteTodoById(Todo todoToDelete) async {
395395
You can cancel any mutation API request by calling `.cancel` on the mutation request promise that's returned by `.create(...)`, `.update(...)`, or `.delete(...)`.
396396

397397
```ts
398-
const promise = client.models.Todo.create({ content: 'New Todo ' });
398+
const promise = client.models.Todo.create({ content: 'New Todo' });
399399
// ^ Note: we're not awaiting the request, we're returning the promise
400400

401401
try {

src/pages/[platform]/build-a-backend/data/override-resources/index.mdx

+21-20
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,53 @@ Amplify GraphQL API uses a variety of auto-generated, underlying AWS services an
3434

3535
In your Amplify app, you can access every underlying resource using CDK ["L2"](https://docs.aws.amazon.com/cdk/v2/guide/constructs.html#constructs_using) or ["L1"](https://docs.aws.amazon.com/cdk/v2/guide/constructs.html#constructs_l1_using) constructs. Access the generated resources as L2 constructs via the `.resources` property on the returned stack or access the generated resources as L1 constructs using the `.resources.cfnResources` property.
3636

37-
```ts
37+
```ts title="amplify/backend.ts"
3838
import { defineBackend } from '@aws-amplify/backend';
3939
import { data } from './data/resource';
4040

4141
const backend = defineBackend({
4242
data
4343
});
4444

45-
const dataResources = backend.data.resources;
45+
const { cfnResources } = backend.data.resources;
4646

47-
Object.values(dataResources.cfnResources.amplifyDynamoDbTables).forEach((table) => {
47+
for (const table of Object.values(cfnResources.amplifyDynamoDbTables)) {
4848
table.pointInTimeRecoveryEnabled = true;
49-
});
49+
}
5050
```
5151

5252
## Customize Amplify-generated AppSync GraphQL API resources
5353

5454
Apply all the customizations on `backend.data.resources.graphqlApi` or `backend.data.resources.cfnResources.cfnGraphqlApi`. For example, to enable X-Ray tracing for the AppSync GraphQL API:
5555

56-
```ts
56+
```ts title="amplify/backend.ts"
5757
import { defineBackend } from '@aws-amplify/backend';
5858
import { data } from './data/resource';
5959

6060
const backend = defineBackend({
6161
data
6262
});
6363

64-
const dataResources = backend.data.resources;
64+
const { cfnResources } = backend.data.resources;
6565

66-
dataResources.cfnResources.cfnGraphqlApi.xrayEnabled = true;
66+
cfnResources.cfnGraphqlApi.xrayEnabled = true;
6767
```
6868

6969
## Customize Amplify-generated resources for data models
7070

7171
Pass in the model type name into `backend.data.resources.amplifyDynamoDbTables["MODEL_NAME"]` to modify the resources generated for that particular model type. For example, to enable time-to-live on the Todo `@model` type's DynamoDB table:
7272

73-
```ts
73+
```ts title="amplify/backend.ts"
7474
import { defineBackend } from '@aws-amplify/backend';
7575
import { data } from './data/resource';
7676

7777
const backend = defineBackend({
7878
data
7979
});
8080

81-
const dataResources = backend.data.resources;
81+
const { cfnResources } = backend.data.resources;
8282

83-
dataResources.cfnResources.amplifyDynamoDbTables["Todo"].timeToLiveAttribute = {
83+
cfnResources.amplifyDynamoDbTables["Todo"].timeToLiveAttribute = {
8484
attributeName: "ttl",
8585
enabled: true,
8686
};
@@ -90,34 +90,35 @@ dataResources.cfnResources.amplifyDynamoDbTables["Todo"].timeToLiveAttribute = {
9090

9191
Set the [DynamoDB billing mode](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-billingmode) for the DynamoDB table as either "PROVISIONED" or "PAY_PER_REQUEST".
9292

93-
```ts
93+
```ts title="amplify/backend.ts"
9494
import { defineBackend } from '@aws-amplify/backend';
95-
import { data } from './data/resource';
9695
import { BillingMode } from "aws-cdk-lib/aws-dynamodb";
96+
import { data } from './data/resource';
9797

9898
const backend = defineBackend({
9999
data
100100
});
101-
const dataResources = backend.data.resources;
102101

103-
dataResources.cfnResources.amplifyDynamoDbTables['Todo'].billingMode = BillingMode.PAY_PER_REQUEST;
102+
const { cfnResources } = backend.data.resources;
103+
104+
cfnResources.amplifyDynamoDbTables['Todo'].billingMode = BillingMode.PAY_PER_REQUEST;
104105
```
105106

106107
### Example - Configure provisioned throughput for a DynamoDB table
107108

108109
Override the default [ProvisionedThroughput](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-provisionedthroughput) provisioned for each model table and its Global Secondary Indexes (GSI). This override is only valid if the "DynamoDBBillingMode" is set to "PROVISIONED".
109110

110-
```ts
111+
```ts title="amplify/backend.ts"
111112
import { defineBackend } from '@aws-amplify/backend';
112113
import { data } from './data/resource';
113114

114115
const backend = defineBackend({
115116
data
116117
});
117118

118-
const dataResources = backend.data.resources;
119+
const { cfnResources } = backend.data.resources;
119120

120-
dataResources.cfnResources.amplifyDynamoDbTables["Todo"].provisionedThroughput = {
121+
cfnResources.amplifyDynamoDbTables["Todo"].provisionedThroughput = {
121122
readCapacityUnits: 5,
122123
writeCapacityUnits: 5,
123124
};
@@ -127,15 +128,15 @@ dataResources.cfnResources.amplifyDynamoDbTables["Todo"].provisionedThroughput =
127128

128129
Enable/disable [DynamoDB point-in-time recovery](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-pointintimerecoveryspecification.html) for each model table.
129130

130-
```ts
131+
```ts title="amplify/backend.ts"
131132
import { defineBackend } from '@aws-amplify/backend';
132133
import { data } from './data/resource';
133134

134135
const backend = defineBackend({
135136
data
136137
});
137138

138-
const dataResources = backend.data.resources;
139+
const { cfnResources } = backend.data.resources;
139140

140-
dataResources.cfnResources.amplifyDynamoDbTables['Todo'].pointInTimeRecoveryEnabled = true;
141+
cfnResources.amplifyDynamoDbTables['Todo'].pointInTimeRecoveryEnabled = true;
141142
```

0 commit comments

Comments
 (0)