refinedev / refine

A React Framework for building internal tools, admin panels, dashboards & B2B apps with unmatched flexibility.
https://refine.dev
MIT License
25.99k stars 1.97k forks source link

[BUG] Default GraphQL DataProvider GetListResponse from 'count' property not possible. #5942

Open jamesdh opened 1 month ago

jamesdh commented 1 month ago

Describe the bug

The default GraphQL providers getList function return the following GetListResponse shaped object:

https://github.com/refinedev/refine/blob/3046f9610f647bb049dbd388cd8cd5c267b481fa/packages/graphql/src/dataProvider/index.ts#L39-L42

As mentioned by another user on Discord (possibly @Karabur?), this does not make sense. In order for getList to function correctly with various integration points within Refine (like the MUI useDataGrid hook), response[operation] must return an array of objects. An array cannot have additional properties on it such as count. I'm not sure I understand how anybody could be using this default data provider out of the box with working pagination.

Steps To Reproduce

N/A. Per the graphQL spec, a list cannot have additional properties.

Expected behavior

I do not see how any GraphQL API could provide a response that would provide working pagination for the default GraphQL provider. Even the docs for useList indicate something considerably different, more akin to a Relay response.

Packages

Additional Context

No response

BatuhanW commented 1 month ago

Hey @jamesdh you are right, it's a bit illogical to expect a field in an array. GraphQL data provider, due to nature of GraphQL can't fit into every API so it's more like a blueprint to start building your own data provider. I just checked and it seems we are missing asserting count field in the tests. Nevertheless, this can be fixed to avoid confusion.

jamesdh commented 1 month ago

GraphQL data provider, due to nature of GraphQL can't fit into every API

True, but there are conventions for this frequently found in the wild that are based on the Relay spec. Specifically, Relay has the concept of Connection types. Connections must contain a PageInfo field. What you commonly see "in the wild" (but that is not part of the official spec) is that either the Connection object itself or the PageInfo object contain a "totalCount" property. I believe it's usually found on the Connection object, since it should not change between paginations (and hence it makes less sense for it to be on the PageInfo object).

In any case, the "path" in the object graph where this count property can be found should be something that is definable in the meta object along with the query. The same is true for where the intended data can be found, and thus #5943 could be fixed.