Skip to content

Commit 9a68e09

Browse files
committed
Merge pull request #205 from mickhansen/greenkeeper-graphql-0.5.0
Update graphql to version 0.5.0 🚀
2 parents 962be48 + d372b65 commit 9a68e09

File tree

8 files changed

+78
-70
lines changed

8 files changed

+78
-70
lines changed

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
"url": "https://github.com/mickhansen/graphql-sequelize/issues"
3333
},
3434
"homepage": "https://github.com/mickhansen/graphql-sequelize",
35+
"dependencies": {
36+
"babel-runtime": "^6.0.8",
37+
"graphql-relay": "^0.4.1",
38+
"invariant": "2.2.1",
39+
"lodash": "^4.0.0"
40+
},
41+
"peerDependencies": {
42+
"graphql": "^0.5.0"
43+
},
3544
"devDependencies": {
3645
"babel": "^5.8.29",
3746
"babel-core": "^5.8.31",
@@ -40,7 +49,6 @@
4049
"chai": "^3.0.0",
4150
"chai-as-promised": "^5.1.0",
4251
"eslint": "^1.7.3",
43-
"graphql": "^0.4.15",
4452
"istanbul": "^0.4.0",
4553
"mocha": "^2.2.5",
4654
"pg": "^4.4.2",
@@ -50,11 +58,5 @@
5058
"sinon-as-promised": "^4.0.0",
5159
"sinon-chai": "^2.8.0",
5260
"sqlite3": "^3.0.9"
53-
},
54-
"dependencies": {
55-
"babel-runtime": "^6.0.8",
56-
"graphql-relay": "^0.3.6",
57-
"invariant": "2.2.1",
58-
"lodash": "^4.0.0"
5961
}
6062
}

src/generateIncludes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function inList(list, attribute) {
66
return ~list.indexOf(attribute);
77
}
88

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

1212
type = type.ofType || type;
@@ -46,7 +46,7 @@ export default function generateIncludes(simpleAST, type, root, options) {
4646
var dummyResult = generateIncludes(
4747
fieldAST,
4848
fieldType,
49-
root,
49+
context,
5050
options
5151
);
5252

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

7575
if (includeResolver.$before) {
76-
includeOptions = includeResolver.$before(includeOptions, args, root, {
76+
includeOptions = includeResolver.$before(includeOptions, args, context, {
7777
ast: fieldAST,
7878
type: type
7979
});
@@ -113,7 +113,7 @@ export default function generateIncludes(simpleAST, type, root, options) {
113113
nestedResult = generateIncludes(
114114
fieldAST,
115115
fieldType,
116-
root,
116+
context,
117117
includeResolver.$options
118118
);
119119

src/relay.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function sequelizeConnection({name, nodeType, target, orderBy: orderByEnu
187187
handleConnection: false,
188188
include: true,
189189
list: true,
190-
before: function (options, args, root, context) {
190+
before: function (options, args, context, info) {
191191
if (args.first || args.last) {
192192
options.limit = parseInt(args.first || args.last, 10);
193193
}
@@ -265,9 +265,9 @@ export function sequelizeConnection({name, nodeType, target, orderBy: orderByEnu
265265
options.attributes = _.uniq(options.attributes);
266266

267267

268-
return before(options, args, root, context);
268+
return before(options, args, context, info);
269269
},
270-
after: function (values, args, root, {source}) {
270+
after: function (values, args, context, {source}) {
271271
let edges = values.map((value) => {
272272
return resolveEdge(value, args, source);
273273
});
@@ -298,9 +298,9 @@ export function sequelizeConnection({name, nodeType, target, orderBy: orderByEnu
298298
}
299299
});
300300

301-
let resolver = (source, args, info) => {
301+
let resolver = (source, args, context, info) => {
302302
if (simplifyAST(info.fieldASTs[0], info).fields.edges) {
303-
return $resolver(source, args, info);
303+
return $resolver(source, args, context, info);
304304
}
305305

306306
return {

src/resolver.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ function resolverFactory(target, options) {
3636

3737
validateOptions(options);
3838

39-
resolver = function (source, args, info) {
40-
var root = info.rootValue || {}
41-
, ast = info.fieldASTs
39+
resolver = function (source, args, context, info) {
40+
var ast = info.fieldASTs
4241
, type = info.returnType
4342
, list = options.list || type instanceof GraphQLList
4443
, includeResult
4544
, simpleAST = simplifyAST(ast[0], info)
4645
, fields = simpleAST.fields
4746
, findOptions = argsToFindOptions(args, model);
4847

48+
context = context || {};
49+
4950
if (isConnection(info.returnType)) {
5051
simpleAST = nodeAST(simpleAST);
5152
fields = simpleAST.fields;
@@ -60,7 +61,8 @@ function resolverFactory(target, options) {
6061
return handleConnection(source.get(association.as), args);
6162
}
6263

63-
return options.after(source.get(association.as), args, root, {
64+
return options.after(source.get(association.as), args, context, {
65+
...info,
6466
ast: simpleAST,
6567
type: type,
6668
source: source
@@ -87,7 +89,7 @@ function resolverFactory(target, options) {
8789
includeResult = generateIncludes(
8890
simpleAST,
8991
type,
90-
root,
92+
context,
9193
options
9294
);
9395

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

100-
findOptions.root = root;
101-
findOptions.logging = findOptions.logging || root.logging;
102+
findOptions.root = context;
103+
findOptions.context = context;
104+
findOptions.logging = findOptions.logging || context.logging;
102105

103-
findOptions = options.before(findOptions, args, root, {
106+
findOptions = options.before(findOptions, args, context, {
107+
...info,
104108
ast: simpleAST,
105109
type: type,
106110
source: source
@@ -116,7 +120,8 @@ function resolverFactory(target, options) {
116120
if (options.handleConnection && isConnection(info.returnType)) {
117121
result = handleConnection(result, args);
118122
}
119-
return options.after(result, args, root, {
123+
return options.after(result, args, context, {
124+
...info,
120125
ast: simpleAST,
121126
type: type,
122127
source: source
@@ -125,7 +130,8 @@ function resolverFactory(target, options) {
125130
}
126131

127132
return model[list ? 'findAll' : 'findOne'](findOptions).then(function (result) {
128-
return options.after(result, args, root, {
133+
return options.after(result, args, context, {
134+
...info,
129135
ast: simpleAST,
130136
type: type,
131137
source: source

test/integration/relay.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ describe('relay', function () {
554554
}
555555
}
556556
}
557-
`, {
557+
`, null, {
558558
logging: sqlSpy
559559
}).then(result => {
560560
if (result.errors) throw new Error(result.errors[0].stack);
@@ -599,7 +599,7 @@ describe('relay', function () {
599599
}
600600
}
601601
}
602-
`, {
602+
`, null, {
603603
logging: sqlSpy
604604
}).then(result => {
605605
if (result.errors) throw new Error(result.errors[0].stack);

test/integration/relay/connection.test.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ if (helper.sequelize.dialect.name === 'postgres') {
8787
connectionFields: () => ({
8888
totalCount: {
8989
type: GraphQLInt,
90-
resolve: function (connection, args, {rootValue}) {
90+
resolve: function (connection, args, {logging}) {
9191
self.projectTaskConnectionFieldSpy(connection);
9292
return connection.source.countTasks({
9393
where: connection.where,
94-
logging: rootValue.logging
94+
logging: logging
9595
});
9696
}
9797
}
@@ -127,11 +127,11 @@ if (helper.sequelize.dialect.name === 'postgres') {
127127
connectionFields: () => ({
128128
totalCount: {
129129
type: GraphQLInt,
130-
resolve: function (connection, args, {rootValue}) {
130+
resolve: function (connection, args, {logging}) {
131131
self.userTaskConnectionFieldSpy(connection);
132132
return connection.source.countTasks({
133133
where: connection.where,
134-
logging: rootValue.logging
134+
logging: logging
135135
});
136136
}
137137
}
@@ -227,8 +227,8 @@ if (helper.sequelize.dialect.name === 'postgres') {
227227
},
228228
viewer: {
229229
type: this.viewerType,
230-
resolve: function (source, args, info) {
231-
return info.rootValue.viewer;
230+
resolve: function (source, args, {viewer}) {
231+
return viewer;
232232
}
233233
},
234234
}
@@ -376,8 +376,8 @@ if (helper.sequelize.dialect.name === 'postgres') {
376376
},
377377
viewer: {
378378
type: this.viewerType,
379-
resolve: function (source, args, info) {
380-
return info.rootValue.viewer;
379+
resolve: function (source, args, {viewer}) {
380+
return viewer;
381381
}
382382
}
383383
}
@@ -404,7 +404,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
404404
}
405405
}
406406
}
407-
`, {
407+
`, null, {
408408
logging: sqlSpy
409409
});
410410

@@ -460,7 +460,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
460460
}
461461
}
462462
}
463-
`);
463+
`, null, {});
464464
};
465465

466466
let firstResult = await query();
@@ -491,7 +491,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
491491
}
492492
}
493493
}
494-
`);
494+
`, null, {});
495495

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

@@ -518,7 +518,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
518518
}
519519
}
520520
}
521-
`);
521+
`, null, {});
522522

523523
if (result.errors) throw new Error(result.errors[0].stack);
524524
expect(result.data.user.tasks.edges[0].node.title).to.equal('CAA');
@@ -571,7 +571,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
571571
}
572572
}
573573
}
574-
`);
574+
`, null, {});
575575
};
576576

577577
let firstResult = await query();
@@ -605,7 +605,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
605605
}
606606
}
607607
}
608-
`);
608+
`, null, {});
609609

610610
let secondResult = await graphql(this.schema, `
611611
{
@@ -624,7 +624,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
624624
}
625625
}
626626
}
627-
`);
627+
`, null, {});
628628

629629
expect(firstResult.data.user.tasks.edges[2].node.name).to.equal('ABC');
630630
expect(firstResult.data.user.tasks.edges[2].node.name).to.equal(secondResult.data.user.tasks.edges[0].node.name);
@@ -654,7 +654,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
654654
}
655655
}
656656
}
657-
`, {
657+
`, null, {
658658
logging: sqlSpy
659659
});
660660

@@ -687,7 +687,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
687687
}
688688
}
689689
}
690-
`, {
690+
`, null, {
691691
logging: sqlSpy
692692
});
693693

@@ -717,7 +717,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
717717
}
718718
}
719719
}
720-
`, {
720+
`, null, {
721721
logging: sqlSpy
722722
});
723723

@@ -744,7 +744,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
744744
}
745745
}
746746
}
747-
`, {
747+
`, null, {
748748
logging: sqlSpy
749749
});
750750

@@ -775,7 +775,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
775775
fragment projectOwner on userProjectEdge {
776776
isOwner
777777
}
778-
`, {
778+
`, null, {
779779
logging: sqlSpy
780780
});
781781

@@ -796,7 +796,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
796796
}
797797
}
798798
}
799-
`, {
799+
`, null, {
800800
logging: sqlSpy
801801
});
802802

@@ -827,7 +827,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
827827
}
828828
}
829829
}
830-
`, {});
830+
`, null, {});
831831

832832
if (result.errors) throw new Error(result.errors[0].stack);
833833
expect(result.data.user).not.to.be.null;
@@ -864,7 +864,7 @@ if (helper.sequelize.dialect.name === 'postgres') {
864864
}
865865
}
866866
}
867-
`, {
867+
`, null, {
868868
viewer: viewer
869869
});
870870

0 commit comments

Comments
 (0)