clean up node interface
This commit is contained in:
@@ -15,19 +15,20 @@ const model_dir = __dirname + '/../models'
|
||||
class Database {
|
||||
|
||||
static sync(){
|
||||
|
||||
console.log("syncing db")
|
||||
fs.readdirSync(model_dir).forEach(function(file) {
|
||||
model = require(model_dir + '/' + file);
|
||||
var model = require(model_dir + '/' + file);
|
||||
Database[model.name] = model;
|
||||
Database.models.push(model);
|
||||
});
|
||||
|
||||
// add associations
|
||||
for (var model of Database.models){
|
||||
console.log(`setting ${model.name}`);
|
||||
model.set();
|
||||
}
|
||||
|
||||
return sequelize.sync();
|
||||
return sequelize.sync().then(()=>{ console.log("done syncing db") });
|
||||
}
|
||||
}
|
||||
Database.sequelize = sequelize;
|
||||
|
||||
@@ -3,17 +3,16 @@ import {
|
||||
nodeDefinitions,
|
||||
} from 'graphql-relay';
|
||||
|
||||
import DB from './../database'
|
||||
|
||||
var {nodeInterface, nodeField} = nodeDefinitions(
|
||||
(globalId) => {
|
||||
var {type, id} = fromGlobalId(globalId);
|
||||
return null;
|
||||
var {graphql_type_name, id} = fromGlobalId(globalId),
|
||||
model = DB[graphql_type_name];
|
||||
return model.findOne({where: {id: id}});
|
||||
},
|
||||
(obj) => {
|
||||
if (obj instanceof Array) {
|
||||
return Array;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
(instance) => {
|
||||
return instance.Model().graphql_type;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export default function(){
|
||||
viewer: {
|
||||
type: DB.User.graphql_type,
|
||||
resolve: (_, args) => {
|
||||
return DB.User.findOne({where: {username: args.username}});
|
||||
return DB.User.findOne({where: {username: 'bethany'}});
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user