vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
898 stars 56 forks source link

Page response type ignored #703

Open simasch opened 1 year ago

simasch commented 1 year ago

I have this endpoint method:

@Nonnull
public Page<@Nonnull Person> list(String filter, Pageable pageable) {

This generates:

function _list(
 filter: string | undefined,
 pageable: Pageable | undefined,
 __init?: EndpointRequestInit
): Promise<Array<Person>>
{
 return client.call('PersonEndpoint', 'list', {filter, pageable}, __init);
}

As you can see the return type Page is ignored.

Why is that? If I would like the result as Page I cannot do that and have to create my own result type .

platosha commented 1 year ago

It was introduced in https://github.com/vaadin/flow/pull/11648 in order to support returning Page from endpoints somehow. The idea back then was that a simple array result is enough.

The old generator was struggling to emit the Page directly, as it is coming from a dependency, which source is not available, and reflection support was lacking.

Since this is unexpected, we could improve this for the new generator, and the old one could use a better (more similar to Page) internal representation as a workaround.

Until this is fixed, please use a DTO as a workaround.

platosha commented 1 year ago

Hm-m, actually it would be preferable to fix this issue in a way that keeps the same behavior in the old and new generator. I’m marking this as a blocker, so that it is fixed before the 2.0 major release.

platosha commented 1 year ago

After one more take on this, it turns out that generic entities such as Page were not supported. Fixing this issue is blocked by https://github.com/vaadin/hilla/issues/579

Sadly it is not possible to fix in the 2.0 beta at the moment. Let us revisit this after adding support for generic entities.

nav-nilesh-kumar commented 1 year ago

I am facing the same problem. Looks like it is not fixed yet. Hope to see this gets fixed in the future. As a workaround, I am also using a Custom DTO for page objects.

thiagonuic commented 5 months ago

+1 for fixing this.