Issue with data query after adding apiVersion to the client in Next.js Sanity client.
12 replies
Last updated: Jan 18, 2022
J
Has anyone experienced breaks when adding the apiVersion to the client?
I did not have any version in my Next.js sanity client, so I started getting a warning about the future deprecation and I added it, but after doing that some of the data I query is undefined and I don’t understand why, if it’s due to some update or what. When I comment out the apiVersion all works fine
I did not have any version in my Next.js sanity client, so I started getting a warning about the future deprecation and I added it, but after doing that some of the data I query is undefined and I don’t understand why, if it’s due to some update or what. When I comment out the apiVersion all works fine
Jan 17, 2022, 4:02 PM
A
Hey Jonathon. Would you be able to share the GROQ query that is now returning incomplete data?
Jan 17, 2022, 4:29 PM
J
Hey Ash, thanks for responding!
Sure, I think the problem is that some things are not working after the apiVersion: “2021-03-25”,
Sure, I think the problem is that some things are not working after the apiVersion: “2021-03-25”,
Jan 17, 2022, 4:35 PM
J
export const GET_MENU_FRAGMENT = (locale) => { return ` ..., _type == "link" => { _type, "linkTo": linkTo->, "text": coalesce(text[${locale}], text.en_eu), ... }, _type == "externalLink" => { _type, url, "text": coalesce(text[${locale}], text.en_eu), ... }, _type == "dropdown" => { _type, "text": coalesce(text[${locale}], text.en_eu), dropdownItems[]{ type, "title": coalesce(text[${locale}], text.en_eu), "text": coalesce(text[${locale}], text.en_eu), url, linkTo->, "previewTitle": coalesce(previewTitle[${locale}], previewTitle.en_eu), "previewParagraph": coalesce(previewParagraph[${locale}], previewParagraph.en_eu), "previewImage": previewImage { _type, asset-> }, "previewTag": coalesce(previewTag[${locale}], previewTag.en_eu), ... }, ... }`; };
Jan 17, 2022, 4:36 PM
J
This is a general fragment I am using for a menu item
Jan 17, 2022, 4:36 PM
J
coalesce()does not seem to work anymore
Jan 17, 2022, 4:36 PM
J
and joining the reference using
linkTo->does not seem to work anymore
Jan 17, 2022, 4:37 PM
J
user E
Jan 17, 2022, 4:37 PM
J
When I log the data without the apiVersion, everything works fine, but after that date, the query does not work the same, I checked the changelog but there was nothing about using -> for reference or coalesce
Jan 17, 2022, 4:38 PM
A
Thanks for providing the example query. I'll take a closer look at this for you.
Jan 17, 2022, 4:39 PM
Hi Jonathan. I suspect it’s the placement of your ellipses . In
v1, they could come before or after your named attributes and it wouldn’t matter—the named attribute would always “win.” In
v2021-03-25and later, the placement matters, so what’s happening is the
textfield coming back from
…is overriding your named
textfield. If you move the
…to the start of each object, it should work again.
Jan 17, 2022, 5:51 PM
J
You were right! Thanks so much this fixed my problem
user A
🔥Jan 18, 2022, 10:16 AM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.