Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Issue with data query after adding apiVersion to the client in Next.js Sanity client.

12 replies
Last updated: Jan 18, 2022
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
Jan 17, 2022, 4:02 PM
Hey Jonathon. Would you be able to share the GROQ query that is now returning incomplete data?
Jan 17, 2022, 4:29 PM
Hey Ash, thanks for responding!
Sure, I think the problem is that some things are not working after the apiVersion: “2021-03-25”,
Jan 17, 2022, 4:35 PM
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
This is a general fragment I am using for a menu item
Jan 17, 2022, 4:36 PM
coalesce()
does not seem to work anymore
Jan 17, 2022, 4:36 PM
and joining the reference using
linkTo->
does not seem to work anymore
Jan 17, 2022, 4:37 PM
user E
Jan 17, 2022, 4:37 PM
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
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-25
and later, the placement matters, so what’s happening is the
text
field coming back from
is overriding your named
text
field. If you move the
to the start of each object, it should work again.
Jan 17, 2022, 5:51 PM
You were right! Thanks so much this fixed my problem
user A
🔥
Jan 18, 2022, 10:16 AM
Glad to hear it!
Jan 18, 2022, 6:16 PM

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.

Was this answer helpful?