๐Ÿ˜Ž Discover cool tips and tricks for customization in our next Developer Deep Dive virtual event - sign up now!

Using global studio client without specifying API version

In a previous version of the Sanity content studio, you could import a global, preconfigured Sanity client from part:@sanity/base/client. From version 2.7.0 and onwards, you should now specify which API version you want to use:

import sanityClient from 'part:@sanity/base/client'

const client = sanityClient.withConfig({
  apiVersion: 'v2021-03-25'
})

client.fetch('/* ... */')

To explain why this is necessary, consider the following scenario:

  • Plugin A is released in 2020, and contains queries and API calls that are written for API version v1.
  • Plugin B is released in 2021, and contains queries and API calls that are written for API version v2020-03-25.
  • If both plugins had to use the same API version, you would either have to wait for the plugin authors to align on a single version, or have the risk of the plugins breaking.

By allowing each plugin to declare which API version they want to use, we can use multiple different API versions within the studio, without causing any issues.

Backwards compatibility

Using the global client without specifying an API version will still work as before (using v1 for API calls), but will give a warning message in the developer console telling you to specify an API version.

Was this article helpful?