Skip to content

Commit

Permalink
fix(middleware): use graphql of the adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton committed Jul 28, 2015
1 parent 1a33dc0 commit d1af1ee
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 74 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"url": "https://github.com/RisingStack/graffiti/issues"
},
"homepage": "https://github.com/RisingStack/graffiti#readme",
"dependencies": {
"boom": "^2.8.0"
},
"devDependencies": {
"babel-eslint": "^4.0.0",
"chai": "^3.2.0",
Expand All @@ -42,9 +45,5 @@
"pre-commit": [
"eslint",
"test"
],
"dependencies": {
"boom": "^2.8.0",
"graphql": "^0.1.8"
}
]
}
7 changes: 2 additions & 5 deletions src/express/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ var checkDep = require('../util').checkDep;
var isPrefixed = require('../util').isPrefixed;
var isGet = require('../util').isGet;

function create(options) {

var graphql = checkDep(options, 'graphql');

function create() {
return function(options) {

var models = checkDep(options, 'models');
Expand All @@ -19,7 +16,7 @@ function create(options) {
var query = request.query.q;

if (isGet(request) && isPrefixed(request, prefix)) {
return graphql(schema, query)
return adapter.graphql(schema, query)
.then(function(result) {
respone.json(result);
})
Expand Down
32 changes: 13 additions & 19 deletions src/express/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ describe('graffiti express', function() {

it('throws an error if not all met', function() {

var mwFactory = express.create({
graphql: {}
});
var mwFactory = express.create();

try {
mwFactory({
Expand All @@ -27,9 +25,7 @@ describe('graffiti express', function() {

it('doesn\'t throw if all is passed', function() {

var mwFactory = express.create({
graphql: {}
});
var mwFactory = express.create();

var mw = mwFactory({
prefix: '/graphql',
Expand All @@ -44,9 +40,7 @@ describe('graffiti express', function() {
});

it('creates the schema', function() {
var mwFactory = express.create({
graphql: {}
});
var mwFactory = express.create();
var getSchemaSpy = this.sandbox.spy();
var models = [{
name: 'User'
Expand All @@ -71,17 +65,16 @@ describe('graffiti express', function() {
data: 1
};

var mwFactory = express.create({
graphql: function() {
return Promise.resolve(result);
}
});
var mwFactory = express.create();

var mw = mwFactory({
prefix: '/graphql',
models: [],
adapter: {
getSchema: function() {}
getSchema: function() {},
graphql: function() {
return Promise.resolve();
}
}
});

Expand All @@ -108,15 +101,16 @@ describe('graffiti express', function() {

it('calls the next middleware', function() {

var mwFactory = express.create({
graphql: {}
});
var mwFactory = express.create();

var mw = mwFactory({
prefix: '/graphql',
models: [],
adapter: {
getSchema: function() {}
getSchema: function() {},
graphql: function() {
return Promise.resolve();
}
}
});

Expand Down
7 changes: 2 additions & 5 deletions src/hapi/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
var checkDep = require('../util').checkDep;
var boom = require('boom');

function create(options) {

var graphql = checkDep(options, 'graphql');

function create() {
var plugin = {
register: function(server, options, next) {

Expand All @@ -20,7 +17,7 @@ function create(options) {

var query = request.query.q;

return graphql(schema, query)
return adapter.graphql(schema, query)
.then(function(result) {
reply(result);
})
Expand Down
15 changes: 6 additions & 9 deletions src/hapi/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ describe('graffiti hapi', function() {

it('throws an error if not all met', function() {

var mwFactory = hapi.create({
graphql: {}
});
var mwFactory = hapi.create();

try {
mwFactory({
Expand All @@ -38,15 +36,14 @@ describe('graffiti hapi', function() {
};

server.register({
register: hapi.create({
graphql: function() {
return Promise.resolve(result);
}
}),
register: hapi.create(),
options: {
models: [],
adapter: {
getSchema: function() {}
getSchema: function() {},
graphql: function() {
return Promise.resolve();
}
}
}
}, {
Expand Down
14 changes: 3 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
var graphql = require('graphql');

var koa = require('./koa');
var hapi = require('./hapi');
var express = require('./express');

module.exports.koa = koa.create({
graphql: graphql.graphql
});
module.exports.hapi = hapi.create({
graphql: graphql.graphql
});
module.exports.express = express.create({
graphql: graphql.graphql
});
module.exports.koa = koa.create();
module.exports.hapi = hapi.create();
module.exports.express = express.create();
7 changes: 2 additions & 5 deletions src/koa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ var checkDep = require('../util').checkDep;
var isPrefixed = require('../util').isPrefixed;
var isGet = require('../util').isGet;

function create(options) {

var graphql = checkDep(options, 'graphql');

function create() {
return function koa(options) {

var models = checkDep(options, 'models');
Expand All @@ -19,7 +16,7 @@ function create(options) {
var query = this.query.q;

if (isGet(this) && isPrefixed(this, prefix)) {
this.body = yield graphql(schema, query);
this.body = yield adapter.graphql(schema, query);
return this.body;
}

Expand Down
25 changes: 10 additions & 15 deletions src/koa/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ describe('graffiti koa', function() {

it('throws an error if not all met', function() {

var mwFactory = koa.create({
graphql: {}
});
var mwFactory = koa.create();

try {
mwFactory({
Expand All @@ -28,9 +26,7 @@ describe('graffiti koa', function() {
});

it('creates the schema', function() {
var mwFactory = koa.create({
graphql: {}
});
var mwFactory = koa.create();
var getSchemaSpy = this.sandbox.spy();
var models = [{
name: 'User'
Expand All @@ -55,17 +51,18 @@ describe('graffiti koa', function() {
data: 1
};

var mwFactory = koa.create({
graphql: function() {
return Promise.resolve(result);
}
});
var mwFactory = koa.create();

var mw = mwFactory({
prefix: '/graphql',
models: [],
adapter: {
getSchema: function() {}
getSchema: function() {},
graphql: function() {
return Promise.resolve({
data: 1
});
}
}
});

Expand All @@ -88,9 +85,7 @@ describe('graffiti koa', function() {

it('calls the next middleware', function *(done) {

var mwFactory = koa.create({
graphql: {}
});
var mwFactory = koa.create();

var mw = mwFactory({
prefix: '/graphql',
Expand Down

0 comments on commit d1af1ee

Please sign in to comment.