{"id":55399,"date":"2022-08-22T15:20:44","date_gmt":"2022-08-22T09:50:44","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=55399"},"modified":"2024-06-10T15:40:15","modified_gmt":"2024-06-10T10:10:15","slug":"graphql-with-headless-cms-aemaacs","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/graphql-with-headless-cms-aemaacs\/","title":{"rendered":"GraphQL with Headless CMS (AEMaaCS)"},"content":{"rendered":"<h2><b>What is Headless CMS<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">CMS consist of Head and Body. Body is where the <\/span><b>content<\/b><span style=\"font-weight: 400;\"> is stored and head is where it is <\/span><b>presented<\/b><span style=\"font-weight: 400;\">. In Headless CMS the body remains constant i.e. in our case it will be AEM but there is no head, meaning we can decide the head on our own. This does not mean that you don&#8217;t want or need a head (presentation), it&#8217;s that you get to pick and choose which head\/s you send your body (content) to. It could be one or many.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-55389 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.07.02-PM-252x300.png\" alt=\"\" width=\"252\" height=\"300\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.07.02-PM-252x300.png 252w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.07.02-PM-859x1024.png 859w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.07.02-PM-768x916.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.07.02-PM-624x744.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.07.02-PM.png 1030w\" sizes=\"(max-width: 252px) 100vw, 252px\" \/><\/p>\n<h2><b>Benefits of Headless CMS<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">There are many benefits of using a headless CMS. If you benefit from the below points then you might want to consider using it:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Head (Presentation) can be decided freely.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Can use technologies which do not have easy editing of content features.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Content developers are not bothered about the presentation layer and vice versa.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Wider reach: You can present your content to different platforms which in return target a wider audience.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Security : As content and presentation are on different platforms access to those can be well managed and segregated<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">More revenue if you monetise your content.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Allows you to build a technology stack that can easily and quickly adapt to future digital experience demands.<\/span><\/li>\n<\/ol>\n<h2><b>What is GraphQL <\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">GraphQL is a query and manipulation language for APIs. GraphQL is a query language and server-side runtime for APIs that prioritizes giving clients exactly the data they request and no more.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Below are some of the basic queries:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-55390 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.09.06-PM-300x173.png\" alt=\"\" width=\"300\" height=\"173\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.09.06-PM-300x173.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.09.06-PM-1024x590.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.09.06-PM-768x442.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.09.06-PM-624x359.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.09.06-PM.png 1070w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/span><\/p>\n<h2><b>Configuration to Enable GraphQL on AEMCaaS<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Make sure you have the below configurations done in order to consume GraphQL:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Go to Tools \u2192 General \u2192 Configuration Browser \u2192 Open properties of your project. Enable content fragment models &amp; GraphQL persistent queries.<br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-55391 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.10.59-PM-223x300.png\" alt=\"\" width=\"223\" height=\"300\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.10.59-PM-223x300.png 223w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.10.59-PM.png 334w\" sizes=\"(max-width: 223px) 100vw, 223px\" \/><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Go to Tools \u2192 General \u2192 GraphQl.<br \/>\nCreate a new endpoint. Give any name and select your project for which you have done the configuration in the previous step. After creation you will see the endpoint which you will be using for connections.<\/span><\/span><\/li>\n<\/ol>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-55392 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.13.13-PM-300x222.png\" alt=\"\" width=\"300\" height=\"222\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.13.13-PM-300x222.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.13.13-PM.png 604w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">3. <\/span><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"> You also need to allo<\/span><\/span><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">w the endpoint in the CSRF Filter config. As on AEMaaCS you have to write all your configs in your code. Below is the config:<\/span><\/span><\/p>\n<h2><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-55393 size-full\" style=\"font-size: 1rem;\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.14.34-PM.png\" alt=\"\" width=\"938\" height=\"376\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.14.34-PM.png 938w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.14.34-PM-300x120.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.14.34-PM-768x308.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.14.34-PM-624x250.png 624w\" sizes=\"(max-width: 938px) 100vw, 938px\" \/><\/h2>\n<h2><\/h2>\n<h2><b>Creating Content Fragments<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">GraphQL only works with content fragments in AEM. For creating one please follow the steps below:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Go to Tools \u2192 Assets \u2192 Content fragments models (If you don\u2019t have Content Fragments Models here then that means your instance is not cloud sdk. You can find it under Tools \u2192 General).\n<p><\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create a new model. Open the model in editor mode. You can drag the data types from the right side to the editor pane. <\/span><\/span><span style=\"font-weight: 400;\">You can select different properties like label, placeholder, default value, max length, required, unique, translatable, validation, error message, description etc.<br \/>\n<\/span><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-55394 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.15.42-PM-1024x507.png\" alt=\"\" width=\"625\" height=\"309\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.15.42-PM-1024x507.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.15.42-PM-300x148.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.15.42-PM-768x380.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.15.42-PM-1536x760.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.15.42-PM-624x309.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.15.42-PM.png 1592w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Once you are done creating your model then go to Navigation \u2192 Assets \u2192 Files \u2192 Folder of your project. Open properties of the project folder and allow your model in policies.<\/span><\/span><\/span>&nbsp;\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-55395 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.16.47-PM-1024x398.png\" alt=\"\" width=\"625\" height=\"243\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.16.47-PM-1024x398.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.16.47-PM-300x116.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.16.47-PM-768x298.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.16.47-PM-624x242.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.16.47-PM.png 1226w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/li>\n<li><span style=\"font-weight: 400;\">Create a content fragment using your content fragment model.<\/span><\/li>\n<\/ol>\n<h2><b>Testing GraphQL Queries<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">You are now all set to use GraphQL to interact with AEM. But we should first test it using the GraphQL query editor. Go to Tools \u2192 General \u2192 GraphQL Query Editor (GQE). If you don\u2019t see the option here then you need to install GraphiQL package from software center. But I would highly recommend having a cloud sdk instance because the GQE which comes with the cloud sdk provides you the option to save and access persistent queries easily. Nevertheless irrespective of what your instance is, all persistent queries are saved at your project configuration folder like:\u00a0 <\/span><span style=\"font-weight: 400;\">\/conf\/ttn-cart-products\/settings\/graphql\/persistentQueries<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-55396 size-medium\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.18.24-PM-300x271.png\" alt=\"\" width=\"300\" height=\"271\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.18.24-PM-300x271.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.18.24-PM-768x693.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.18.24-PM-624x563.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.18.24-PM.png 958w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">On the GQE screen on the top right side of the screen you can select the endpoint on which you want to write queries for.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you get any error then do make sure you have performed all the steps in the configuration section above.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-55423 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.19.37-PM-1-1024x407.png\" alt=\"\" width=\"625\" height=\"248\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.19.37-PM-1-1024x407.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.19.37-PM-1-300x119.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.19.37-PM-1-768x305.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.19.37-PM-1-1536x610.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.19.37-PM-1-624x248.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.19.37-PM-1.png 2020w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In order to pass query parameters you can use Query Variables section<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-55422 size-large\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.22.45-PM-1-1024x500.png\" alt=\"\" width=\"625\" height=\"305\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.22.45-PM-1-1024x500.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.22.45-PM-1-300x146.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.22.45-PM-1-768x375.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.22.45-PM-1-1536x750.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.22.45-PM-1-624x305.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/08\/Screenshot-2022-08-22-at-12.22.45-PM-1.png 2024w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In order to access this outside AEM you can get the curl request of the queries you create in GQE and implement them using any other technology.<\/span><\/p>\n<p><b>References<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">https:\/\/experienceleague.adobe.com\/docs\/experience-manager-cloud-service\/content\/headless\/journeys\/developer\/overview.html?lang=en<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">https:\/\/www.sanity.io\/blog\/headless-cms-explained<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">GraphQL : https:\/\/www.youtube.com\/watch?v=ZQL7tL2S0oQ<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>What is Headless CMS\u00a0 CMS consist of Head and Body. Body is where the content is stored and head is where it is presented. In Headless CMS the body remains constant i.e. in our case it will be AEM but there is no head, meaning we can decide the head on our own. This does [&hellip;]<\/p>\n","protected":false},"author":1470,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":153},"categories":[5868,4308,4488],"tags":[4847,5008,5010,5009],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/55399"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=55399"}],"version-history":[{"count":13,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/55399\/revisions"}],"predecessor-version":[{"id":55429,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/55399\/revisions\/55429"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=55399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=55399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=55399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}