Skip to content

Instantly share code, notes, and snippets.

@Serabass
Last active December 6, 2018 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Serabass/afa1f59599a87f329d0e5b36871a875a to your computer and use it in GitHub Desktop.
Save Serabass/afa1f59599a87f329d0e5b36871a875a to your computer and use it in GitHub Desktop.
Require GraphQL in Node
import * as fs from 'fs';
require.extensions['.gql'] = function (module, filename) {
const content = fs.readFileSync(filename).toString('utf-8');
module._compile(`
exports.default = ${JSON.stringify(content)}; // Здесь можно вызвать, например buildSchema и вернуть собранную схему.
`, filename);
};
let a = require('../example.gql').default;
console.log(a);
// ........................................
// import type from '../example.gql';
// console.log(type);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment