Skip to content

Commit

Permalink
Merge pull request #3412 from m4theushw/graphql
Browse files Browse the repository at this point in the history
[RFR] Add pagination and sorting params to GET_MANY_REFERENCE
  • Loading branch information
fzaninotto authored Jul 19, 2019
2 parents 3ec6799 + 25c1fba commit d7b4d06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/ra-data-graphql-simple/src/buildVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ export default introspectionResults => (
case GET_MANY_REFERENCE: {
const parts = preparedParams.target.split('.');
return {
page: parseInt(preparedParams.pagination.page, 10) - 1,
perPage: parseInt(preparedParams.pagination.perPage, 10),
sortField: preparedParams.sort.field,
sortOrder: preparedParams.sort.order,
filter: { [`${parts[0]}Id`]: preparedParams.id },
};
}
Expand Down
6 changes: 6 additions & 0 deletions packages/ra-data-graphql-simple/src/buildVariables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ describe('buildVariables', () => {
const params = {
target: 'author.id',
id: 'author1',
pagination: { page: 1, perPage: 10 },
sort: { field: 'name', order: 'ASC' },
};

expect(
Expand All @@ -143,6 +145,10 @@ describe('buildVariables', () => {
)
).toEqual({
filter: { authorId: 'author1' },
page: 0,
perPage: 10,
sortField: 'name',
sortOrder: 'ASC',
});
});
});
Expand Down

0 comments on commit d7b4d06

Please sign in to comment.