Skip to content

Commit

Permalink
fix(query): fix orderBy argument on lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Andras Toth committed Feb 15, 2016
1 parent 9054e96 commit ef9a603
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
28 changes: 26 additions & 2 deletions src/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('e2e', () => {
});

it('should return results in ascending order', async function Test() {
const result = await graphql(schema, `{
let result = await graphql(schema, `{
viewer {
users(orderBy: NAME_ASC) {
edges {
Expand All @@ -311,10 +311,22 @@ describe('e2e', () => {
{ node: { name: 'Foo' } },
{ node: { name: 'Mother' } }
]);

result = await graphql(schema, `{
users(orderBy: NAME_ASC) {
name
}
}`);

expect(result.data.users).to.be.eql([
{ name: 'Bar' },
{ name: 'Foo' },
{ name: 'Mother' }
]);
});

it('should return results in descending order', async function Test() {
const result = await graphql(schema, `{
let result = await graphql(schema, `{
viewer {
users(orderBy: NAME_DESC) {
edges {
Expand All @@ -331,6 +343,18 @@ describe('e2e', () => {
{ node: { name: 'Foo' } },
{ node: { name: 'Bar' } }
]);

result = await graphql(schema, `{
users(orderBy: NAME_DESC) {
name
}
}`);

expect(result.data.users).to.be.eql([
{ name: 'Mother' },
{ name: 'Foo' },
{ name: 'Bar' }
]);
});

it('should be able to limit the ordered results', async function Test() {
Expand Down
5 changes: 4 additions & 1 deletion src/query/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@ function getListResolver(graffitiModel) {
args.id = ids;
}

const { orderBy: sort } = args;
delete args.orderBy;

const Collection = graffitiModel.model;
if (Collection) {
return getList(Collection, args, {}, info);
return getList(Collection, args, {sort}, info);
}

return null;
Expand Down

0 comments on commit ef9a603

Please sign in to comment.