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

ra-data-graphql-simple ReferenceManyField target Filter #4713

Closed
wmwart opened this issue Apr 22, 2020 · 9 comments
Closed

ra-data-graphql-simple ReferenceManyField target Filter #4713

wmwart opened this issue Apr 22, 2020 · 9 comments

Comments

@wmwart
Copy link

wmwart commented Apr 22, 2020

What you were expecting:
After making changes to the target parameter, I was finally able to remove another crutch. Thanks so much for this.

But there is one more problem.
Here is the request sent in List:

const DistrictFilter = (props) => (
    <Filter {...props}>
        <ReferenceInput source="gasRegion.id" reference="GasRegion" allowEmpty emptyText="ra.message.no">
            <AutocompleteInput optionText="name" />
        </ReferenceInput>
    </Filter>
);

==>

{operationName: "allGasDistricts",…}
operationName: "allGasDistricts"
query: "query allGasDistricts($page: Int, $perPage: Int, $sortField: String, $sortOrder: String, $filter: GasDistrictFilter) {↵  items: allGasDistricts(page: $page, perPage: $perPage, sortField: $sortField, sortOrder: $sortOrder, filter: $filter) {↵    id↵    name↵    description↵    createdAt↵    createdBy {↵      id↵      name↵      email↵      phone↵      __typename↵    }↵    updatedAt↵    deleted↵    gasRegion {↵      id↵      name↵      description↵      __typename↵    }↵    gasMeterPads {↵      id↵      name↵      description↵      __typename↵    }↵    reports {↵      id↵      name↵      description↵      type↵      template↵      __typename↵    }↵    tags {↵      id↵      name↵      description↵      color↵      resource↵      __typename↵    }↵    aisId↵    __typename↵  }↵  total: _allGasDistrictsMeta(page: $page, perPage: $perPage, filter: $filter) {↵    count↵    __typename↵  }↵}↵"
variables: {filter: {gasRegion: {id: "ck7omjmc40000pcurc9zc8usn"}}, page: 0, perPage: 10, sortField: "updatedAt",…}
filter: {gasRegion: {id: "ck7omjmc40000pcurc9zc8usn"}}
gasRegion: {id: "ck7omjmc40000pcurc9zc8usn"}
id: "ck7omjmc40000pcurc9zc8usn"
page: 0
perPage: 10
sortField: "updatedAt"
sortOrder: "DESC"

pay attention to the filter:

filter: {
    gasRegion: {
         id: "ck7omjmc40000pcurc9zc8usn"
     }
}

This is exactly what i expect to see. This is working correctly.

What happened instead:
However, if I want to get the same data with:

<ReferenceManyField 
                label="resources.GasRegion.fields.gasDistricts"
                reference="GasDistrict" 
                target="gasRegion.id" 
                sort={{ field: 'updatedAt', order: 'DESC' }}
                pagination={<Pagination />}
                perPage={25} 
            >
                <GasDistrictReferenceDatagrid />
            </ReferenceManyField>

such a request is sent:

{operationName: "allGasDistricts",…}
operationName: "allGasDistricts"
query: "query allGasDistricts($page: Int, $perPage: Int, $sortField: String, $sortOrder: String, $filter: GasDistrictFilter) {↵  items: allGasDistricts(page: $page, perPage: $perPage, sortField: $sortField, sortOrder: $sortOrder, filter: $filter) {↵    id↵    name↵    description↵    createdAt↵    createdBy {↵      id↵      name↵      email↵      phone↵      __typename↵    }↵    updatedAt↵    deleted↵    gasRegion {↵      id↵      name↵      description↵      __typename↵    }↵    gasMeterPads {↵      id↵      name↵      description↵      __typename↵    }↵    reports {↵      id↵      name↵      description↵      type↵      template↵      __typename↵    }↵    tags {↵      id↵      name↵      description↵      color↵      resource↵      __typename↵    }↵    aisId↵    __typename↵  }↵  total: _allGasDistrictsMeta(page: $page, perPage: $perPage, filter: $filter) {↵    count↵    __typename↵  }↵}↵"
variables: {filter: {gasRegion.id: "ck7omjmc40000pcurc9zc8usn"}, page: 0, perPage: 25, sortField: "updatedAt",…}
filter: {gasRegion.id: "ck7omjmc40000pcurc9zc8usn"}
gasRegion.id: "ck7omjmc40000pcurc9zc8usn"
page: 0
perPage: 25
sortField: "updatedAt"
sortOrder: "DESC"

filter: {gasRegion.id: "ck7omjmc40000pcurc9zc8usn"}

This is a mistake.

I expected that in both cases the same filter will be generated.

Environment

  • React-admin version: 3.4.2
@djhi
Copy link
Collaborator

djhi commented Apr 23, 2020

Thanks for reporting

@djhi djhi added the bug label Apr 23, 2020
@jschroed91
Copy link

Experiencing the same issue - any resolution here?

@wmwart
Copy link
Author

wmwart commented Nov 9, 2020

you recently made a bug fix #5457
I think these are related problems. Will there be a fix for target as well?

@fzaninotto
Copy link
Member

Not sure the two are related - this issue is about the graphql data provider, not the core filter system.

@wmwart
Copy link
Author

wmwart commented Nov 9, 2020

definitely the wrong filter is sending ra-data-graph-simple, but as I mentioned earlier, it seems to me that the components:

<ReferenceInput resource="GasDistrict" source="gasRegion.id" reference="GasRegion">
    <AutocompleteInput optionText="name" />
</ReferenceInput>

and

<ReferenceManyField resource="GasRegion" reference="GasDistrict" target="gasRegion.id">
    <GasDistrictReferenceDatagrid />
</ReferenceManyField>

must send the identical request to the provider:

{
    query allGasDistricts(..., $filter: GasDistrictFilter) {
        items: allGasDistricts(..., filter: $filter) { id ...}
        total: _allGasDistrictsMeta(... , filter: $filter) { count ...}
    },
    variables: {
        filter: {
            gasRegion: {
                id: "ck7omjmc40000pcurc9zc8usn"
            }
        }, 
        …
    }
}

for source="gasRegion.id" a filter is sent to the dataProvider with {gasRegion: { id: "ck7omjmc40000pcurc9zc8usn"}}
for target="gasRegion.id a filter is sent to the dataProvider with {"gasRegion.id": "ck7omjmc40000pcurc9zc8usn"}}

but it doesn't. This allows us to conclude that parameters source="gasRegion.id" and target="gasRegion.id that are supposed to fulfill the same role work differently.
Please let me know if this is not the case.

@djhi
Copy link
Collaborator

djhi commented Oct 4, 2021

It looks like it works on the graphql demo. The category edit page has a ReferenceManyField which targets the category products. Is this still an issue?

@wmwart
Copy link
Author

wmwart commented Oct 7, 2021

Hi!
what is this graphql demo?
If you mean react-admin-demo (https://marmelab.com/react-admin-demo/#/categories/0) then the ReferenceManyField code applied does not match the problem description.
The problem is in the text of the target parameter. In your example, target = "category_id" (not a complex structure).
The problem arises when target = "category.id" (complex structure).

@djhi
Copy link
Collaborator

djhi commented Oct 7, 2021

I see. Then please provide a way for us to reproduce the issue.
By the way, we haven't deployed the gql demo but you can run it from the repository. See https://github.com/marmelab/react-admin/blob/master/package.json#L20

@WiXSL WiXSL removed the bug label Feb 14, 2022
@fzaninotto
Copy link
Member

No news for some time, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants