question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with useEmbedded = true

See original GitHub issue

API 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:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
seltzlabcommented, May 28, 2020

@alanpoulain great thanks, it works. I had to change the format function with

 format={v => v !== null && typeof v === 'object' && v.hasOwnProperty('@id') ? v['@id'] : v}

because if v is null it fails with Cannot read property '@id' of null

0reactions
alanpoulaincommented, May 27, 2020

I’ve added a documentation here: https://github.com/api-platform/docs/pull/1116.

Basically you need to add:

format={v => v['@id'] ?? v}

to your ReferenceInput.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with edit form when useEmbedded = true #346 - GitHub
The create view works as expected but edit is causing issues unless I reselect he certificate type field. If I edit the page...
Read more >
If is Evil… when used in location context - NGINX
In some cases it may be good idea to use embedded scripting modules (embedded perl, ... just how it works location /only-one-if {...
Read more >
Use embedded data to prepopulate a question and update ...
Hi folks, I've chased this a bunch of different ways and am getting nowhere so any help would be truly appreciated.
Read more >
Computer Literacy Flashcards - Quizlet
Watson was using augmented reality to solve the problems. False. New cars use embedded computers to make driving safer. True.
Read more >
Missing api-prefix in request from ReferenceArrayInput
The problem with this generated Code is, that the property_values are displayed as serialized json-objects. const PropertyEdit = props => ( < ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found