I am building a CMS using @api-platform API on backend and with their react admin boilerplate. Using their Hydra dataProvider none of the Query methods of calling getOne doesn't seem to be working. I tried all hooks and also legacy component or useDataProvider.getOne. The behavior is that the GET URL is wrong generated. It doesn't contain the resource path. Instead there is a undefined in the URL created.
<Query type="getOne" resource="videos" payload={{ id: '1000' }}>
{({ data, loading, error }) => {
if (loading) {
return <Loading />;
}
if (error) {
return <Error />;
}
return data.name;
}}
</Query>;
Also using useQuery:
const { data, loading, error } = useQuery({
type: 'getOne',
resource: 'videos',
payload: { id: "1000"}
});
They are generating the following GET request:
Request URL: https://ra-api.testing.company.com/undefined
Request Method: GET
All other methods generate something like this:
Request URL: https://ra-api.testing.company.com/api/videos
Request Method: GET
The dataProvider looks like this:
export const dataProvider = baseHydraDataProvider(
global.RA_API_ENTRYPOINT,
fetchHydra,
apiDocumentationParser
);
Other methods like getLists or update/create are working properly. Any ideea ?
The Hydra data provider is not using the
resource
parameter for thegetOne
query, only theid
: https://github.com/api-platform/admin/blob/5badc1f19024c1800a60431e575219039b86d0b6/src/hydra/dataProvider.js#L227It's because the
id
in the payload needs to be an IRI, like this:With API Platform Admin (and the Hydra data provider), all identifiers are IRI.