Issue with API version and GROQ query in Sanity.io resolved successfully.
Looking at your error, I can see the problem! The key clue is in the error details: 'query': '[object Object]'. This means you're passing an object to sanity.fetch() instead of a GROQ query string.
The issue is in this line:
const domains = await sanity.fetch(await getProjectDomains());The fetch() method expects a string like '*[_type == "projects"]', but getProjectDomains() is returning an object. When JavaScript tries to convert that object to a string, it becomes "[object Object]", which is invalid GROQ syntax - hence the parse error.
To fix this, either:
- Pass the query string directly:
const domains = await sanity.fetch('*[_type == "projects"]');- Or make sure
getProjectDomains()returns a string:
function getProjectDomains() {
return '*[_type == "projects"]'; // Return the string, not an object
}
const domains = await sanity.fetch(getProjectDomains());
// No await needed unless getProjectDomains is actually asyncRegarding your API version question:
The apiVersion: '2021-10-21' you're seeing is totally fine! Sanity uses date-based API versioning to ensure compatibility. You set this when creating your client:
import {createClient} from '@sanity/client'
const sanity = createClient({
projectId: 'your-project-id',
dataset: 'production',
apiVersion: '2021-10-21', // Any date works - this locks API behavior
useCdn: true
})You can use any date like '2024-01-01' or '2023-05-03'. The date locks in the API behavior from that point, protecting you from breaking changes. The most recent version is 2025-02-19 which changed the default perspective from raw to published.
The Vision tool might show a different version, but that's just its own configuration - it doesn't affect your code. Your error is purely about passing an object instead of a string to fetch().
Sanity β Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.