Skip to content

Commit

Permalink
fix(type): fix orderBy arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Andras Toth committed Jan 2, 2016
1 parent 84294f8 commit 0975ae2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,26 @@ describe('e2e', () => {
});

it('should return results in descending order', async function Test() {
const result = await graphql(schema, `{
viewer {
users(orderBy: NAME_DESC) {
edges {
node {
name
}
}
}
}
}`);

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

it('should be able to limit the ordered results', async function Test() {
const result = await graphql(schema, `{
viewer {
users(orderBy: NAME_DESC, first: 2) {
Expand Down
10 changes: 8 additions & 2 deletions src/type/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,16 @@ function getOrderByType({name}, fields) {
if (field.type instanceof GraphQLScalarType) {
const upperCaseName = field.name.toUpperCase();
values[`${upperCaseName}_ASC`] = {
[field.name]: 1
name: `${upperCaseName}_ASC`,
value: {
[field.name]: 1
}
};
values[`${upperCaseName}_DESC`] = {
[field.name]: -1
name: `${upperCaseName}_DESC`,
value: {
[field.name]: -1
}
};
}

Expand Down

0 comments on commit 0975ae2

Please sign in to comment.