AppSync
CLASS | DESCRIPTION |
---|---|
AppSyncResolver |
AppSync GraphQL API Resolver |
AppSyncResolver ¶
AppSyncResolver()
Bases: Router
AppSync GraphQL API Resolver
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
METHOD | DESCRIPTION |
---|---|
batch_resolver |
Registers batch resolver function for GraphQL type and field name. |
exception_handler |
A decorator function that registers a handler for one or more exception types. |
include_router |
Adds all resolvers defined in a router |
resolve |
Resolves the response based on the provide event and decorator routes |
resolver |
Registers direct resolver function for GraphQL type and field name. |
Source code in aws_lambda_powertools/event_handler/appsync.py
50 51 52 53 54 55 56 |
|
batch_resolver ¶
batch_resolver(
type_name: str = "*",
field_name: str | None = None,
raise_on_error: bool = False,
aggregate: bool = True,
) -> Callable
Registers batch resolver function for GraphQL type and field name.
By default, we handle errors gracefully by returning None
. If you want
to short-circuit and fail the entire batch use raise_on_error=True
.
PARAMETER | DESCRIPTION |
---|---|
type_name
|
GraphQL type e.g., Query, Mutation, by default "*" meaning any
TYPE:
|
field_name
|
GraphQL field e.g., getTodo, createTodo, by default None
TYPE:
|
raise_on_error
|
Whether to fail entire batch upon error, or handle errors gracefully (None), by default False
TYPE:
|
aggregate
|
A flag indicating whether the batch items should be processed at once or individually. If True (default), the batch resolver will process all items in the batch as a single event. If False, the batch resolver will process each item in the batch individually.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
Registered resolver |
Source code in aws_lambda_powertools/event_handler/appsync.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
exception_handler ¶
exception_handler(
exc_class: type[Exception] | list[type[Exception]],
)
A decorator function that registers a handler for one or more exception types.
PARAMETER | DESCRIPTION |
---|---|
exc_class
|
A single exception type or a list of exception types. |
RETURNS | DESCRIPTION |
---|---|
Callable
|
A decorator function that registers the exception handler. |
Source code in aws_lambda_powertools/event_handler/appsync.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
|
include_router ¶
include_router(router: Router) -> None
Adds all resolvers defined in a router
PARAMETER | DESCRIPTION |
---|---|
router
|
A router containing a dict of field resolvers
TYPE:
|
Source code in aws_lambda_powertools/event_handler/appsync.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
resolve ¶
resolve(
event: dict | list[dict],
context: LambdaContext,
data_model: type[
AppSyncResolverEvent
] = AppSyncResolverEvent,
) -> Any
Resolves the response based on the provide event and decorator routes
PARAMETER | DESCRIPTION |
---|---|
event
|
Lambda event either coming from batch processing endpoint or from standard processing endpoint |
context
|
Lambda context
TYPE:
|
data_model
|
Your data data_model to decode AppSync event, by default AppSyncResolverEvent
TYPE:
|
Example
1 2 3 4 5 6 7 8 9 |
|
Bringing custom models
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
RETURNS | DESCRIPTION |
---|---|
Any
|
Returns the result of the resolver |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If we could not find a field resolver |
Source code in aws_lambda_powertools/event_handler/appsync.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
resolver ¶
resolver(
type_name: str = "*", field_name: str | None = None
) -> Callable
Registers direct resolver function for GraphQL type and field name.
PARAMETER | DESCRIPTION |
---|---|
type_name
|
GraphQL type e.g., Query, Mutation, by default "*" meaning any
TYPE:
|
field_name
|
GraphQL field e.g., getTodo, createTodo, by default None
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Callable
|
Registered resolver |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Source code in aws_lambda_powertools/event_handler/appsync.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|