运行时系统实用程序
runtime 库提供一些实用程序以控制或修改解析器和函数的运行时属性。
运行时系统实用程序列表
-
runtime.earlyReturn(obj?: unknown, returnOptions?: {skipTo: 'END' | 'NEXT'}): never -
调用该函数将停止执行当前处理程序,即 Amazon AppSync 函数或解析器(单位解析器或管道解析器),具体取决于当前上下文。将返回指定的对象以作为结果。
-
在 Amazon AppSync 函数请求处理程序中调用时,将跳过数据来源和响应处理程序,并调用下一个函数请求处理程序(如果这是最后一个 Amazon AppSync 函数,则调用管道解析器响应处理程序)。
-
在 Amazon AppSync 管道解析器请求处理程序中调用时,将跳过管道执行,并立即调用管道解析器响应处理程序。
-
如果在
skipTo设置为“END”时返回了returnOptions,则会跳过管道执行,并立即调用管道解析器响应处理程序。 -
如果在
skipTo设置为“NEXT”时返回了returnOptions,则会跳过函数执行,并调用下一个管道处理程序。
示例:
import { runtime } from '@aws-appsync/utils' export function request(ctx) { runtime.earlyReturn({ hello: 'world' }) // code below is not executed return ctx.args } // never called because request returned early export function response(ctx) { return ctx.result } -