Issues with useEmbedded = true
See original GitHub issueAPI Platform version(s) affected: 2.2.0
Description
When using the useEmbedded = true
parameter with the HydraDataProvider
fetching a nested resource is failing because the built URL is not valid (trying GET /[object%20Object])
How to reproduce
I have this .jsonld produced by my Api-platform APIs.
There’s a resource Publisher (https://gist.github.com/seltzlab/dd9651b28b81ec35527cf01d060781bf#file-jsonld-L1291) that embeds a MediaType resource https://gist.github.com/seltzlab/dd9651b28b81ec35527cf01d060781bf#file-jsonld-L977
In he Publisher list view everything is fine, I can print the MediaType.name property without any issue
const PublishersList = props => (
<List {...props} exporter={false}>
<Datagrid>
<FieldGuesser source="name" />
<TextField source="type.name" label="Media type" sortable={false} />
<FieldGuesser source="country_code" sortable={false} />
<EditButton />
</Datagrid>
</List>
);
But within the edit view the Autocomplete gets no value and I see the provider trying to retrieve GET /[object%20Object]
export default function PublisherEdit(props) {
return <Edit {...props} actions={<React.Fragment />}>
<SimpleForm variant="outlined">
<Typography variant="h5">Edit publisher</Typography>
<TextInput source="name" fullWidth />
<ReferenceInput label="Media type" reference="media-types" source="type">
<AutocompleteInput optionValue="id" optionText="name" options={{variant: "outlined"}} fullWidth pagination={false}/>
</ReferenceInput>
<TextInput source="country_code" label="Country code (2 chars)" />
</SimpleForm>
</Edit>;
}
Additional Context
Digging into the hydraDataProvider I’ve seen that into convertReactAdminRequestToHydraRequest the params.id
is an object itself.
Without the useEmbedded the edit view looks working fine, while the list is not.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
@alanpoulain great thanks, it works. I had to change the format function with
because if v is null it fails with
Cannot read property '@id' of null
I’ve added a documentation here: https://github.com/api-platform/docs/pull/1116.
Basically you need to add:
to your
ReferenceInput
.