本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
支援的執行時間功能
以下各節說明 APPSYNC_JS 執行時間的支援功能集。
核心功能
支援下列核心功能。
- Types
-
以下是支援的類型:
-
數字
-
字串
-
布林值
-
objects
-
陣列
-
函數
-
- Operators
-
支援運算子,包括:
-
標準數學運算子 (
+、-、/%、、*等) -
nullish coalescing 運算子 (
??) -
選用鏈結 (
?.) -
位元運算子
-
void和typeof運算子 -
分散運算子 (
...)
不支援下列運算子:
-
統一運算子 (
++、--和~) -
in運算子注意
使用
Object.hasOwn運算子來檢查指定的屬性是否位於指定的物件中。
-
- Statements
-
支援下列陳述式:
-
const -
let -
var -
break -
else -
for-in -
for-of -
if -
return -
switch -
分散語法
不支援下列項目:
-
catch -
continue -
do-while -
finally -
for(initialization; condition; afterthought)注意
支援的例外是
for-in和for-of表達式。 -
throw -
try -
while -
標籤陳述式
-
- Literals
-
支援下列 ES 6 範本常值
: -
多行字串
-
表達式插補
-
巢狀化範本
-
- Functions
-
支援下列函數語法:
-
支援函數宣告。
-
支援 ES 6 箭頭函數。
-
支援 ES 6 靜態參數語法。
-
- Strict mode
-
函數按預設會在嚴格模式下運作,因此您不需要在函數程式碼中新增
use_strict陳述式。無法對此進行變更。
基本物件
支援 ES 及其函數的下列基本物件。
- Object
-
支援下列物件:
-
Object.assign() -
Object.entries() -
Object.hasOwn() -
Object.keys() -
Object.values() -
delete
-
- String
-
支援下列字串:
-
String.prototype.length() -
String.prototype.charAt() -
String.prototype.concat() -
String.prototype.endsWith() -
String.prototype.indexOf() -
String.prototype.lastIndexOf() -
String.raw() -
String.prototype.replace()注意
不支援規則運算式。
不過,提供的參數中支援 Java 樣式的規則表達式建構。如需詳細資訊,請參閱模式
。 -
String.prototype.replaceAll()注意
不支援規則運算式。
不過,提供的參數中支援 Java 樣式的規則表達式建構。如需詳細資訊,請參閱模式
。 -
String.prototype.slice() -
String.prototype.split() -
String.prototype.startsWith() -
String.prototype.toLowerCase() -
String.prototype.toUpperCase() -
String.prototype.trim() -
String.prototype.trimEnd() -
String.prototype.trimStart()
-
- Number
-
支援下列號碼:
-
Number.isFinite -
Number.isNaN
-
內建物件和函數
支援下列函數和物件。
- Math
-
支援下列數學函數:
-
Math.random() -
Math.min() -
Math.max() -
Math.round() -
Math.floor() -
Math.ceil()
-
- Array
-
支援下列陣列方法:
-
Array.prototype.length -
Array.prototype.concat() -
Array.prototype.fill() -
Array.prototype.flat() -
Array.prototype.indexOf() -
Array.prototype.join() -
Array.prototype.lastIndexOf() -
Array.prototype.pop() -
Array.prototype.push() -
Array.prototype.reverse() -
Array.prototype.shift() -
Array.prototype.slice() -
Array.prototype.sort()注意
Array.prototype.sort()不支援引數。 -
Array.prototype.splice() -
Array.prototype.unshift() -
Array.prototype.forEach() -
Array.prototype.map() -
Array.prototype.flatMap() -
Array.prototype.filter() -
Array.prototype.reduce() -
Array.prototype.reduceRight() -
Array.prototype.find() -
Array.prototype.some() -
Array.prototype.every() -
Array.prototype.findIndex() -
Array.prototype.findLast() -
Array.prototype.findLastIndex() -
delete
-
- Console
-
主控台物件可用於偵錯。在即時查詢執行期間,主控台日誌/錯誤陳述式會傳送至 Amazon CloudWatch Logs (如果啟用記錄)。使用 進行程式碼評估期間
evaluateCode,日誌陳述式會在命令回應中傳回。-
console.error() -
console.log()
-
- Function
-
-
不支援
bind、apply和call方法。 -
不支援函數建構子。
-
不支援將函數做為引數傳遞。
-
不支援遞迴函數呼叫。
-
- JSON
-
支援下列 JSON 方法:
-
JSON.parse()注意
如果剖析的字串不是有效的 JSON,則傳回空白字串。
-
JSON.stringify()
-
- Promises
-
不支援非同步程序,也不支援 promise。
注意
在 in.
APPSYNC_JS執行時間內不支援網路和檔案系統存取 AWS AppSync。 會根據 AWS AppSync 解析程式或 AWS AppSync 函數提出的請求 AWS AppSync 來處理所有 I/O 操作。
全域變數
支援以下全局常數:
-
NaN -
Infinity -
undefined
錯誤類型
throw 不支援使用 擲回錯誤。您可以使用 util.error()函數傳回錯誤。您可以使用 util.appendError函數在 GraphQL 回應中包含錯誤。
如需詳細資訊,請參閱錯誤 utils。