Skip to content

Commit ef9a603

Browse files
author
Andras Toth
committed
fix(query): fix orderBy argument on lists
1 parent 9054e96 commit ef9a603

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/e2e.spec.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe('e2e', () => {
294294
});
295295

296296
it('should return results in ascending order', async function Test() {
297-
const result = await graphql(schema, `{
297+
let result = await graphql(schema, `{
298298
viewer {
299299
users(orderBy: NAME_ASC) {
300300
edges {
@@ -311,10 +311,22 @@ describe('e2e', () => {
311311
{ node: { name: 'Foo' } },
312312
{ node: { name: 'Mother' } }
313313
]);
314+
315+
result = await graphql(schema, `{
316+
users(orderBy: NAME_ASC) {
317+
name
318+
}
319+
}`);
320+
321+
expect(result.data.users).to.be.eql([
322+
{ name: 'Bar' },
323+
{ name: 'Foo' },
324+
{ name: 'Mother' }
325+
]);
314326
});
315327

316328
it('should return results in descending order', async function Test() {
317-
const result = await graphql(schema, `{
329+
let result = await graphql(schema, `{
318330
viewer {
319331
users(orderBy: NAME_DESC) {
320332
edges {
@@ -331,6 +343,18 @@ describe('e2e', () => {
331343
{ node: { name: 'Foo' } },
332344
{ node: { name: 'Bar' } }
333345
]);
346+
347+
result = await graphql(schema, `{
348+
users(orderBy: NAME_DESC) {
349+
name
350+
}
351+
}`);
352+
353+
expect(result.data.users).to.be.eql([
354+
{ name: 'Mother' },
355+
{ name: 'Foo' },
356+
{ name: 'Bar' }
357+
]);
334358
});
335359

336360
it('should be able to limit the ordered results', async function Test() {

src/query/query.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ function getListResolver(graffitiModel) {
169169
args.id = ids;
170170
}
171171

172+
const { orderBy: sort } = args;
173+
delete args.orderBy;
174+
172175
const Collection = graffitiModel.model;
173176
if (Collection) {
174-
return getList(Collection, args, {}, info);
177+
return getList(Collection, args, {sort}, info);
175178
}
176179

177180
return null;

0 commit comments

Comments
 (0)