This topic is not about population, please discuss that topic here: Discussion regarding default population of REST
Current Status Post: Discussion regarding the complex response structure for REST & GraphQL (Developer Experience) - #35
Hello Everyone,
As mentioned in a news post in our Discord last week we wanted to setup this discussion around how the response structure is handled (nested data
& populate
) in Strapi v4.
If you haven’t already please read the following documents, pull requests, or issues before commenting:
- Original v4 RFC for REST: rfcs/xxxx-v4-rest-api.md at v4/rest-api · strapi/rfcs · GitHub
- Original v4 RFC for GraphQL: rfcs/xxxx-v4-graphql-api.md at v4/graphql-api · strapi/rfcs · GitHub
- Locked discussion topic issue: [V4] [RFC] GraphQL Developer Experience improvements 🥇 · Issue #11649 · strapi/strapi · GitHub
- Related comments the above mentioned issue (on GQL RFC PR): GRAPHQL API by Convly · Pull Request #29 · strapi/rfcs · GitHub
- JSON API structure of which this new system is based on: https://jsonapi.org/
Currently purposed suggestions:
- Revert to v3 style in GraphQL => Not possible at this moment
- Remove Attributes and throw everything under data in GraphQL => Not possible due to breaking changes
- Recommend usage of something like normalizr for REST Users + potentially integrate a normalization library in the Strapi SDK JS
Current status on v4:
At this time we are not prepared or planning to modify this data structure in the response, the time for that type of modification has passed as it should have been addressed during the RFC process. We do understand that it was not clear at the time during our RFC process this was the case and we are already doing retrospectives to improve this process.
In the short term we would rather explore options to optimize using this response structure on the client side and see how we can assist. An above mentioned suggestion of including normalization libraries in best practices or even sponsored SDKs (like the Strapi-SDK-JS is) is one example of what we believe could benefit everyone.
Why is Strapi using this structure?
The primary goal behind this new structure was to pick some kind of standard for a response structure, ideally not reinvent the wheel and try to use an already existing standard. In our case we picked JSON API: https://jsonapi.org/
(Image src: xkcd: Standards)
We have not entirely implemented the standard yet but our goal with the first release of Strapi v4 was to lay the groundwork so that we could continue to build on it without breaking changes. This meant unifying the REST and GraphQL data responses, error handling, filtering/paging system, ect.