-
-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84dea54
commit 0f87872
Showing
6 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: ECMAScript Modules | ||
--- | ||
|
||
Since `v2.0.0` release, TypeGraphQL is compatible with ECMAScript modules. | ||
|
||
Thanks to this, we can `import` the `type-graphql` package in the ESM projects without any hassle. | ||
|
||
## TypeScript configuration | ||
|
||
It's important to properly configure the project, so that it uses ESM correctly: | ||
|
||
- the `module` options should be set to `ES2020/ES2022/ESNext` | ||
- for the NodeJS apps, we should set `moduleResolution` to `"node16"` | ||
|
||
All in all, the `tsconfig.json` file should looks like this: | ||
|
||
```json title="tsconfig.json" | ||
{ | ||
"compilerOptions": { | ||
"target": "es2021", | ||
"module": "es2020", | ||
"moduleResolution": "node16", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true | ||
} | ||
} | ||
``` | ||
|
||
## Package.json configuration | ||
|
||
It is also important to set `type` option to `"module"` in your `package.json` file: | ||
|
||
```json title="package.json" | ||
{ | ||
"type": "module" | ||
} | ||
``` | ||
|
||
## Imports | ||
|
||
Apart from using `import` syntax, your local imports have to use the `.js` suffix, e.g.: | ||
|
||
```ts | ||
import { MyResolver } from "./resolvers/MyResolver.js"; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"module": "ES2020", | ||
"moduleResolution": "node16", | ||
"outDir": "./build/esm" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters