Commit 28db1222 by Shawn Barratt

init graph

parent b7ebf283
/* eslint-env shelljs */
// https://github.com/shelljs/shelljs
require('shelljs/global')
env.NODE_ENV = 'production'
var path = require('path')
var config = require('../config')
var ora = require('ora')
var webpack = require('webpack')
var webpackConfig = require('./webpack.prod.conf')
console.log(
' Tip:\n' +
' Built files are meant to be served over an HTTP server.\n' +
' Opening index.html over file:// won\'t work.\n'
)
var spinner = ora('building for production...')
spinner.start()
var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)
rm('-rf', assetsPath)
mkdir('-p', assetsPath)
cp('-R', 'static/', assetsPath)
webpack(webpackConfig, function (err, stats) {
spinner.stop()
if (err) throw err
process.stdout.write(stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false
}) + '\n')
})
var ExtractTextPlugin = require('extract-text-webpack-plugin')
module.exports = function (options) {
options = options || {}
// generate loader string to be used with extract text plugin
function generateLoaders (loaders) {
var sourceLoader = loaders.map(function (loader) {
var extraParamChar
if (/\?/.test(loader)) {
loader = loader.replace(/\?/, '-loader?')
extraParamChar = '&'
} else {
loader = loader + '-loader'
extraParamChar = '?'
}
return loader + (options.sourceMap ? extraParamChar + 'sourceMap' : '')
}).join('!')
if (options.extract) {
return ExtractTextPlugin.extract('vue-style-loader', sourceLoader)
} else {
return ['vue-style-loader', sourceLoader].join('!')
}
}
// http://vuejs.github.io/vue-loader/configurations/extract-css.html
return {
css: generateLoaders(['css']),
postcss: generateLoaders(['css']),
less: generateLoaders(['css', 'less']),
sass: generateLoaders(['css', 'sass?indentedSyntax']),
scss: generateLoaders(['css', 'sass']),
stylus: generateLoaders(['css', 'stylus']),
styl: generateLoaders(['css', 'stylus'])
}
}
require('eventsource-polyfill')
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
hotClient.subscribe(function (event) {
if (event.action === 'reload') {
window.location.reload()
}
})
var path = require('path')
var express = require('express')
var webpack = require('webpack')
var config = require('../config')
var proxyMiddleware = require('http-proxy-middleware')
var webpackConfig = process.env.NODE_ENV === 'testing'
? require('./webpack.prod.conf')
: require('./webpack.dev.conf')
// default port where dev server listens for incoming traffic
var port = process.env.PORT || config.dev.port
// Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware
var proxyTable = config.dev.proxyTable
var app = express()
var compiler = webpack(webpackConfig)
var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
chunks: false
}
})
var hotMiddleware = require('webpack-hot-middleware')(compiler)
// force page reload when html-webpack-plugin template changes
compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
hotMiddleware.publish({ action: 'reload' })
cb()
})
})
// proxy api requests
Object.keys(proxyTable).forEach(function (context) {
var options = proxyTable[context]
if (typeof options === 'string') {
options = { target: options }
}
app.use(proxyMiddleware(context, options))
})
// handle fallback for HTML5 history API
app.use(require('connect-history-api-fallback')())
// serve webpack bundle output
app.use(devMiddleware)
// enable hot-reload and state-preserving
// compilation error display
app.use(hotMiddleware)
// serve pure static assets
var staticPath = path.posix.join(config.build.assetsPublicPath, config.build.assetsSubDirectory)
app.use(staticPath, express.static('./static'))
module.exports = app.listen(port, function (err) {
if (err) {
console.log(err)
return
}
console.log('Listening at http://localhost:' + port + '\n')
})
var path = require('path')
var config = require('../config')
var cssLoaders = require('./css-loaders')
var projectRoot = path.resolve(__dirname, '../')
module.exports = {
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
publicPath: config.build.assetsPublicPath,
filename: '[name].js'
},
resolve: {
extensions: ['', '.js', '.vue'],
fallback: [path.join(__dirname, '../node_modules')],
alias: {
'src': path.resolve(__dirname, '../src'),
'assets': path.resolve(__dirname, '../src/assets'),
'components': path.resolve(__dirname, '../src/components')
}
},
resolveLoader: {
fallback: [path.join(__dirname, '../node_modules')]
},
module: {
preLoaders: [
{
test: /\.vue$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
},
{
test: /\.js$/,
loader: 'eslint',
include: projectRoot,
exclude: /node_modules/
}
],
loaders: [
{
test: /\.vue$/,
loader: 'vue'
},
{
test: /\.js$/,
loader: 'babel',
include: projectRoot,
exclude: /node_modules/
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.html$/,
loader: 'vue-html'
},
{
test: /\.(png|jpe?g|gif|svg|woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url',
query: {
limit: 10000,
name: path.join(config.build.assetsSubDirectory, '[name].[hash:7].[ext]')
}
}
]
},
vue: {
loaders: cssLoaders()
},
eslint: {
formatter: require('eslint-friendly-formatter')
}
}
var webpack = require('webpack')
var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf')
var HtmlWebpackPlugin = require('html-webpack-plugin')
// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
})
module.exports = merge(baseWebpackConfig, {
// eval-source-map is faster for development
devtool: '#eval-source-map',
plugins: [
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
})
]
})
var path = require('path')
var config = require('../config')
var webpack = require('webpack')
var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf')
var cssLoaders = require('./css-loaders')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = merge(baseWebpackConfig, {
devtool: config.build.productionSourceMap ? '#source-map' : false,
output: {
path: config.build.assetsRoot,
filename: path.join(config.build.assetsSubDirectory, '[name].[chunkhash].js'),
chunkFilename: path.join(config.build.assetsSubDirectory, '[id].[chunkhash].js')
},
vue: {
loaders: cssLoaders({
sourceMap: config.build.productionSourceMap,
extract: true
})
},
plugins: [
// http://vuejs.github.io/vue-loader/workflow/production.html
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin(),
// extract css into its own file
new ExtractTextPlugin(path.join(config.build.assetsSubDirectory, '[name].[contenthash].css')),
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: process.env.NODE_ENV === 'testing'
? 'index.html'
: config.build.index,
template: 'index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
}
})
]
})
......@@ -31,7 +31,8 @@
"ethereal/SimpleTable": "dev-master",
"bshaffer/oauth2-server-php": "^1.8",
"ramsey/uuid": "^3.1",
"doctrine/couchdb": "@dev"
"doctrine/couchdb": "@dev",
"webonyx/graphql-php": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
......
......@@ -3,6 +3,7 @@
"type": "socket",
"host": "localhost",
"port": 5984,
"dbname": "infinity",
"user": null,
"password": null,
"ip": null,
......
{
"hooks": {
"Infinity\\links\\init": {
"hooks": [
{
"topic": "Infinity\\links\\init",
"class": "\\Infinity\\Users\\Users",
"method": "getLinks"
}
}
]
}
......@@ -4,116 +4,113 @@ namespace Infinity\Controller;
class Action
{
protected $request;
protected $response;
protected $args;
protected $container;
public function __construct(
\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Message\ResponseInterface $response,
\Pimple\Container $container,
array $args
) {
$this->request = $request;
$this->response = $response;
$this->container = $container;
$this->args = $args;
}
public function fire($action)
{
if (!method_exists($this, $action)) {
return $this->response->withStatus(404, 'Action not found');
}
$this->beforeAction();
$this->{$action}();
$this->afterAction();
$this->dispatch();
return $this->response;
}
public function __get($property)
{
if (property_exists($this, $property)) {
return $this->{$property};
}
if (isset($this->args[$property])) {
return $this->args[$property];
}
try {
if ($service = $this->container[$property]) {
return $service;
}
} catch(Exception $e) {
//property wasnt in di container
}
return false;
}
public function getUri()
{
$uri = $this->request->getUri();
return "{$uri->getScheme()}://{$uri->getHost()}{$uri->getBasePath()}/{$uri->getPath()}";
}
protected function required($param)
{
$found = $this->{$param};
if ($found) {
$this->response = $this->response->withStatus(400, "Required element {$param} not found");
}
return $found;
}
/**
* prepare the response for return
* @return \Psr\Http\Message\ResponseInterface PSR7 Response Object
*/
protected function dispatch()
{
}
protected function beforeAction()
{
}
protected function afterAction()
{
}
/**
* Gets the value of request.
*
* @return Slim\Http\Request
*/
protected function getRequest()
{
return $this->request;
}
/**
* Gets the value of responce.
*
* @return Slim\Http\Response
*/
protected function getResponse()
{
return $this->responce;
}
/**
* Gets the value of args.
*
* @return mixed
*/
protected function getArgs()
{
return $this->args;
}
protected $request;
protected $response;
protected $args;
protected $container;
public function __construct(
\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Message\ResponseInterface $response,
\Pimple\Container $container,
array $args
) {
$this->request = $request;
$this->response = $response;
$this->container = $container;
$this->args = $args;
}
public function fire($action)
{
if (!method_exists($this, $action)) {
return $this->response->withStatus(404, 'Action not found');
}
$this->beforeAction();
$this->{$action}();
$this->afterAction();
$this->dispatch();
return $this->response;
}
public function __get($property)
{
if (property_exists($this, $property)) {
return $this->{$property};
}
if (isset($this->args[$property])) {
return $this->args[$property];
}
try {
if ($service = $this->container[$property]) {
return $service;
}
} catch (Exception $e) {
//property wasnt in di container
}
return false;
}
public function getUri()
{
$uri = $this->request->getUri();
return "{$uri->getScheme()}://{$uri->getHost()}{$uri->getBasePath()}/{$uri->getPath()}";
}
protected function required($param)
{
$found = $this->{$param};
if ($found) {
$this->response = $this->response->withStatus(400, "Required element {$param} not found");
}
return $found;
}
/**
* prepare the response for return
* @return \Psr\Http\Message\ResponseInterface PSR7 Response Object
*/
protected function dispatch()
{
}
protected function beforeAction()
{
}
protected function afterAction()
{
}
/**
* Gets the value of request.
*
* @return Slim\Http\Request
*/
protected function getRequest()
{
return $this->request;
}
/**
* Gets the value of responce.
*
* @return Slim\Http\Response
*/
protected function getResponse()
{
return $this->responce;
}
/**
* Gets the value of args.
*
* @return mixed
*/
protected function getArgs()
{
return $this->args;
}
}
<?php
namespace Infinity\Controller;
use GraphQL\Server\StandardServer;
use GraphQL\Executor\ExecutionResult;
use GraphQL\Type\Schema;
use GraphQL\Type\Definition\ObjectType;
class GraphQL extends Action
{
protected $request;
protected $response;
protected $container;
protected $schema;
public function __construct(
\Psr\Http\Message\ServerRequestInterface $request,
\Psr\Http\Message\ResponseInterface $response,
\Pimple\Container $container,
array $args
) {
$this->request = $request;
$this->response = $response;
$this->container = $container;
}
private function getSchema()
{
if ($this->schema) {
return $this->schema;
}
// Check for schema in cache
if (!$this->schema = $this->container['cache']->get('graphql_schema')) {
$this->schema = $this->buildSchema();
$this->container['cache']->set('graphql_schema', $this->schema);
}
return $this->schema;
}
private function buildSchema()
{
$schemaBuilder = array(
'query' => [
'name' => 'Query',
'fields' => []
],
'mutation' => [
'name' => 'Mutation',
'fields' = []
]
);
$result = $this->container['hooks']->fire('graphql.schema', $schemaBuilder);
$query = new ObjejectType($result['query']);
$mutation = new ObjejectType($result['mutation']);
return new Schema(['query' => $query, 'mutation' => $mutation]);
}
public function process($action)
{
$server = new StandardServer([]);
return $psrResponse = $server->processPsrRequest($this->request, $this->response, $psrBodyStream);
}
}
......@@ -15,6 +15,7 @@ class QueryBuilder
public function where(array $constraint)
{
$this->where = array_merge($this->where, $where);
return $this;
}
}
<?php
namespace Infinity\Db;
class Row implements \Ethereal\Db\RowInterface
{
protected $data = array();
protected $table;
public function __construct(array $data, TableInterface $table)
{
$this->table = $table;
$this->data = $data;
}
/**
* Gets the value of table.
*
* @return mixed
*/
public function getTable()
{
return $this->table;
}
public function save()
{
if ($this->_id) {
return $this->table->update($this->getData(), array($this->_id, $this->_rev));
}
return $this->table->insert($this->getData());
}
/**
* Gets the value of data.
*
* @return mixed
*/
public function getData()
{
return $this->data;
}
public function toArray()
{
return (array) $this->getData();
}
public function __toString()
{
return json_encode($this->toArray());
}
}
<?php
tablespace Infinity;
class Table implements \Ethereal\Db\TableInterface
{
protected $client;
protected $table;
protected $type;
public function __construct(Db $db, $table = null)
{
$this->client = $db->getClient();
}
public function getTable()
{
return $this->table;
}
public function getConnection()
{
return $this->$db->getClient();
}
public function select($cols = '*')
{
return new QueryBuilder($this->client, $cols);
}