make update schema gulp task
This commit is contained in:
@@ -7,22 +7,26 @@ import graphQLHTTP from 'express-graphql';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import WebpackDevServer from 'webpack-dev-server';
|
import WebpackDevServer from 'webpack-dev-server';
|
||||||
import {Schema} from './config/graphql/schema';
|
import schema from './config/graphql/schema';
|
||||||
|
|
||||||
|
import DB from './config/database';
|
||||||
|
|
||||||
const APP_PORT = 3000;
|
const APP_PORT = 3000;
|
||||||
const GRAPHQL_PORT = 8080;
|
const GRAPHQL_PORT = 8080;
|
||||||
|
|
||||||
var graphql_server = express();
|
var graphql_server = express();
|
||||||
|
|
||||||
// Expose a GraphQL endpoint
|
DB.sync.then(()=>{
|
||||||
graphql_server.use('/', graphQLHTTP({
|
// Expose a GraphQL endpoint
|
||||||
graphiql: true,
|
graphql_server.use('/', graphQLHTTP({
|
||||||
pretty: true,
|
graphiql: true,
|
||||||
schema: Schema,
|
pretty: true,
|
||||||
}));
|
schema: schema(),
|
||||||
graphql_server.listen(GRAPHQL_PORT, () => console.log(
|
}));
|
||||||
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
|
graphql_server.listen(GRAPHQL_PORT, () => console.log(
|
||||||
));
|
`GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compile and Serve Relay App w/ Webpack
|
* Compile and Serve Relay App w/ Webpack
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ type Query {
|
|||||||
type User implements Node {
|
type User implements Node {
|
||||||
id: ID!
|
id: ID!
|
||||||
username: String!
|
username: String!
|
||||||
house(after: String, first: Int, before: String, last: Int): HouseConnection
|
house: HouseConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserConnection {
|
type UserConnection {
|
||||||
|
|||||||
@@ -633,48 +633,7 @@
|
|||||||
{
|
{
|
||||||
"name": "house",
|
"name": "house",
|
||||||
"description": "Returns user's house.",
|
"description": "Returns user's house.",
|
||||||
"args": [
|
"args": [],
|
||||||
{
|
|
||||||
"name": "after",
|
|
||||||
"description": null,
|
|
||||||
"type": {
|
|
||||||
"kind": "SCALAR",
|
|
||||||
"name": "String",
|
|
||||||
"ofType": null
|
|
||||||
},
|
|
||||||
"defaultValue": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "first",
|
|
||||||
"description": null,
|
|
||||||
"type": {
|
|
||||||
"kind": "SCALAR",
|
|
||||||
"name": "Int",
|
|
||||||
"ofType": null
|
|
||||||
},
|
|
||||||
"defaultValue": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "before",
|
|
||||||
"description": null,
|
|
||||||
"type": {
|
|
||||||
"kind": "SCALAR",
|
|
||||||
"name": "String",
|
|
||||||
"ofType": null
|
|
||||||
},
|
|
||||||
"defaultValue": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "last",
|
|
||||||
"description": null,
|
|
||||||
"type": {
|
|
||||||
"kind": "SCALAR",
|
|
||||||
"name": "Int",
|
|
||||||
"ofType": null
|
|
||||||
},
|
|
||||||
"defaultValue": null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"type": {
|
"type": {
|
||||||
"kind": "OBJECT",
|
"kind": "OBJECT",
|
||||||
"name": "HouseConnection",
|
"name": "HouseConnection",
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import gulp from 'gulp';
|
import gulp from 'gulp';
|
||||||
import yargs from 'yargs';
|
import yargs from 'yargs';
|
||||||
|
|
||||||
import DB from './config/database';
|
import DB from './config/database';
|
||||||
import {PowerDataSeed, HouseSeed, UserSeed} from './lib/tasks/seed_data'
|
import {PowerDataSeed, HouseSeed, UserSeed} from './lib/tasks/seed_data';
|
||||||
|
import updateSchema from './lib/tasks/update_schema';
|
||||||
|
|
||||||
gulp.task('generate_power_csv', function(done){
|
gulp.task('generate_power_csv', function(done){
|
||||||
DB.sync().then(()=>{
|
DB.sync().then(()=>{
|
||||||
|
|||||||
35
lib/tasks/update_schema.js
Normal file
35
lib/tasks/update_schema.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { graphql, GraphQLSchema } from 'graphql';
|
||||||
|
import { introspectionQuery, printSchema } from 'graphql/utilities';
|
||||||
|
|
||||||
|
import DB from './../../config/database';
|
||||||
|
import schema from './../../config/graphql/schema';
|
||||||
|
|
||||||
|
DB.sync().then(()=>{
|
||||||
|
|
||||||
|
var Schema = schema();
|
||||||
|
|
||||||
|
// Save JSON of full schema introspection for Babel Relay Plugin to use
|
||||||
|
(async () => {
|
||||||
|
var result = await (graphql(Schema, introspectionQuery));
|
||||||
|
if (result.errors) {
|
||||||
|
console.error(
|
||||||
|
'ERROR introspecting schema: ',
|
||||||
|
JSON.stringify(result.errors, null, 2)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(__dirname, './../../config/graphql/schema.json'),
|
||||||
|
JSON.stringify(result, null, 2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Save user readable type system shorthand of schema
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(__dirname, './../../config/graphql/schema.graphql'),
|
||||||
|
printSchema(Schema)
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
@@ -37,7 +37,8 @@ var House = DB.sequelize.define(NAME, {
|
|||||||
},
|
},
|
||||||
classMethods: {
|
classMethods: {
|
||||||
set: ()=>{
|
set: ()=>{
|
||||||
|
House.associate();
|
||||||
|
House.defineGraphQLType();
|
||||||
},
|
},
|
||||||
associate: ()=>{
|
associate: ()=>{
|
||||||
House.hasMany(DB.PowerDatum, {as: 'PowerData'});
|
House.hasMany(DB.PowerDatum, {as: 'PowerData'});
|
||||||
@@ -82,7 +83,7 @@ var House = DB.sequelize.define(NAME, {
|
|||||||
},
|
},
|
||||||
interfaces: [nodeInterface]
|
interfaces: [nodeInterface]
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
getPowerDataByTime: (start_date, end_date, page)=>{
|
getPowerDataByTime: (start_date, end_date, page)=>{
|
||||||
var params = extend({
|
var params = extend({
|
||||||
order: 'time ASC',
|
order: 'time ASC',
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "babel-node ./app.express.js",
|
"start": "babel-node ./app.express.js",
|
||||||
"update-schema": "babel-node --debug ./scripts/updateSchema.js"
|
"update-schema": "babel-node ./lib/tasks/update_schema.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "~1.12.0",
|
"body-parser": "~1.12.0",
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
import 'babel-polyfill';
|
|
||||||
|
|
||||||
import App from './components/App';
|
|
||||||
import AppHomeRoute from './routes/AppHomeRoute';
|
|
||||||
import React from 'react';
|
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import Relay from 'react-relay';
|
|
||||||
|
|
||||||
ReactDOM.render(
|
|
||||||
<Relay.RootContainer
|
|
||||||
Component={App}
|
|
||||||
route={new AppHomeRoute()}
|
|
||||||
/>,
|
|
||||||
document.getElementById('root')
|
|
||||||
);
|
|
||||||
@@ -1,36 +1,2 @@
|
|||||||
#!/usr/bin/env babel-node --optional es7.asyncFunctions
|
|
||||||
|
|
||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import schema from '../config/graphql/schema';
|
|
||||||
import { graphql, GraphQLSchema } from 'graphql';
|
|
||||||
import { introspectionQuery, printSchema } from 'graphql/utilities';
|
|
||||||
import DB from './../config/database';
|
|
||||||
|
|
||||||
DB.sync().then(()=>{
|
|
||||||
|
|
||||||
var Schema = schema();
|
|
||||||
|
|
||||||
// Save JSON of full schema introspection for Babel Relay Plugin to use
|
|
||||||
(async () => {
|
|
||||||
var result = await (graphql(Schema, introspectionQuery));
|
|
||||||
if (result.errors) {
|
|
||||||
console.error(
|
|
||||||
'ERROR introspecting schema: ',
|
|
||||||
JSON.stringify(result.errors, null, 2)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
fs.writeFileSync(
|
|
||||||
path.join(__dirname, '../config/graphql/schema.json'),
|
|
||||||
JSON.stringify(result, null, 2)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Save user readable type system shorthand of schema
|
|
||||||
fs.writeFileSync(
|
|
||||||
path.join(__dirname, '../config/graphql/schema.graphql'),
|
|
||||||
printSchema(Schema)
|
|
||||||
);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user