GraphQL Modules always supports the latest TypeScript version. Lower versions are not supported!
TS-Node (recommended way)
To set up your development environment easily, we recommend to use TypeScript.
You don't have to use TypeScript, but it makes it much easier to use GraphQL Modules.
To get started with your development environment, install the following tools in your project:
tsconfig.json in your root directory:
These configurations facilitate development, but of course you can modify them as you wish. Keep particularly in mind to keep
experimentalDecorators: truebecause that's important for GraphQL Modules.
Next, add the following scripts to your
devstarts your server in the development mode.
debugstarts the server in the debug mode.
startruns the compiled server using pure Node.
TypeScript has an aliasing mechanism for working with modules directories.
To set it up quickly with GraphQL Modules, first add the following package to your server:
Then update your scripts to load the require extension for TypeScript
And you can add custom mapping to your
You can now import files between modules like below:
You can also treat
.graphql files as text files and import from them easily.
It's useful because many IDEs detect
.graphql files and do syntax highlighting for them.
You can use graphql-import-node to enable NodeJS to import
.graphql files, you can use graphql-tag/loader.
Here is a simple
webpack.config.js that should do the job:
You can use Babel for TypeScript with GraphQL Modules by using TypeScript-Babel-Starter.
Still, if you use dependency injection, you have to decorate each property and argument in the providers manually even for the classes like below;
You can use
Injectable as regular functions to wrap your arguments and classes from
Take care to add the polyfill
reflect-metadata and require it (once).
We recommend Jest as your test runner: it has a simple API, it's super fast and you can integrate it with any CI tools.
To test your GraphQL Modules server with Jest, first add support for TypeScript to your Jest instance:
Then, add the following section to your
And add a script to your
Also, make sure that each one of your spec files starts with:
Other Test Runners
You can use any other test runner you prefer. Just figure out how to use it with TypeScript and make sure you can import CommonJS easily.