✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Troubleshooting a Query Error in Nuxt

6 replies
Last updated: Jan 16, 2023
This qroq query creates an excerpt/summary from the body text by taking the first 100 characters.
<script>

import { groq } from "@nuxtjs/sanity";

export default {

async asyncData({ $sanity }) {
`const query = groq`*[_type == "project"]{`

title,

mainImage,

createdAt,
`"excerpt": array::join(string::split((body[0].children[0].text), "")[0..100], "") + "..."}`;`

const projects = await $sanity.fetch(query);

return { projects };

},

}

</script>
Hi guys, very very minor problem here
😂 The query expects a
}
and I don't know where it's supposed to go.

ClientError
expected '}' following object body
Jan 16, 2023, 4:04 PM
Try putting it at the very end directly behind the last closing }
Jan 16, 2023, 6:24 PM
Hi,
user G
. Thank you for the response, but I'm afraid I don't quite get what you mean.
Jan 16, 2023, 6:28 PM
directly before the script tag
Jan 16, 2023, 6:30 PM
I'm afraid that didn't work.
Jan 16, 2023, 6:36 PM
You know, I once changed the api version in the desk to v1 and it gave errors. But any version after 2021-10-21 gives the correct output
Jan 16, 2023, 6:40 PM
Anybody else have this issue? I am using nuxt (vue framework).
Jan 16, 2023, 7:47 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?