# graphql-import-node

> This extension makes your NodeJS application able to import `graphql` files. It uses `require.extensions` to allow you to import/require from `.graphql` files in NodeJS environment. The imported content will be a compiled version of the GraphQL string (`D

Latest version **0.0.5** (published 2022-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-import-node
pnpm add graphql-import-node
yarn add graphql-import-node
bun add graphql-import-node
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2022-04-28 |
| First published | 2018-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 80 |
| Maintainers | dotansimha, ardatan |

## Links

- npm: https://www.npmjs.com/package/graphql-import-node
- Repository: https://github.com/ardatan/graphql-import-node
- npm.io page: https://npm.io/package/graphql-import-node

## Recent versions

- 0.0.5 (latest) — 2022-04-28
- 0.0.4 — 2019-04-30
- 0.0.3 — 2019-04-24
- 0.0.2 — 2019-04-14
- 0.0.1 — 2018-11-17

## README

# GraphQL Import Node

This extension makes your NodeJS application able to import `graphql` files. It uses `require.extensions` to allow you to import/require from `.graphql` files in NodeJS environment. The imported content will be a compiled version of the GraphQL string (`DocumentNode`).

It needs to be installed `graphql` on the project. Then, you can install it using npm or yarn;

```
yarn add graphql-import-node
```

After that, you need to load this library before anything else.

## Usage with Node (JavaScript)

Make sure to run your NodeJS process with `-r` flag:

```
node -r graphql-import-node/register index.js
```

Or, you can require it manually in your index file:

```js
// CommonJS
require('graphql-import-node/register');
```

```js
// ES2016
import 'graphql-import-node';
```

Now you should be able to do:

```js
const schema = require('./schema.graphql');
```

## Usage with TypeScript

If you are using TypeScript (with `ts-node` or `ts-node-dev`), make sure to add the same `-r graphql-import-node/register` flag:

```
ts-node -r graphql-import-node/register index.ts
```

or to have typings for `*.graphql` files it'd better to add the import the library like below;

```ts
import 'graphql-import-node';
```

Now you should be able to do:

```ts
import * as schema from './schema.graphql';
```

## Usage with Jest

If you are running a test environment like Jest, you should add the following configuration to your Jest config:

```json
{
  "transform": {
    "^.+\\.graphql$": "graphql-import-node/jest"
  }
}
```

---
_Source: https://npm.io/package/graphql-import-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
