Files
old-spike/models/house.js

50 lines
944 B
JavaScript
Raw Normal View History

2016-01-26 19:42:30 -06:00
import {
GraphQLString,
GraphQLNonNull,
GraphQLObjectType
} from 'graphql';
import {
fromGlobalId,
globalIdField,
nodeDefinitions,
} from 'graphql-relay';
2016-01-27 20:15:09 -06:00
import DB from "./../config/database";
import {nodeInterface} from './../lib/node.relay';
2016-01-26 19:42:30 -06:00
/**
* Define your own types here
*/
2016-01-27 20:15:09 -06:00
var House = DB.sequelize.define('House', {
2016-01-26 19:42:30 -06:00
id: {
2016-01-27 20:15:09 -06:00
type: DB.Sequelize.INTEGER,
2016-01-26 19:42:30 -06:00
primaryKey: true,
autoIncrement: true // Automatically gets converted to SERIAL for postgres
},
2016-01-27 20:15:09 -06:00
name: DB.Sequelize.STRING
2016-01-26 19:42:30 -06:00
}, {
tableName: "houses",
instanceMethods: {
},
classMethods: {
2016-01-27 20:15:09 -06:00
associate: ()=>{
House.hasMany(DB.PowerDatum, {as: 'PowerData'});
2016-01-26 19:42:30 -06:00
}
}
});
House.graphql_type = new GraphQLObjectType({
name: 'House',
description: 'A house',
fields: () => ({
id: globalIdField('House'),
name: GraphQLNonNull(GraphQLInt)
}),
interfaces: [nodeInterface],
});
2016-01-27 20:15:09 -06:00
House.name = 'House';
module.exports = House;