I need to require bar from bar.js and foo from foo.js in each file.
How I can do it?
foo.js
const bar = require('./bar');
const foo = 'Hello';
console.log(`${foo} ${bar}!`);
module.exports = foo;
bar.js
const foo = require('./foo');
const bar = 'World';
console.log(`${foo} ${bar}!`);
module.exports = bar;
Main purpose is for have many to many GraphQL connection.
I want to require in rootQuery separate files with lets say postType.js and tagType.js. And I need to query posts from tags, and tags from posts.
Is it possible?
Yes this is possible node.js has built in mechanisms for handling just this sort circular require() calls. Please read the node documentation. https://nodejs.org/api/modules.html#modules_cycles