requireImportFragment
| Property | Value |
|---|---|
| Config name | requireImportFragment |
| Default severity | — |
| Context | Document |
| In recommended | No |
What it checks
Section titled “What it checks”Requires that fragment spreads referencing fragments defined in other files have a corresponding import comment. This makes cross-file fragment dependencies explicit rather than relying on implicit global resolution.
Fragments defined in the same document do not require an import comment.
The expected import syntax is:
# import FragmentName from "path/to/file.graphql"Multiple fragments can be imported from the same file using comma-separated names:
# import FragmentA, FragmentB from "path/to/file.graphql"Examples
Section titled “Examples”# ⚠️ Warning — fragment used without importquery GetUser { user { ...UserFields # Warning: Fragment 'UserFields' is used without a corresponding import comment }}# ✅ Good — fragment imported explicitly# import UserFields from "fragments/user.graphql"query GetUser { user { ...UserFields }}# ✅ Good — locally defined fragment needs no importfragment UserFields on User { id name}
query GetUser { user { ...UserFields }}Configuration
Section titled “Configuration”# Enable the ruleextensions: graphql-analyzer: lint: rules: requireImportFragment: warn
# Or as an errorextensions: graphql-analyzer: lint: rules: requireImportFragment: error