I am Newbie & exploring the Dato CMS how to use and what it offers and how it can fulfill my use-cases, and I am using REST API Client to get the list of Records available under my Project.
Iāve below Schema Model for my Project:
SEO and Social
Single-line String
Structured Text
Single Asset
Single-line String
Single-line String
Slug
Date
Single Link (References)
when I am using the above-shared JavaScript CMA Client, I am getting below response:
where I am getting the ID of the Uploaded Image for this Single Asset and I am getting similar for SEO Meta which is as below:
"seo_details": {
"image": "Rt7tzv0JRsOE-5LqfpPlyA",
"title": "NPM dv-social-share",
"no_index": false,
"description": "dv-social-share is a powerful npm package for seamless social media sharing integration in Reactjs & Nextjs web app. Simplify sharing with ease!",
"twitter_card": "summary_large_image"
},
here I am getting ID only, and I am thinking to use react-datocms, can anyone help me or guide me how to display this Image in my Remix Project?
The GraphQL API seamlessly handles relationships between item types for you (such as records and images) and lets you fetch exactly the data you need in a single call. For example, to fetch an image alongside other record data: Images and videosā Content Delivery API ā DatoCMS
If youāve never used GraphQL before, weād encourage you to check it out. There is a very slight learning curve (just an hour or two, I think?) but itās very helpful for this use case of getting data from a CMS into your frontend.
While itās possible to do something similar with the REST API as well, it would require several independent calls (such as listing records and then separately fetching their uploads) and then joining all of that back together clientside (typically by ID).
Thanks for your quick help. Iāll look into GraphQL how to use it, and save my time with all this.
I want to ask is like after fetching the Data, how can I show that it to client? I mean in my Remix App, how do I display the content? for that I need to use react-datocms?
Well, thatās really up to you Thatās what makes this a āheadlessā system: itās entirely up to you how the frontend displays this content. You can render it to raw HTML, or compose complex and beautiful JSX components, or use a UI toolkit like MUI or Chakra.
Some of our bigger customers also choose to implement their own components instead using ours, which is totally fine too if they need more control. But ours should get you a āgood enoughā implementation for most use cases.
I want to understand one thing, if I am using GraphQL to retrieve the Article, which will retrieve Article + Image associated with it, so itāll be counted as only 1 Request or 2?
like in REST API, itāll be multiple API Calls which will be more than 1 Requestā¦
because 100k API calls each month are available under the Free Plan, so how itāll be counted for both REST API & GraphQL?
Each network request you send to the CDA or CMA is one call. Thatās one of the benefits of the GraphQL system: We handle the relationships on our side and you just get the data you need back, in one call. The CMAās intended purpose is for record updates (it supports writes) and exports. For your frontend, the GraphQL is more suitable (it only supports reads, not mutations, but it will handle the relationships and embedded links and such better).
If youāre trying to stay under the free plan limits for a production site, it would be best to not call the API directly from user browsers (clientside), but to do some sort of server-side fetching & building into static pages. That way youād only have to make API calls when something actually changes, not on every page load. Frameworks like Next should make that easy. At the very least, you can also do server-side rendering with caching (on a CDN) to at least limit the amount of requests that make it through to our API.
I want to know one more thing that inside of Structured Text how can I add Images? like mostly one after another? because in grid it wonāt be possibleā¦
so is that possible to add multiple Images inside of Structured Text?
like if I tell more clearly so what I want is like, I want to show/display some text, like some heading, some p tags and some bullet points, then show the images (maybe 2 or 3 or maybe 4) and then again show the some texts again.
I want to achieve this, can you please guide or help me how can I do this with Dato CMS?
Iād probably use Blocks for this. A Block is a DatoCMS term for a repeatable set of fields that you can embed into Structured Text (and modular content fields. That way, you can make a Block with a single-asset (or gallery field), add additional layout information there if needed (as hints for your frontend, e.g. to tell it you want the images āside by sideā or in a āmosaicā or āthumbnail galleryā or whatever).
That way, youād get a JSON of those images along with your Structured Text, and then after that itās up to your frontend how to display them.
Does that help? Please me know if you need a fuller example.
@roger Sorry to bother but can you please help me with fuller example? as am quite new to Dato CMS and still learning and exploring the potential of it⦠And Yes, I started a little and Yes it seems quite good.
Also, how can I render this Blocks into my FrontEnd with the use of react-datocms?
I also invited you to a sample project (please check your email) using that example.
Given a record like this: https://forum-5121-remix-blog.admin.datocms.com/editor/item_types/538956/items/19072917 (youāll have to accept the invitation to see it)
Then from that point on, itās up to your frontend (Remix and the example repo).
Can I ask if this is the kind of setup you were looking for? Iām just trying to make sure youāre not looking for something more WYSIWYG/no-code/low-code? DatoCMS is a āheadlessā CMS, so really, the primary thing we provide you is a JSON of your content. How you render that on the frontend is really up to you. Although we do provide JS helper libs for things like Structured Text, thatās just to assist in parsing them. Rendering the blocks in a particular way is still up to you and your frontend. The Remix example has a very basic example, but if you need more complex layouts than that, youād either have to use a UI kit (like I mentioned earlier) or write your own CSS to lay them out a certain way.
At that point itās not really about the CMS at all, but just your frontend (like how youād display any image, whether from Dato or a local file). Does that make sense?
Yes, I do have checked the Remix Example (GitHub) youāve shared, and based on that only Iām able to give it a shoot and started with it and created Records and populated over there⦠I just made a little change is that Iāve used fetch() here to get the Records from Dato CMS.
Furthermore, I just accepted the invitation to the sample project youāve shared to me, and in that I just tried to play with the GraphQL Query for Blocks, but in that I am not getting record.__typename: "ImageBlockRecord, or itāll be taken care by react-datocmsās StructuredText ?
Furthermore, suppose in 1st Image Block Iāve 3-4 Images, how can I identify that itās a Single Image or Multiple Image together?
Furthermore, I just accepted the invitation to the sample project youāve shared to me, and in that I just tried to play with the GraphQL Query for Blocks, but in that I am not getting record.__typename: "ImageBlockRecord , or itāll be taken care by react-datocms ās StructuredText ?
Iām not totally sure I understand the question, sorry? In GraphQL, you can either query for the __typename or the modelApiKey (different representations of the same thing):
Then from there you have to tell the frontend how to render it using the custom block renderer.
Furthermore, suppose in 1st Image Block Iāve 3-4 Images, how can I identify that itās a Single Image or Multiple Image together?
That depends on your schema. If your block only accepts a single image, it will be just that image. You can have multiple blocks one after another, each for one image.
If your block contains a gallery field (for multiple assets) then theyāll be an array.
In either case, youāll have to adjust the frontend to accommodate that.
Basically, to fetch record #1, youād say first: 1, skip: 0, to fetch the 2nd record itād be first: 1, skip 1, etc. You just keep track of which record youāre currently on and then skip however many you want.
But in many cases (like going prev/next between blog posts) it may be better to let your frontend router handle that instead, fetching all possible article IDs ahead of time and then passing them to a router so the next/prev links can be hardcoded. That way your users can just directly navigate to the next article instead of waiting for you to do an API lookup.
Unfortunately the Link you shared for generating the TypeScript Types from GraphQL, doesnāt seems to work as expected and the way I am lookingā¦
more specifically I am getting types error when I am running the loop on the Array, and that time either I need to define any or the proper types for it⦠For other fields like title, date, slug I can define the type as string correctly, but when it comes for the StructuredText data, block, I am getting the error for type/interface.
Sorry, it is difficult to replicate & debug this from these code snippets. Might it be possible for you to share your repo with us (r.tuan@datocms.com on Github) or make a separate minimal example for us?
Otherwise, you might be able to import the StructuredText types directly from our libs (possibly one of these react-datocms/src/StructuredText/index.tsx at master Ā· datocms/react-datocms Ā· GitHub). But unless you are doing some parsing on your own, I donāt know that it would get you anything over just marking them as any and using our lib to render them into HTML directly. (i.e. if you are trying to validate our response shape, you are redoing work that our internal libs should already be doing).
The TypeScirpt wonāt get you runtime/fetch time response type validation anyway⦠so if Iām understanding your use case here, maybe what you need instead is a simple try/catch block that makes sure the GraphQL response was successful, and that the resulting data block is valid and not empty? Itās just a sanity check, not a full type check, but it should be fine?
What Iām saying is that itās OK to just treat our structured text as a generic blob you donāt have to worry about typing individually, and you can use our renderer to override specific node rendering if you need to.
Does that help at all? Otherwise, can you please share a repo with us so we can take a deeper look at your specific use case?
that GitHub Link you shared regarding the type/interface that worked for me.
Actually I use the fetch() to get to Query the GraphQL, and when I am passing the response like data.datoCMSProject.value to Structured Text it was throwing error for any or unknown something and to resolve it I was needed the correct type for it to resolve it, TypesafeStructuredTextGraphQlResponse this resolved my problem.