Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-import-node

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

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:

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

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-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;

import 'graphql-import-node';

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

FAQs

Package last updated on 28 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc