5

If using DD4T2 and publishing JSON, is it possible to request individual component field elements from the published JSON (e.g. for a page or a DCP) using the GraphQL Content Service (in Tridion Sites 9), or would I need to request the whole JSON for the page/DCP using the GraphQL Content Service and then parse it in my code?

I saw from Oleksii and Ben’s TDS presentation (https://vimeo.com/293897994#t=31m10s) that we can get the ‘raw data’ for the published JSON, but I wonder whether we can drop into that in the query and just have the GraphQL Content Service return, for example, an individual content field from a component?

One of the big advantages of GraphQL is being able to retrieve only small data packets. Obviously that it not so valuable if we can't return just individual component fields and instead have to send the JSON for the whole Page/DCP over the wire (and process it).

2 Answers 2

3

Unfortunately, the DD4T JSON (or DXA R2 JSON for that matter) is basically just a blob of text for the Content Service.

Indeed, the GraphQL Content Service provides a feature to return JSON content as JSON within the GraohQL result (rather than an escaped JSON string), but that is as far as it goes; it is not really structured data which can be filtered or queried.

There are ideas to improve this in Sites 9.5, though.

4

Rick already answered to clarified.

Indeed!, there is no OOTB way to retrieve individual components fields values of published DCP and page JSON outputs, but It's possible to do a Graph-QL extension using the ‘CDGraphQLSchemaExtension’ extension point. This is available in Sites 9.0 but with limited support as it is currently not documented. It will fully be supported in 9.1 when R&D introduces the new Add-On service UnifiedExtension mechanism.

For now, the content part is returned as “untyped JSON” and can’t be selected via GraphQL. This is something R&D looking into for 9.5. So writing your own extension you can either add new custom fields or transform the content body to something else.

Updated (March 9th): In Sites 9.5 Templates Data-only publishing, and semantic content models (custom GraphQL Schema) It's possible to query individual fields.

You have two approaches to consume your published data:

  • As-is called “untyped content”
  • By defining custom semantic models that allow you to map JSON transformations to either change the structure of your content or retrieve only some fields of a JSON data fragment.

Useful references:

Note: AFAIK In Sites 9.6 release automatic semantic models generated based on schemas fields to query individual fields without the need to define custom semantic models, I love this feature and look forward to this feature.

I hope it helps.

2
  • @Velu - Do we know if there have been any updates to 9.1 or 9.5 for OOTB? I do see that DXA model service is using GraphQL Schema Extension for Sitemap but no other useful information from documentation
    – Shiva
    Commented Mar 8, 2021 at 21:39
  • 1
    @Shiva - Updated my answer
    – Velmurugan
    Commented Mar 9, 2021 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.