First:
Create a custom route for that use case, attach a custom controller to it, which calls the core controller, but transforms the response to your needs.
Second:
Create a custom route which uses the default controller, but attach a custom middleware to it to transform the response to your needs after the default controller has returned the response.
Third:
Use Transformer | Strapi Market which reduces the depth of the returned object. You’d still have an object in the response, but it’s not as deeply nested.
After reading this topic my team decided stop using strapi and move to our own solution. It’s impossible to keep maintaining structure, update controllers always. Strapi v4 complete fail as product version, I can’t see future in this project
I invested a lot of time into strapi 3 - and dealt with the changes in strapi 4 with some client side transforms (a very poor solution I know) - but I think this will be the conclusion of most people looking at the data responses coming back from the server. Really hope it is acknowledged more and dealt with correctly. Strapi is a was a nice project but without addressing this issue I don’t see much of a future either. Unfortunately for me (and many I suspect) moving off will be painful, but necessary without changes. I wouldn’t have used strapi if I looked at Strapi 4 first as well.
We are now more that 1 year after that issue was open and, after a lot of “blabla”, the GraphQL schema is still the same nightmare. In addition, there is no plan to solve this in the futur (excluding v5, because no ETA nor clear commitment).
I have the following feedback:
a frontend SDK is NOT a solution in anyway, it just look like putting a band-aid on a wooden leg (what about CURL usage for ex. ?)
adding an option (disabled by default) in official GraphQL plugin, something like “use standardized Apollo schema” is NOT a breaking change so the “semver” arg is just irrelevant
the reason why this horrible schema was initially introduced is about adding new features in it but… one year later, where are that famous new features??
The logical conclusion is:
there is no real, strong reason to keep that schema
nothing will happens from Strapi side regarding that issue
So, if you are looking to build a new project with strapi and plan to use it’s API, just run away!
For existing project, you will have to schedule a backend migration in your roadmap.
Just started using stapi and started loving it and then suddenly hit boom… very sad to see it, but its nightmare to go with such graphql where meta is more important then data…
any good alternatives to strapi with solid graphql support and nice UI like strapi?
I just published very simple library which I use for my needs that can be used to flatten graphql responses from strapi v4. What I believe is neat, the typings in the library along with the flattener allow to transform nested typings to a proper flattened types.
Hi, can anyone recommend an approach how we solve the Apollo cache issues?
I am not looking to add a ‘flattener’ library to our projects, nor am I interested in extensive explanations about why the current implementation is the way it is. What I’m after are practical suggestions or strategies that I can use to resolve these Apollo cache problems.
I’ve been testing out strapi for our solution but the structure does seem like a nightmare. I’m considering using the strapi backend but connecting directly to MySQL to query the database. Thoughts?
Any opinion on doing the data transformation on front-end instead? I’d rather flatten the Strapi API response just for a few exceptions and leave Strapi untouched. The front-end project is already using zod for runtime type checking (forms mainly).
Directus? The reason I gave up on Directus was due to the short comings with it’s one role per user. Now I see Strapi has some major shortcomings as well.
You could look at Hasura, it doesn’t include the Admin UI like Strapi does but it does generate a very nice API from your database.
Hi, can anyone recommend an approach how we solve the Apollo cache issues?
I am not looking to add a ‘flattener’ library to our projects, nor am I interested in extensive explanations about why the current implementation is the way it is. What I’m after are practical suggestions or strategies that I can use to resolve these Apollo cache problems