Functions quick start
Functions new document change events and filtering options!
v2025-08-20
We are excited to give developers more document change events to trigger their Functions! The new events are:
create
: Emitted when a document is created.delete
: Emitted when a document is deleted.update
: Emitted when a document is updated.
Additionally, two new boolean toggles are available when defining the triggering event for your Functions:
includeDrafts
: Whether the event should be emitted with respect to draft documents. Defaults tofalse
.includeAllVersions
: Whether the event should be emitted with respect to version documents (documents part of a Content Release). Defaults tofalse
.
Keep in mind that combining update
with includeDrafts
and/or includeAllVersions
may result in many, rapid, invocations whenever changes are synced. See the rate limits and use with caution.
Note that these new events and options have significant overlap with the existing publish
event. In fact, publish
can be defined as:
on: ['create', 'update']
, andincludeAllVersions: true
The publish
event was an early beta attempt at encapsulating a useful, initial first-pass at a Functions source event.
These new additions set up a deprecation of the publish
event, so keep an eye out for that to officially land sometime in the near future. If you want to get ahead of things, you can update any existing function events that use on: ['publish']
to instead use the on
and includeAllVersions
values mentioned above—or make them more specific for your needs.
Support for these new events and filters landed in the following tools under the specified versions. Upgrade to at least these versions to take advantage of the changes:
@sanity/blueprints
v0.2.0sanity
CLI v4.5.0
Functions `projection` breaking change
v2025-08-06
Why we're making the change
⚠️ Previously, we accepted GROQ projections in function event definitions that were not wrapped in curly braces ({}
). Behind the scenes, we would transparently wrap your projection with curly braces.
📣 In order to better support the full GROQ specification, as of now, if you wish to receive an object as a projection in your function invocation, you are required to wrap your projection in curly braces.
Before
❌ Previously, you could provide the following projection that expressed "give me an object with _id
and type
properties":
{
"on": ["publish"],
"filter": "_type == 'post'",
"projection": "_id, type"
}
Now, trying to create or update a function with the above projection
will yield an error like:
Failed to manage function subscription: Failed to validate document change event rule: projection is invalid: parse error at position 3: unable to parse entire expression"
After
✅ Instead, wrap the projection
with curly braces:
{
"on": ["publish"],
"filter": "_type == 'post'",
"projection": "{_id, type}"
}
This explicitly says that you want an object.
Existing functions
If you have an existing function deployed to Sanity, we've migrated the deployed code to the new syntax. Your function will continue to work as it has without any intervention.
Prior to your next deployment, you will need to update any projections to use the new syntax. In short, wrap your projection in curly braces as shown above and then deploy the changes.
Functions now supports full GROQ syntax
v2025-07-29
Up until now, customers using GROQ to limit the scope of Function invocations did not have access to the full suite of GROQ functions and features. Powerful abilities like Delta functions or document dereferences were unfortunately not supported in the initial release of Functions, and if you tried to deploy a Function using either of these features (among others), you would see an error during your Blueprint deployment.
However, that is no longer the case! You can now use the full power of GROQ with Functions.
At this time, locally invoked functions do not support these additional GROQ features and may return an error when running npx sanity functions test
or npx sanity functions dev
.
We recommend testing locally without the added filter or projection changes, then using logs to test deployed functions with the added features.
Types included for Functions and additional bugfixes and improvements
v3.89.0
✨ Highlights
TypeScript types for Functions
Functions now have official types available. When selecting "TypeScript" after running sanity blueprints add function
, you'll be prompted if you'd like to include the type package and handler.
You can also manually install types by adding the @sanity/functions
package to your function. See the Functions quick start or function handler reference for usage details.
🐛 Notable bugfixes
- Adds a notification for when a media library cannot be found (#9387) (9a2039cbd3)
- Removes linting configs from app templates (#9421) (3ae5104dc2)
- Adds fix for hanging requests (#9433) (e57b96c9dc)
- Updates React Compiler dependencies 🤖 ✨ (#9440) (7ac692662b)
- Updates dependency @sanity/client to ^7.2.2 (#9448) (7e52ce2039)
- Improves connection error handling (#5893) (974be5178e)
Install or upgrade Sanity Studio
To initiate a new Sanity Studio project or upgrade an existing one, please refer to our comprehensive guide on Installing and Upgrading Sanity Studio.