Configuring utilities for the APPSYNC_JS
runtime
Amazon AppSync provides two libraries that aid in the development of resolvers with the APPSYNC_JS
runtime:
-
@aws-appsync/eslint-plugin- Catches and fixes problems quickly during development. -
@aws-appsync/utils- Provides type validation and autocompletion in code editors.
Configuring the eslint plugin
ESLint@aws-appsync/eslint-plugin is an ESLint plugin that catches invalid syntax in your code when
leveraging the APPSYNC_JS runtime. The plugin allows you to quickly get feedback about your
code during development without having to push your changes to the cloud.
@aws-appsync/eslint-plugin provides two rule sets that you can use during development.
"plugin:@aws-appsync/base" configures a base set of rules that you can leverage in your project:
| Rule | Description |
|---|---|
| no-async | Async processes and promises are not supported. |
| no-await | Async processes and promises are not supported. |
| no-classes | Classes are not supported. |
| no-for | for is not supported (except for for-in and for-of,
which are supported) |
| no-continue | continue is not supported. |
| no-generators | Generators are not supported. |
| no-yield | yield is not supported. |
| no-labels | Labels are not supported. |
| no-this | this keyword is not supported. |
| no-try | Try/catch structure is not supported. |
| no-while | While loops are not supported. |
| no-disallowed-unary-operators | ++, --, and ~ unary operators are not
allowed. |
| no-disallowed-binary-operators | The instanceof operator is not allowed. |
| no-promise | Async processes and promises are not supported. |
"plugin:@aws-appsync/recommended" provides some additional rules but also requires you to add TypeScript configurations to your project.
| Rule | Description |
|---|---|
| no-recursion | Recursive function calls are not allowed. |
| no-disallowed-methods | Some methods are not allowed. See the reference for a full set of supported built-in functions. |
| no-function-passing | Passing functions as function arguments to functions is not allowed. |
| no-function-reassign | Functions cannot be reassigned. |
| no-function-return | Functions cannot be the return value of functions. |
To add the plugin to your project, follow the installation and usage steps at Getting Started
with ESLint
$ npm install @aws-appsync/eslint-plugin
In your .eslintrc.{js,yml,json} file, add "plugin:@aws-appsync/base" or "plugin:@aws-appsync/recommended" to the extends property. The snippet below is
a basic sample .eslintrc configuration for JavaScript:
{ "extends": ["plugin:@aws-appsync/base"] }
To use the "plugin:@aws-appsync/recommended" rule set, install the required dependency:
$ npm install -D @typescript-eslint/parser
Then, create an .eslintrc.js file:
{ "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2018, "project": "./tsconfig.json" }, "extends": ["plugin:@aws-appsync/recommended"] }