diff --git a/app.express.js b/app.express.js index cc180da..2d47191 100644 --- a/app.express.js +++ b/app.express.js @@ -16,7 +16,8 @@ const GRAPHQL_PORT = 8080; var graphql_server = express(); -DB.sync.then(()=>{ +DB.sync().then(()=>{ + console.log("db done syncing") // Expose a GraphQL endpoint graphql_server.use('/', graphQLHTTP({ graphiql: true, @@ -34,7 +35,7 @@ DB.sync.then(()=>{ var compiler = webpack({ entry: { - app: path.resolve(__dirname, 'relay', 'application.js') + app: path.resolve(__dirname, 'lib', 'relay', 'app.relay.js') }, module: { loaders: [ @@ -99,6 +100,7 @@ dev_server.app.get("/", (req, res, next)=>{ res.render("index"); }); +console.log("launching dev server") dev_server.listen(APP_PORT, () => { console.log(`App is now running on http://localhost:${APP_PORT}`); }); diff --git a/build/babelRelayPlugin.js b/build/babelRelayPlugin.js index 5f10b24..d8e8624 100644 --- a/build/babelRelayPlugin.js +++ b/build/babelRelayPlugin.js @@ -1,4 +1,4 @@ var getbabelRelayPlugin = require('babel-relay-plugin'), - schema = require('../data/schema.json'); + schema = require('../config/graphql/schema.json'); module.exports = getbabelRelayPlugin(schema.data, {abortOnError: true}); diff --git a/config/database.js b/config/database.js index 1140b79..3d32f44 100644 --- a/config/database.js +++ b/config/database.js @@ -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; diff --git a/config/graphql/node.js b/config/graphql/node.js index 8371453..1f4b230 100644 --- a/config/graphql/node.js +++ b/config/graphql/node.js @@ -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; } ); diff --git a/config/graphql/schema.js b/config/graphql/schema.js index 789cb51..995a8e3 100644 --- a/config/graphql/schema.js +++ b/config/graphql/schema.js @@ -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'}}); } }, }), diff --git a/lib/relay/components/App.js b/lib/relay/components/App.js index c56199d..6548d40 100644 --- a/lib/relay/components/App.js +++ b/lib/relay/components/App.js @@ -1,12 +1,10 @@ import React from 'react'; import Relay from 'react-relay'; -import DB from './../../config/database' - class App extends React.Component { render() { var viewer = this.props.viewer, - house = viewer.house.edge.node; + house = viewer.house.edges[0].node; return (