Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ra-data-graphql-simple Many Reference Target Filter #4685

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/ra-data-graphql-simple/src/buildVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,18 @@ export default introspectionResults => (
filter: { ids: preparedParams.ids },
};
case GET_MANY_REFERENCE: {
const parts = preparedParams.target.split('.');
let variables = buildGetListVariables(introspectionResults)(
resource,
aorFetchType,
preparedParams,
queryType
);
variables.filter[`${parts[0]}Id`] = preparedParams.id;

variables.filter = {
...variables.filter,
[preparedParams.target]: preparedParams.id,
};

return variables;
}
case GET_ONE:
Expand Down
4 changes: 2 additions & 2 deletions packages/ra-data-graphql-simple/src/buildVariables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('buildVariables', () => {
describe('GET_MANY_REFERENCE', () => {
it('returns correct variables', () => {
const params = {
target: 'author.id',
target: 'author_id',
id: 'author1',
pagination: { page: 1, perPage: 10 },
sort: { field: 'name', order: 'ASC' },
Expand All @@ -144,7 +144,7 @@ describe('buildVariables', () => {
{}
)
).toEqual({
filter: { authorId: 'author1' },
filter: { author_id: 'author1' },
page: 0,
perPage: 10,
sortField: 'name',
Expand Down