Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
"url": "https://github.com/mickhansen/graphql-sequelize/issues"
},
"homepage": "https://github.com/mickhansen/graphql-sequelize",
"dependencies": {
"babel-runtime": "^6.0.8",
"graphql-relay": "^0.4.1",
"invariant": "2.2.1",
"lodash": "^4.0.0"
},
"peerDependencies": {
"graphql": "^0.5.0"
},
"devDependencies": {
"babel": "^5.8.29",
"babel-core": "^5.8.31",
Expand All @@ -40,7 +49,6 @@
"chai": "^3.0.0",
"chai-as-promised": "^5.1.0",
"eslint": "^1.7.3",
"graphql": "^0.4.15",
"istanbul": "^0.4.0",
"mocha": "^2.2.5",
"pg": "^4.4.2",
Expand All @@ -50,11 +58,5 @@
"sinon-as-promised": "^4.0.0",
"sinon-chai": "^2.8.0",
"sqlite3": "^3.0.9"
},
"dependencies": {
"babel-runtime": "^6.0.8",
"graphql-relay": "^0.3.6",
"invariant": "2.2.1",
"lodash": "^4.0.0"
}
}
8 changes: 4 additions & 4 deletions src/generateIncludes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function inList(list, attribute) {
return ~list.indexOf(attribute);
}

export default function generateIncludes(simpleAST, type, root, options) {
export default function generateIncludes(simpleAST, type, context, options) {
var result = {include: [], attributes: [], order: []};

type = type.ofType || type;
Expand Down Expand Up @@ -46,7 +46,7 @@ export default function generateIncludes(simpleAST, type, root, options) {
var dummyResult = generateIncludes(
fieldAST,
fieldType,
root,
context,
options
);

Expand All @@ -73,7 +73,7 @@ export default function generateIncludes(simpleAST, type, root, options) {
}

if (includeResolver.$before) {
includeOptions = includeResolver.$before(includeOptions, args, root, {
includeOptions = includeResolver.$before(includeOptions, args, context, {
ast: fieldAST,
type: type
});
Expand Down Expand Up @@ -113,7 +113,7 @@ export default function generateIncludes(simpleAST, type, root, options) {
nestedResult = generateIncludes(
fieldAST,
fieldType,
root,
context,
includeResolver.$options
);

Expand Down
10 changes: 5 additions & 5 deletions src/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function sequelizeConnection({name, nodeType, target, orderBy: orderByEnu
handleConnection: false,
include: true,
list: true,
before: function (options, args, root, context) {
before: function (options, args, context, info) {
if (args.first || args.last) {
options.limit = parseInt(args.first || args.last, 10);
}
Expand Down Expand Up @@ -265,9 +265,9 @@ export function sequelizeConnection({name, nodeType, target, orderBy: orderByEnu
options.attributes = _.uniq(options.attributes);


return before(options, args, root, context);
return before(options, args, context, info);
},
after: function (values, args, root, {source}) {
after: function (values, args, context, {source}) {
let edges = values.map((value) => {
return resolveEdge(value, args, source);
});
Expand Down Expand Up @@ -298,9 +298,9 @@ export function sequelizeConnection({name, nodeType, target, orderBy: orderByEnu
}
});

let resolver = (source, args, info) => {
let resolver = (source, args, context, info) => {
if (simplifyAST(info.fieldASTs[0], info).fields.edges) {
return $resolver(source, args, info);
return $resolver(source, args, context, info);
}

return {
Expand Down
26 changes: 16 additions & 10 deletions src/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ function resolverFactory(target, options) {

validateOptions(options);

resolver = function (source, args, info) {
var root = info.rootValue || {}
, ast = info.fieldASTs
resolver = function (source, args, context, info) {
var ast = info.fieldASTs
, type = info.returnType
, list = options.list || type instanceof GraphQLList
, includeResult
, simpleAST = simplifyAST(ast[0], info)
, fields = simpleAST.fields
, findOptions = argsToFindOptions(args, model);

context = context || {};

if (isConnection(info.returnType)) {
simpleAST = nodeAST(simpleAST);
fields = simpleAST.fields;
Expand All @@ -60,7 +61,8 @@ function resolverFactory(target, options) {
return handleConnection(source.get(association.as), args);
}

return options.after(source.get(association.as), args, root, {
return options.after(source.get(association.as), args, context, {
...info,
ast: simpleAST,
type: type,
source: source
Expand All @@ -87,7 +89,7 @@ function resolverFactory(target, options) {
includeResult = generateIncludes(
simpleAST,
type,
root,
context,
options
);

Expand All @@ -97,10 +99,12 @@ function resolverFactory(target, options) {
}
findOptions.attributes = _.uniq(findOptions.attributes.concat(includeResult.attributes));

findOptions.root = root;
findOptions.logging = findOptions.logging || root.logging;
findOptions.root = context;
findOptions.context = context;
findOptions.logging = findOptions.logging || context.logging;

findOptions = options.before(findOptions, args, root, {
findOptions = options.before(findOptions, args, context, {
...info,
ast: simpleAST,
type: type,
source: source
Expand All @@ -116,7 +120,8 @@ function resolverFactory(target, options) {
if (options.handleConnection && isConnection(info.returnType)) {
result = handleConnection(result, args);
}
return options.after(result, args, root, {
return options.after(result, args, context, {
...info,
ast: simpleAST,
type: type,
source: source
Expand All @@ -125,7 +130,8 @@ function resolverFactory(target, options) {
}

return model[list ? 'findAll' : 'findOne'](findOptions).then(function (result) {
return options.after(result, args, root, {
return options.after(result, args, context, {
...info,
ast: simpleAST,
type: type,
source: source
Expand Down
4 changes: 2 additions & 2 deletions test/integration/relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ describe('relay', function () {
}
}
}
`, {
`, null, {
logging: sqlSpy
}).then(result => {
if (result.errors) throw new Error(result.errors[0].stack);
Expand Down Expand Up @@ -599,7 +599,7 @@ describe('relay', function () {
}
}
}
`, {
`, null, {
logging: sqlSpy
}).then(result => {
if (result.errors) throw new Error(result.errors[0].stack);
Expand Down
46 changes: 23 additions & 23 deletions test/integration/relay/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ if (helper.sequelize.dialect.name === 'postgres') {
connectionFields: () => ({
totalCount: {
type: GraphQLInt,
resolve: function (connection, args, {rootValue}) {
resolve: function (connection, args, {logging}) {
self.projectTaskConnectionFieldSpy(connection);
return connection.source.countTasks({
where: connection.where,
logging: rootValue.logging
logging: logging
});
}
}
Expand Down Expand Up @@ -127,11 +127,11 @@ if (helper.sequelize.dialect.name === 'postgres') {
connectionFields: () => ({
totalCount: {
type: GraphQLInt,
resolve: function (connection, args, {rootValue}) {
resolve: function (connection, args, {logging}) {
self.userTaskConnectionFieldSpy(connection);
return connection.source.countTasks({
where: connection.where,
logging: rootValue.logging
logging: logging
});
}
}
Expand Down Expand Up @@ -227,8 +227,8 @@ if (helper.sequelize.dialect.name === 'postgres') {
},
viewer: {
type: this.viewerType,
resolve: function (source, args, info) {
return info.rootValue.viewer;
resolve: function (source, args, {viewer}) {
return viewer;
}
},
}
Expand Down Expand Up @@ -376,8 +376,8 @@ if (helper.sequelize.dialect.name === 'postgres') {
},
viewer: {
type: this.viewerType,
resolve: function (source, args, info) {
return info.rootValue.viewer;
resolve: function (source, args, {viewer}) {
return viewer;
}
}
}
Expand All @@ -404,7 +404,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`, {
`, null, {
logging: sqlSpy
});

Expand Down Expand Up @@ -460,7 +460,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`);
`, null, {});
};

let firstResult = await query();
Expand Down Expand Up @@ -491,7 +491,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`);
`, null, {});

if (result.errors) throw new Error(result.errors[0].stack);

Expand All @@ -518,7 +518,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`);
`, null, {});

if (result.errors) throw new Error(result.errors[0].stack);
expect(result.data.user.tasks.edges[0].node.title).to.equal('CAA');
Expand Down Expand Up @@ -571,7 +571,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`);
`, null, {});
};

let firstResult = await query();
Expand Down Expand Up @@ -605,7 +605,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`);
`, null, {});

let secondResult = await graphql(this.schema, `
{
Expand All @@ -624,7 +624,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`);
`, null, {});

expect(firstResult.data.user.tasks.edges[2].node.name).to.equal('ABC');
expect(firstResult.data.user.tasks.edges[2].node.name).to.equal(secondResult.data.user.tasks.edges[0].node.name);
Expand Down Expand Up @@ -654,7 +654,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`, {
`, null, {
logging: sqlSpy
});

Expand Down Expand Up @@ -687,7 +687,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`, {
`, null, {
logging: sqlSpy
});

Expand Down Expand Up @@ -717,7 +717,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`, {
`, null, {
logging: sqlSpy
});

Expand All @@ -744,7 +744,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`, {
`, null, {
logging: sqlSpy
});

Expand Down Expand Up @@ -775,7 +775,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
fragment projectOwner on userProjectEdge {
isOwner
}
`, {
`, null, {
logging: sqlSpy
});

Expand All @@ -796,7 +796,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`, {
`, null, {
logging: sqlSpy
});

Expand Down Expand Up @@ -827,7 +827,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`, {});
`, null, {});

if (result.errors) throw new Error(result.errors[0].stack);
expect(result.data.user).not.to.be.null;
Expand Down Expand Up @@ -864,7 +864,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
}
}
}
`, {
`, null, {
viewer: viewer
});

Expand Down
Loading