# graphql-tag-loader-register

> Require `.graphql` files with Node & Typescript.

Latest version **1.0.4** (published 2018-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-tag-loader-register
pnpm add graphql-tag-loader-register
yarn add graphql-tag-loader-register
bun add graphql-tag-loader-register
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-04-08 |
| First published | 2017-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jonjaques |

## Links

- npm: https://www.npmjs.com/package/graphql-tag-loader-register
- Repository: https://github.com/jonjaques/graphql-tag-register
- npm.io page: https://npm.io/package/graphql-tag-loader-register

## Dependencies (1)

- [pirates](https://npm.io/package/pirates.md) ^3.0.1

## Recent versions

- 1.0.4 (latest) — 2018-04-08
- 1.0.3 — 2017-10-21
- 1.0.2 — 2017-10-21
- 1.0.1 — 2017-10-21
- 1.0.0 — 2017-10-21

## README

# graphql-tag-loader-register

Require `.graphql` files with Node & Typescript.

You may want to add `"ignore": [".graphql", ".graphqls"]` to your .babelrc if you use babel@6. I hear that babel@7 fixes this by using the same dependency this module does ;)

*Supports node@>=6*

## Usage

### Install

```
npm i --save graphql graphql-tag graphql-tag-loader-register [@types/graphql]
```

### Code

```js
const register = require('graphql-tag-loader-register')
register()

const schema = require('./schema.graphqls')
console.log(schema) // schema document ast

const query = require('./query.graphql')
console.log(query) // query document ast
```

Also supports ES6 imports and TypeScript with a default export.

```ts
import register from 'graphql-tag-register'
register()
```

If using TypeScript, slightly more work is required. My only use case right now involves ts-node, and to get that to work I did the following:

```ts
// entry.js
process.env.TS_NODE_IGNORE = '\.graphqls?$'
require('ts-node/register')

// graphql.ts
import register from 'graphql-tag-loader-register'
register()

import {DocumentNode} from 'graphql'
const schema = require('schema.graphqls') as DocumentNode
const query = require('schema.graphql') as DocumentNode
```

> If somebody can improve the module by contributing working configs or figuring out how to declare this globally or more succinctly, please do!

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