graphql-require-extension
Require extensions for GraphQL - allows you to import /require from `.graphql` files in a NodeJS environment.
Last updated 2 years ago by dotansimha .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install graphql-require-extension 
SYNC missed versions from official npm registry.

graphql-require-extension

Require extensions for GraphQL - allows you to import /require from .graphql files in a NodeJS environment.

Automatically parses your .graphql (or .graphqls / .gql / .gqls) into DocumentNode. No need to compile on runtime.

How to use?

Installing

Use NPM or Yarn to install:

yarn add graphql-require-extension

Usage with Node (JavaScript)

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

node -r graphql-require-extension/register index.js

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

require('graphql-require-extension/register');

Now you should be able to do:

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-require-extension/register flag:

ts-node -r graphql-require-extension/register index.ts

Also, create a typings file under your source code directory with the following content:

declare module '*.graphql' {
  import { DocumentNode } from 'graphql';
  const ast: DocumentNode;
  export default ast;
}

Now you should be able to do:

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:

{
  "transform": {
    "^.+\\.graphql$": "graphql-require-extension/jest"
  }
}

Current Tags

  • 0.0.5                                ...           latest (2 years ago)

5 Versions

  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |