graphql-import-schema
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

GraphQL Import Schema

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 (GrahpQLSchema).

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

yarn add graphql-import-schema

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-schema/register index.js

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

// CommonJS
require('graphql-import-schema/register');
// ES2016
import 'graphql-import-schema';

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-import-schema/register flag:

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

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

import 'graphql-import-schema';

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-import-schema/jest"
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-import-schema

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

2.99 kB

Total Files

5

Last publish

Collaborators

  • draoncc