Reputation: 2421
We have implemented our graphql api response like this.
{
data: {...},
skip: 0,
limit: 10,
total: 100,
hasMore: true
}
If I query our api via graphiql the response looks like expected.
But unfortunately the apollo client in our application strips away all properties from the return object except data
.
Is this expected behaviour? And if so, how can I change it or solve this problem differently. I need to get the total amount of data to implement pagination accordingly.
I know there is a method with fetchMore
but it won't tell me the whole amount of entries in the list.
Upvotes: 2
Views: 493
Reputation: 84867
According to the spec only three top-level keys are expected -- data
, errors
and extensions
. If you include additional keys you're going off-spec -- I would not expect any client to attempt to read them.
At the end of the day, this information should be included in your schema and returned as part of the data
in the response. Returning it anywhere else (as additional keys in the response, as response headers, etc.) is a bad idea, if for no other reason than the fact that you could have multiple query fields at the root level, in which case you'd only be able to convey pagination information about one of the fields and it'd be unclear which field the information applied to. The same could be said if you have nested fields that can also be paginated.
Upvotes: 1