diff --git a/src/e2e.spec.js b/src/e2e.spec.js index 0e71031..284b18f 100644 --- a/src/e2e.spec.js +++ b/src/e2e.spec.js @@ -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) { diff --git a/src/type/type.js b/src/type/type.js index c27350a..39d2063 100644 --- a/src/type/type.js +++ b/src/type/type.js @@ -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 + } }; }