-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(type): graffiti level models
- Loading branch information
Peter Marton
committed
Jul 30, 2015
1 parent
f3912d4
commit d7bb657
Showing
10 changed files
with
134 additions
and
92 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import {graphql} from 'graphql'; | ||
|
||
import {getModels} from './model'; | ||
import {getSchema} from './schema'; | ||
import {getTypes} from './type'; | ||
|
||
export default { | ||
graphql, | ||
getSchema, | ||
getTypes | ||
module.exports.getSchema = function (mongooseModels) { | ||
var models = getModels(mongooseModels); | ||
return getSchema(models); | ||
}; | ||
|
||
module.exports.getTypes = function (mongooseModels) { | ||
var models = getModels(mongooseModels); | ||
return getTypes(models); | ||
}; | ||
|
||
module.exports.graphql = graphql; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {map} from 'lodash'; | ||
|
||
/** | ||
* Turn mongoose model to graffiti model | ||
* @method getModel | ||
* @param {Object} mongooseModel | ||
* @return {Object} graffiti model | ||
*/ | ||
export function getModel (mongooseModel) { | ||
var fields = map(mongooseModel.schema.paths, (schemaPath, name) => { | ||
|
||
var options = schemaPath.options || {}; | ||
|
||
var field = { | ||
name: name, | ||
path: schemaPath.path, | ||
instance: schemaPath.instance, | ||
indexed: options.index ? true : false | ||
}; | ||
|
||
if (schemaPath.caster) { | ||
field.caster = { | ||
path: schemaPath.caster.path, | ||
instance: schemaPath.caster.instance | ||
}; | ||
|
||
if (schemaPath.caster.options.ref) { | ||
field.caster.ref = schemaPath.caster.options.ref; | ||
} | ||
} | ||
|
||
return field; | ||
}); | ||
|
||
return { | ||
name: mongooseModel.modelName, | ||
fields: fields, | ||
model: mongooseModel | ||
}; | ||
} | ||
|
||
/** | ||
* @method getModels | ||
* @param {Array} mongooseModels | ||
* @return {Object} - graffiti models | ||
*/ | ||
export function getModels (mongooseModels) { | ||
return mongooseModels | ||
.map(getModel) | ||
.reduce((models, model) => { | ||
models[model.name] = model; | ||
return models; | ||
}, {}); | ||
} |
Empty file.
Oops, something went wrong.