Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__tests__
.npmignore
LICENSE
README.md
index.js
package.json
readFileSync.js

README.md

ESLint plugin relay-imports

ESLint plugin to check Flow type imports from files generated by the Relay Compiler

Why to use

As described in Relay issue #2539, when you mistype an import from these files, Flow doesn't report any error. Your code then looks strongly typed, but in fact it is typed with any.

Typically this happens during refactoring, when you rename a fragment, but forget to update also the import statement.

Installation

  1. Install the package
    • either with Yarn: yarn add --dev eslint-plugin-relay-imports
    • or with NPM: npm i --save-dev eslint-plugin-relay-imports
  2. Add to your .eslintrc:
    {
      "extends": [
        "plugin:relay-imports/recommended"
      ],
      "plugins": [
        "relay-imports"
      ],
    }
    

Rules

no-values

This rule disallows value imports from __generated__. Typically you want to import only types from these files.

Examples of incorrect code:

import { Kiwi } from './__generated__/Kiwi.graphql';
import Kiwi from './__generated__/Kiwi.graphql';

Examples of correct code:

import type { Kiwi } from './__generated__/Kiwi.graphql';
import { type Kiwi } from './__generated__/Kiwi.graphql';

type-must-exist

This rule checks that the type is explicitly exported from the generated file.

Example of incorrect code:

// given the file Kiwi_data.graphql.js doesn't export type Banana_data
import type { Banana_data } from './__generated__/Kiwi_data.graphql';

Example of correct code:

// given the file Kiwi_data.graphql.js exports type Kiwi_data
import type { Kiwi_data } from './__generated__/Kiwi_data.graphql';
You can’t perform that action at this time.