Skip to content

Commit f985c40

Browse files
DanyC97heitorlessa
andauthored
docs: consistency around admonitions and snippets (aws-powertools#919)
Co-authored-by: heitorlessa <[email protected]>
1 parent 8fb467e commit f985c40

17 files changed

+1860
-2017
lines changed

Diff for: docs/core/event_handler/api_gateway.md

+284-290
Large diffs are not rendered by default.

Diff for: docs/core/event_handler/appsync.md

+51-53
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ You must have an existing AppSync GraphQL API and IAM permissions to invoke your
2727

2828
This is the sample infrastructure we are using for the initial examples with a AppSync Direct Lambda Resolver.
2929

30-
=== "schema.graphql"
30+
???+ tip "Tip: Designing GraphQL Schemas for the first time?"
31+
Visit [AWS AppSync schema documentation](https://docs.aws.amazon.com/appsync/latest/devguide/designing-your-schema.html){target="_blank"} for understanding how to define types, nesting, and pagination.
3132

32-
!!! tip "Designing GraphQL Schemas for the first time?"
33-
Visit [AWS AppSync schema documentation](https://docs.aws.amazon.com/appsync/latest/devguide/designing-your-schema.html){target="_blank"} for understanding how to define types, nesting, and pagination.
33+
=== "schema.graphql"
3434

3535
```typescript
3636
--8<-- "docs/shared/getting_started_schema.graphql"
@@ -176,7 +176,8 @@ You can define your functions to match GraphQL types and fields with the `app.re
176176

177177
Here's an example where we have two separate functions to resolve `getTodo` and `listTodos` fields within the `Query` type. For completion, we use Scalar type utilities to generate the right output based on our schema definition.
178178

179-
!!! info "GraphQL arguments are passed as function arguments"
179+
???+ info
180+
GraphQL arguments are passed as function arguments.
180181

181182
=== "app.py"
182183

@@ -395,69 +396,65 @@ You can nest `app.resolver()` decorator multiple times when resolving fields wit
395396

396397
For Lambda Python3.8+ runtime, this utility supports async functions when you use in conjunction with `asyncio.run`.
397398

398-
=== "async_resolver.py"
399-
400-
```python hl_lines="4 8 10-12 20"
401-
from aws_lambda_powertools import Logger, Tracer
399+
```python hl_lines="4 8 10-12 20" title="Resolving GraphQL resolvers async"
400+
from aws_lambda_powertools import Logger, Tracer
402401

403-
from aws_lambda_powertools.logging import correlation_paths
404-
from aws_lambda_powertools.event_handler import AppSyncResolver
402+
from aws_lambda_powertools.logging import correlation_paths
403+
from aws_lambda_powertools.event_handler import AppSyncResolver
405404

406-
tracer = Tracer(service="sample_resolver")
407-
logger = Logger(service="sample_resolver")
408-
app = AppSyncResolver()
405+
tracer = Tracer(service="sample_resolver")
406+
logger = Logger(service="sample_resolver")
407+
app = AppSyncResolver()
409408

410-
@app.resolver(type_name="Query", field_name="listTodos")
411-
async def list_todos():
412-
todos = await some_async_io_call()
413-
return todos
409+
@app.resolver(type_name="Query", field_name="listTodos")
410+
async def list_todos():
411+
todos = await some_async_io_call()
412+
return todos
414413

415-
@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER)
416-
@tracer.capture_lambda_handler
417-
def lambda_handler(event, context):
418-
result = app.resolve(event, context)
414+
@logger.inject_lambda_context(correlation_id_path=correlation_paths.APPSYNC_RESOLVER)
415+
@tracer.capture_lambda_handler
416+
def lambda_handler(event, context):
417+
result = app.resolve(event, context)
419418

420-
return asyncio.run(result)
421-
```
419+
return asyncio.run(result)
420+
```
422421

423422
### Amplify GraphQL Transformer
424423

425424
Assuming you have [Amplify CLI installed](https://docs.amplify.aws/cli/start/install){target="_blank"}, create a new API using `amplify add api` and use the following GraphQL Schema.
426425

427426
<!-- AppSync resolver decorator is a concise way to create lambda functions to handle AppSync resolvers for multiple `typeName` and `fieldName` declarations. -->
428427

429-
=== "schema.graphql"
430-
431-
```typescript hl_lines="7 15 20 22"
432-
@model
433-
type Merchant {
434-
id: String!
435-
name: String!
436-
description: String
437-
# Resolves to `common_field`
438-
commonField: String @function(name: "merchantInfo-${env}")
439-
}
440-
441-
type Location {
442-
id: ID!
443-
name: String!
444-
address: String
445-
# Resolves to `common_field`
446-
commonField: String @function(name: "merchantInfo-${env}")
447-
}
448-
449-
type Query {
450-
# List of locations resolves to `list_locations`
451-
listLocations(page: Int, size: Int): [Location] @function(name: "merchantInfo-${env}")
452-
# List of locations resolves to `list_locations`
453-
findMerchant(search: str): [Merchant] @function(name: "searchMerchant-${env}")
454-
}
455-
```
428+
```typescript hl_lines="7 15 20 22" title="Example GraphQL Schema"
429+
@model
430+
type Merchant {
431+
id: String!
432+
name: String!
433+
description: String
434+
# Resolves to `common_field`
435+
commonField: String @function(name: "merchantInfo-${env}")
436+
}
437+
438+
type Location {
439+
id: ID!
440+
name: String!
441+
address: String
442+
# Resolves to `common_field`
443+
commonField: String @function(name: "merchantInfo-${env}")
444+
}
445+
446+
type Query {
447+
# List of locations resolves to `list_locations`
448+
listLocations(page: Int, size: Int): [Location] @function(name: "merchantInfo-${env}")
449+
# List of locations resolves to `list_locations`
450+
findMerchant(search: str): [Merchant] @function(name: "searchMerchant-${env}")
451+
}
452+
```
456453

457454
[Create two new basic Python functions](https://docs.amplify.aws/cli/function#set-up-a-function){target="_blank"} via `amplify add function`.
458455

459-
!!! note "Amplify CLI generated functions use `Pipenv` as a dependency manager"
460-
Your function source code is located at **`amplify/backend/function/your-function-name`**.
456+
???+ note
457+
Amplify CLI generated functions use `Pipenv` as a dependency manager. Your function source code is located at **`amplify/backend/function/your-function-name`**.
461458

462459
Within your function's folder, add Lambda Powertools as a dependency with `pipenv install aws-lambda-powertools`.
463460

@@ -713,7 +710,8 @@ You can subclass `AppSyncResolverEvent` to bring your own set of methods to hand
713710

714711
### Split operations with Router
715712

716-
!!! tip "Read the **[considerations section for trade-offs between monolithic and micro functions](./api_gateway.md#considerations){target="_blank"}**, as it's also applicable here."
713+
???+ tip
714+
Read the **[considerations section for trade-offs between monolithic and micro functions](./api_gateway.md#considerations){target="_blank"}**, as it's also applicable here.
717715

718716
As you grow the number of related GraphQL operations a given Lambda function should handle, it is natural to split them into separate files to ease maintenance - That's where the `Router` feature is useful.
719717

0 commit comments

Comments
 (0)