Last active
December 6, 2018 07:33
-
-
Save Serabass/afa1f59599a87f329d0e5b36871a875a to your computer and use it in GitHub Desktop.
Require GraphQL in Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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