Files
old-spike/scripts/updateSchema.js

37 lines
989 B
JavaScript
Raw Normal View History

2016-01-26 19:42:30 -06:00
#!/usr/bin/env babel-node --optional es7.asyncFunctions
import fs from 'fs';
import path from 'path';
2016-01-31 17:18:27 -06:00
import schema from '../config/graphql/schema';
import { graphql, GraphQLSchema } from 'graphql';
2016-01-26 19:42:30 -06:00
import { introspectionQuery, printSchema } from 'graphql/utilities';
2016-01-31 17:18:27 -06:00
import DB from './../config/database';
2016-01-26 19:42:30 -06:00
2016-01-31 17:18:27 -06:00
DB.sync().then(()=>{
2016-01-26 19:42:30 -06:00
2016-01-31 17:18:27 -06:00
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)
);
});