Here is a simplified example to illustrate the issue at hand. When using the resolver Query getAllUsers
, the MongoDB Collection Users
is not accessible in the external resolver file user.js
. This results in the following error when executing the query:
ReferenceError: Users is not defined
While this behavior is expected, I prefer to organize my resolvers in separate files for better modularity, rather than including them all in index.js. My current file structure looks like this:
Current file structure
index.js
/graphql
/typdef
user.graphql
/resolver
user.js
The user.graphql
schema works correctly; it's just the user.js
causing errors due to the unavailable Users
variable.
Below are snippets of index.js
and user.js
.
index.js
(Code from index.js goes here.)
user.js
(Code from user.js goes here.)
I'm looking for the best way to pass the MongoDB or the Users
collection to the resolver files. Alternatively, if there is a better solution to address this issue altogether.