Zendro-dev / graphql-server

Skeleton NodeJS project for a graphQL server.
GNU General Public License v3.0
0 stars 1 forks source link

Create a single index to import all types of data models with a single require statement #10

Closed asishallab closed 5 years ago

asishallab commented 5 years ago

Currently we support two types of data models:

In the near future we will have more storage technologies supported:

In the distant future we might further include:

In spite of these being stored in separate folders we want to be able to include all models with a single require statement:

const models = require('models-helper.js')

Implement the above models-helper.js as laid out by the following pseudo code gist:

let allModels = {}
const modelTypeDirs = [ 'models', 'models-webservice', 'models-cassandra', ... ]
// Even better: Use a glob expression to get all folders that have "models" in their name
// const modelTypeDirs = Dir.glob( "*model*")
for ( modelDir in modelTypeDirs ) { 
   let modelDirRequired = require( modelDir )
   // Validate:
   // Throw an error if modelDirRequired has an entry that is already present in allModels
   // That is, check if there are two models that have the same name, 
   // but are stored in different storage technologies
   allModels = Object.assign( allModels, modelDirRequired )
}

No test required. A short manual test is enough.

Expected work time: 3h