graphql-tools-monorepo / import/src / PathAliases
Interface: PathAliases
import/src.PathAliases
Configuration for path aliasing in GraphQL import statements using the same syntax as tsconfig.json#paths
Table of contents
Properties
Properties
mappings
• mappings: Record<string, string>
A map of path aliases to their corresponding file system paths. Keys are the aliases used in import statements, values are the paths they resolve to.
Supports two patterns:
-
Exact mapping: Maps a specific alias to a specific file
'@user': '/path/to/user.graphql' -
Wildcard mapping: Maps a prefix pattern to a directory pattern using '' 2a. The '' is replaced with the remainder of the import path
'@models/*': '/path/to/models/*'2b. Maps to a directory without wildcard expansion'@types/*': '/path/to/types'
Example
{
mappings: {
// Exact mapping
'@schema': '/project/schema/main.graphql',
// Wildcard mapping with expansion
'@models/*': '/project/graphql/models/*',
// Wildcard mapping without expansion
'@types/*': '/project/graphql/types.graphql',
// Relative paths (resolved against rootDir if specified)
'@common': './common/types.graphql'
}
}Import examples:
#import User from "@schema"→/project/schema/main.graphql#import User from "@models/user.graphql"→/project/graphql/models/user.graphql#import User from "@types/user.graphql"→/project/graphql/types.graphql#import User from "@common"→ Resolved relative to rootDir
Defined in
packages/import/src/index.ts:127
rootDir
• Optional rootDir: string
Root directory for resolving relative paths in mappings. Defaults to the current working directory.
Example
{
rootDir: '/project/src/graphql',
mappings: {
'@types': './types' // Will resolve to '/project/src/graphql/types'
}
}