Skip to content

Commit

Permalink
Add tests for ordering by multiple fields (parse-community#6316)
Browse files Browse the repository at this point in the history
* fix(GraphQL): Unable to run queries with order as array

An internal server error is thrown if the `order` query parameter is an array.
Currently, `order` only works with a single value.

* Add tests

* Reset cache

* Remove one of the tests from Postgres

Co-authored-by: Douglas Muraoka <douglas.muraoka@gmail.com>
  • Loading branch information
davimacedo and douglasmuraoka authored Jan 6, 2020
1 parent d7bc0e4 commit 61b3b29
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ describe('ParseGraphQLServer', () => {

object1 = new Parse.Object('GraphQLClass');
object1.set('someField', 'someValue1');
object1.set('someOtherField', 'A');
const object1ACL = new Parse.ACL();
object1ACL.setPublicReadAccess(false);
object1ACL.setPublicWriteAccess(false);
Expand All @@ -386,6 +387,7 @@ describe('ParseGraphQLServer', () => {

object2 = new Parse.Object('GraphQLClass');
object2.set('someField', 'someValue2');
object2.set('someOtherField', 'A');
const object2ACL = new Parse.ACL();
object2ACL.setPublicReadAccess(false);
object2ACL.setPublicWriteAccess(false);
Expand All @@ -400,6 +402,7 @@ describe('ParseGraphQLServer', () => {

object3 = new Parse.Object('GraphQLClass');
object3.set('someField', 'someValue3');
object3.set('someOtherField', 'B');
object3.set('pointerToUser', user5);
await object3.save(undefined, { useMasterKey: true });

Expand Down Expand Up @@ -5937,6 +5940,98 @@ describe('ParseGraphQLServer', () => {
}
});
});

it('should order by multiple fields', async () => {
await prepareData();

await resetGraphQLCache();

let result;
try {
result = await apolloClient.query({
query: gql`
query OrderByMultipleFields($order: [GraphQLClassOrder!]) {
graphQLClasses(order: $order) {
edges {
node {
objectId
}
}
}
}
`,
variables: {
order: ['someOtherField_DESC', 'someField_ASC'],
},
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
} catch (e) {
handleError(e);
}

expect(
result.data.graphQLClasses.edges.map(edge => edge.node.objectId)
).toEqual([object3.id, object1.id, object2.id]);
});

it_only_db('mongo')(
'should order by multiple fields on a relation field',
async () => {
await prepareData();

const parentObject = new Parse.Object('ParentClass');
const relation = parentObject.relation('graphQLClasses');
relation.add(object1);
relation.add(object2);
relation.add(object3);
await parentObject.save();

await resetGraphQLCache();

let result;
try {
result = await apolloClient.query({
query: gql`
query OrderByMultipleFieldsOnRelation(
$id: ID!
$order: [GraphQLClassOrder!]
) {
parentClass(id: $id) {
graphQLClasses(order: $order) {
edges {
node {
objectId
}
}
}
}
}
`,
variables: {
id: parentObject.id,
order: ['someOtherField_DESC', 'someField_ASC'],
},
context: {
headers: {
'X-Parse-Master-Key': 'test',
},
},
});
} catch (e) {
handleError(e);
}

expect(
result.data.parentClass.graphQLClasses.edges.map(
edge => edge.node.objectId
)
).toEqual([object3.id, object1.id, object2.id]);
}
);
});
});

Expand Down

0 comments on commit 61b3b29

Please sign in to comment.