Skip to content

Commit

Permalink
chore(package): update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Andras Toth committed Dec 12, 2015
1 parent 02eaf3e commit 8b56a10
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 55 deletions.
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Mongoose adapter for graffiti (Node.js GraphQL ORM)",
"main": "lib/index.js",
"scripts": {
"test": "NODE_ENV=test mocha --compilers js:babel/register 'src/**/*.spec.js'",
"test": "NODE_ENV=test mocha --compilers js:babel-register --require babel-polyfill 'src/**/*.spec.js'",
"eslint": "eslint src",
"prepublish": "npm test && npm run build",
"build": "rm -rf lib/* && babel src --ignore *.spec.js --out-dir lib",
Expand Down Expand Up @@ -35,16 +35,21 @@
"graphql": "^0.4.14"
},
"devDependencies": {
"babel": "^5.8.29",
"babel-eslint": "^4.1.3",
"babel": "^6.3.13",
"babel-cli": "^6.3.17",
"babel-eslint": "^5.0.0-beta6",
"babel-istanbul": "^0.5.9",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.3.13",
"chai": "^3.4.1",
"chai-subset": "^1.2.0",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^2.0.0",
"graphql": "^0.4.14",
"mocha": "^2.3.4",
"mongoose": "^4.3.0",
"mongoose": "^4.3.1",
"pre-commit": "^1.1.2",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0"
Expand All @@ -53,6 +58,9 @@
"test"
],
"babel": {
"stage": 0
"presets": [
"es2015",
"stage-0"
]
}
}
43 changes: 23 additions & 20 deletions src/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ describe('e2e', () => {
let motherUser;
let user1;
let user2;
const hooks = {
viewer: {
pre: spy(),
post: spy()
},
singular: {
pre: spy(),
post: spy()
},
plural: {
pre: spy(),
post: spy()
},
mutation: {
pre: spy(),
post: spy()
}
};
const options = {hooks};
const schema = getSchema([User], options);
let schema;
let hooks;
before(function beforeAll() {
hooks = {
viewer: {
pre: spy(),
post: spy()
},
singular: {
pre: spy(),
post: spy()
},
plural: {
pre: spy(),
post: spy()
},
mutation: {
pre: spy(),
post: spy()
}
};
schema = getSchema([User], {hooks});
});

beforeEach(async function BeforeEach() {
motherUser = new User({
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ export default {
getSchema,
getTypes: _getTypes
};

export {
graphql,
getSchema,
_getTypes as getTypes
};
3 changes: 2 additions & 1 deletion src/model/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export default from './model';
export * from './model';
export {default} from './model';
4 changes: 4 additions & 0 deletions src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ function getModels(mongooseModels) {
}

export default {
getModels
};

export {
extractPath,
extractPaths,
getModel,
Expand Down
3 changes: 2 additions & 1 deletion src/query/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export default from './query';
export * from './query';
export {default} from './query';
10 changes: 9 additions & 1 deletion src/query/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,15 @@ async function connectionFromModel(graffitiModel, args, info) {
}

export default {
_idToCursor: idToCursor,
getOneResolver,
getListResolver,
getAddOneMutateHandler,
getUpdateOneMutateHandler,
getDeleteOneMutateHandler
};

export {
idToCursor as _idToCursor,
idToCursor,
getIdFetcher,
getOneResolver,
Expand Down
3 changes: 2 additions & 1 deletion src/schema/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export default from './schema';
export * from './schema';
export {default} from './schema';
26 changes: 11 additions & 15 deletions src/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,21 @@ import {
connectionDefinitions,
globalIdField
} from 'graphql-relay';
import {getModels} from './../model';
import model from './../model';
import {
getTypes,
GraphQLViewer,
nodeInterface,
getTypeFields,
getArguments,
setTypeFields
} from './../type';
import type from './../type';
import {
idToCursor,
getIdFetcher,
getOneResolver,
getListResolver,
getAddOneMutateHandler,
getUpdateOneMutateHandler,
getDeleteOneMutateHandler,
connectionFromModel
} from './../query';
import query from './../query';
import {addHooks} from '../utils';
import viewerInstance from '../model/viewer';

Expand All @@ -52,7 +48,7 @@ function getSingularQueryField(graffitiModel, type, hooks = {}) {
args: {
id: idField
},
resolve: addHooks(getOneResolver(graffitiModel), singular)
resolve: addHooks(query.getOneResolver(graffitiModel), singular)
}
};
}
Expand All @@ -75,7 +71,7 @@ function getPluralQueryField(graffitiModel, type, hooks = {}) {
description: `The ID of a ${name}`
}
}),
resolve: addHooks(getListResolver(graffitiModel), plural)
resolve: addHooks(query.getListResolver(graffitiModel), plural)
}
};
}
Expand Down Expand Up @@ -159,7 +155,7 @@ function getMutationField(graffitiModel, type, viewer, hooks = {}) {
})
}
},
mutateAndGetPayload: addHooks(getAddOneMutateHandler(graffitiModel), mutation)
mutateAndGetPayload: addHooks(query.getAddOneMutateHandler(graffitiModel), mutation)
}),
[updateName]: mutationWithClientMutationId({
name: updateName,
Expand All @@ -173,7 +169,7 @@ function getMutationField(graffitiModel, type, viewer, hooks = {}) {
resolve: (node) => node
}
},
mutateAndGetPayload: addHooks(getUpdateOneMutateHandler(graffitiModel), mutation)
mutateAndGetPayload: addHooks(query.getUpdateOneMutateHandler(graffitiModel), mutation)
}),
[deleteName]: mutationWithClientMutationId({
name: deleteName,
Expand All @@ -187,7 +183,7 @@ function getMutationField(graffitiModel, type, viewer, hooks = {}) {
},
id: idField
},
mutateAndGetPayload: addHooks(getDeleteOneMutateHandler(graffitiModel), mutation)
mutateAndGetPayload: addHooks(query.getDeleteOneMutateHandler(graffitiModel), mutation)
})
};
}
Expand All @@ -199,7 +195,7 @@ function getMutationField(graffitiModel, type, viewer, hooks = {}) {
* @return {Object}
*/
function getFields(graffitiModels, {hooks = {}, mutation = true} = {}) {
const types = getTypes(graffitiModels);
const types = type.getTypes(graffitiModels);
const {viewer, singular} = hooks;

const viewerFields = reduce(types, (fields, type, key) => {
Expand Down Expand Up @@ -285,12 +281,12 @@ function getSchema(mongooseModels, options) {
if (!isArray(mongooseModels)) {
mongooseModels = [mongooseModels];
}
const graffitiModels = getModels(mongooseModels);
const graffitiModels = model.getModels(mongooseModels);
const fields = getFields(graffitiModels, options);
return new GraphQLSchema(fields);
}

export default {
export {
getQueryField,
getMutationField,
getFields,
Expand Down
12 changes: 7 additions & 5 deletions src/schema/schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ describe('schema', () => {
describe('getFields', () => {
it('should return query fields ; including node(id!)', function getFieldsTest() {
this.sandbox.stub(type, 'getTypes').returns(types);

const fields = getFields({});
expect(fields).to.containSubset({
query: {
Expand Down Expand Up @@ -141,19 +142,20 @@ describe('schema', () => {
});

describe('getSchema', () => {
it('should return a GraphQL schema', function getSchemaTest() {
beforeEach(function beforeEach() {
this.sandbox.stub(model, 'getModels').returns({});
this.sandbox.stub(type, 'getTypes').returns(types);
const schema = getSchema([]);
});

it('should return a GraphQL schema', function getSchemaTest() {
const schema = getSchema({});
expect(schema).instanceOf(GraphQLSchema);
expect(schema._queryType.name).to.be.equal('RootQuery');
expect(schema._mutationType.name).to.be.equal('RootMutation');
});

it('should return a GraphQL schema without mutations', function getSchemaTest() {
this.sandbox.stub(model, 'getModels').returns({});
this.sandbox.stub(type, 'getTypes').returns(types);
const schema = getSchema([], {mutation: false});
const schema = getSchema({}, {mutation: false});
expect(schema).instanceOf(GraphQLSchema);
expect(schema._queryType.name).to.be.equal('RootQuery');
expect(schema._mutationType).to.be.equal(undefined);
Expand Down
1 change: 0 additions & 1 deletion src/setup-tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import sinon from 'sinon';
import chai from 'chai';
import sinonChai from 'sinon-chai';
import chaiSubset from 'chai-subset';
import 'babel/polyfill';

import mongoose from 'mongoose';

Expand Down
1 change: 1 addition & 0 deletions src/type/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './type';
export default from './type';
6 changes: 5 additions & 1 deletion src/type/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {addHooks} from '../utils';
import GraphQLDate from './custom/date';
import GraphQLBuffer from './custom/buffer';
import GraphQLGeneric from './custom/generic';
import {connectionFromModel, getOneResolver} from './../query';
import {connectionFromModel, getOneResolver} from '../query';

// Registered types will be saved, we can access them later to resolve types
const types = [];
Expand Down Expand Up @@ -285,6 +285,10 @@ function getTypes(graffitiModels) {
}

export default {
getTypes
};

export {
GraphQLViewer,
GraphQLDate,
GraphQLGeneric,
Expand Down
8 changes: 4 additions & 4 deletions src/utils/Middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {
export default class Middleware {
middleware = []

constructor(middleware = []) {
constructor(middleware) {
this.use(middleware);
}

/**
* Add middleware
* @param {Function} middleware
*/
use(middleware) {
use(middleware = []) {
if (!isArray(middleware)) {
middleware = [middleware];
}
Expand All @@ -34,14 +34,14 @@ export default class Middleware {
compose(...args) {
let lastResult;
return reduceRight(this.middleware, (mw, fn) => {
const next = async (...result) => {
const next = async function next(...result) {
if (!result.length) {
result = args;
}
lastResult = result[0];
await mw.call(this, ...result);
};
return async (...result) => {
return async function composed(...result) {
if (!result.length) {
result = args;
}
Expand Down
5 changes: 5 additions & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ export default {
Middleware,
addHooks
};

export {
Middleware,
addHooks
};

0 comments on commit 8b56a10

Please sign in to comment.