dotcom-rendering icon indicating copy to clipboard operation
dotcom-rendering copied to clipboard

Make Sure Recipe Elements Are Handled Gracefully By AR, DCR, Frontend And Editions Backend

Open JamieB-gu opened this issue 1 year ago • 4 comments

Content Pipeline have added a new recipe element to the CAPI models: https://github.com/guardian/content-api-models/pull/228

### Tasks
- [ ] Test AR
- [ ] Test Editions
- [ ] Test Frontend And DCR
- [ ] Update the CAPI client with the new models
- [x] Update frontend with the new CAPI client and models
- [ ] Update MAPI with the new CAPI client and models
- [ ] Update AR and Editions backend with the new models
- [ ] Modify `scrooge-extras` to generate a TS equivalent of `EnumUnknownElementType`

Testing The CAPI Change

CAPI may start including this element in its responses before the platforms are updated to understand it. We would like to make sure that they can handle this.

AR

MAPI retrieves CAPI's data in Thrift format, and forwards that to AR. AR uses the @guardian/content-api-models package to deserialise this Thrift data into TypeScript format. The presence of a new element that's not handled by the code may cause breakages in AR, although it looks like AR ignores elements it doesn't understand so in practice this may be ok:

https://github.com/guardian/dotcom-rendering/blob/6c64d4302865d358358564924248c752c7c868a0/apps-rendering/src/bodyElement.ts#L469-L473

https://github.com/guardian/dotcom-rendering/blob/6c64d4302865d358358564924248c752c7c868a0/apps-rendering/src/item.ts#L393-L396

Nonetheless, we should test on CODE to make sure. @jonathonherbert has discovered that https://github.com/guardian/scrooge-extras does not generate EnumUnknownElementType for enum members it doesn't understand (which is what Scrooge itself does for Scala), so it's possible the Thrift deserialisation in AR may not handle this gracefully.

@jonathonherbert has suggested we update scrooge-extras to generate a TS equivalent of EnumUnknownElementType, to mitigate this problem in future.

Editions

Editions articles use AR, so if AR works then Editions should too. We should probably also test this with the Editions backend pipeline however, because that project also uses CAPI's TS models (and forwards the Thrift to AR).

DCR

DCR doesn't use CAPI's models directly; frontend retrieves the data, rewrites it, and sends it to DCR as JSON. @alinaboghiu has pointed out that frontend filters to a pre-defined list of elements before sending them to DCR:

https://github.com/guardian/frontend/blob/56647356209e9e612b1ee7f5a46db1509f26e305/common/app/model/dotcomrendering/DotcomRenderingUtils.scala#L234

Therefore it's likely DCR will continue to work with this change.

Frontend

As mentioned above, Scrooge generates EnumUnknownElementType for enum members it doesn't understand, which frontend should already handle.

Updating The CAPI Models

Depending on the results of the above tests, the platforms may gracefully handle any CAPI responses with an element they don't understand, as they will treat it as an unknown element. However, once the platforms do update the model dependencies, the element will be parsed as something that is understood and therefore may need to be handled. For example, in frontend and MAPI it will go from EnumUnknownElementType to Recipe.

We should make sure we update the dependencies as part of this work. That way any changes that are required to handle this don't fall to people working on this code in future. This will likely involve:

  • Updating the CAPI client with the new models
  • Updating frontend with the new CAPI client and models
  • Updating MAPI with the new CAPI client and models
  • Updating AR and Editions backend with the new models

JamieB-gu avatar Oct 20 '23 17:10 JamieB-gu

Thanks for this! Quick double check –

> AR uses Thrift to deserialise the data into TypeScript format.

should I think be

> AR uses @guardian/content-api-models to deserialise Thrift into TypeScript format

jonathonherbert avatar Oct 20 '23 17:10 jonathonherbert

A CAPI URL you can use in CODE to find an example of a recipe element is: https://content.code.dev-guardianapis.com/search?contains-element=recipes&show-fields=all&api-key=INTERNAL TIER KEY

tonytw1 avatar Oct 23 '23 08:10 tonytw1

@guardian/content-platforms would your team be able to pick this up if we offer some support from the webX side?

alinaboghiu avatar Oct 24 '23 10:10 alinaboghiu

Frontend is handled in https://github.com/guardian/frontend/pull/26926

alinaboghiu avatar Feb 29 '24 10:02 alinaboghiu