(Currently not using Apollo)
So I have server.js:
let graphqlHTTP = require('express-graphql');
... // (other graphQL setup)
let users = []; // or any DB solution here
const {
UserType,
UserFactory
} = require('./schema/typeDef.js');
const { QueryType } = require('./schema/query.js');
... // similar imports
// other server declarations
And for example, I have typeDef.js:
const UserType = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: new GraphQLNonNull(GraphQLInt) },
username: { type: new GraphQLNonNull(GraphQLString }
}
});
const UserFactory = function(username, id) {
return {username: username, id: id};
};
module.exports = { UserType, UserFactory };
The problem is, I want to be able to add the UserType to the DB (in this code example, the users array) in server.js; but of course, typeDef.js does not have access to the declared DB in server.js.
I initially separated the files because I didn't want server.js to be too bloated with schema code.
How should I go about this? Thanks!