DEV Community

Alexander
Alexander

Posted on

Today I learned: appsync and description fields.

TLDR

Appsync does not support triple quotes description.
Install eslint and plugins:

npm install -D eslint eslint-plugin-graphql
Enter fullscreen mode Exit fullscreen mode

Add to your eslint settings =>

"overrides": [
    {
      "files": ["schema.graphql"],
      "extends": "plugin:@graphql-eslint/schema-recommended",
      "rules": {
        "@graphql-eslint/description-style": [1,{"style": "inline"}],
        "@graphql-eslint/no-hashtag-description": 0
      }
    }
  ]
Enter fullscreen mode Exit fullscreen mode

Add to parser options

"parserOptions": {
    "schema": ["./schema.graphql"]//  <= ADD THIS LINE
  },
Enter fullscreen mode Exit fullscreen mode

Appsync and description fields

Appsync does not recognize modern field descriptions in GraphQL schema. For example, it does not recognize triple quotes.

  """
  This is usename description! BUT APPSYNC does not catch this description
  """
  name: String!
Enter fullscreen mode Exit fullscreen mode

Coming to the rescue, I installed the ESLint plugin, which can check descriptions.

npm install -D eslint eslint-plugin-graphql
Enter fullscreen mode Exit fullscreen mode

Create file .eslintrc.json with eslint settings in root directory. With this content

{
  "env": {
    "browser": false,
    "es6": true,
    "node": true
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "tsconfig.json",
    "sourceType": "module",
    "schema": ["./schema.graphql"],
    "ecmaVersion": 2022
  },
  "plugins": ["@typescript-eslint", "jest", "prettier","unicorn","json-format"],
  "extends": [
    "eslint:recommended"
  ],
  "overrides": [
    {
      "files": ["schema.graphql"],
      "extends": "plugin:@graphql-eslint/schema-recommended",
      "rules": {
        "@graphql-eslint/description-style": [1,{"style": "inline"}],
        "@graphql-eslint/no-hashtag-description": 0,
        "@graphql-eslint/require-description": 0
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

The most important part of overriding this row

"@graphql-eslint/description-style": [1,{"style": "inline"}],
Enter fullscreen mode Exit fullscreen mode

And this

"@graphql-eslint/no-hashtag-description": 0,
Enter fullscreen mode Exit fullscreen mode
"overrides": [
    {
      "files": ["schema.graphql"],
      "extends": "plugin:@graphql-eslint/schema-recommended",
      "rules": {
        "@graphql-eslint/description-style": [1,{"style": "inline"}],
        "@graphql-eslint/no-hashtag-description": 0,
        "@graphql-eslint/no-unreachable-types": 0,
        "@graphql-eslint/strict-id-in-types": 0,
        "@graphql-eslint/no-typename-prefix": 0,
        "@graphql-eslint/naming-convention": 0,
        "@graphql-eslint/require-description": 0
      }
    }
  ]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)