Instance properties
Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
GROQ-filter to listen to changes for
Optionalparams: ListenParamsOptional query parameters
Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
GROQ-filter to listen to changes for
Optionalparams: ListenParamsOptional query parameters
Optionaloptions: ListenOptionsOptional listener options
Clone the client - returns a new instance
Returns the current client configuration
Reconfigure the client. Note that this mutates the current client.
OptionalnewConfig: Partial<ClientConfig>Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns an observable that resolves to the created document.
Document to create
Mutation options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns an observable that resolves to an array containing the created document.
Document to create
Mutation options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns an observable that resolves to a mutation result object containing the ID of the created document.
Document to create
Mutation options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns an observable that resolves to a mutation result object containing the ID of the created document.
Document to create
Mutation options
Create a document. Requires a _type property. If no _id is provided, it will be generated by the database.
Returns an observable that resolves to the created document.
Document to create
Optionaloptions: BaseMutationOptionsMutation options
Create a document if no document with the same ID already exists. Returns an observable that resolves to the created document.
Document to create
Mutation options
Create a document if no document with the same ID already exists. Returns an observable that resolves to an array containing the created document.
Document to create
Mutation options
Create a document if no document with the same ID already exists. Returns an observable that resolves to a mutation result object containing the ID of the created document.
Document to create
Mutation options
Create a document if no document with the same ID already exists. Returns an observable that resolves to a mutation result object containing the ID of the created document.
Document to create
Mutation options
Create a document if no document with the same ID already exists. Returns an observable that resolves to the created document.
Document to create
Optionaloptions: BaseMutationOptionsMutation options
Create a document if it does not exist, or replace a document with the same document ID Returns an observable that resolves to the created document.
Document to either create or replace
Mutation options
Create a document if it does not exist, or replace a document with the same document ID Returns an observable that resolves to an array containing the created document.
Document to either create or replace
Mutation options
Create a document if it does not exist, or replace a document with the same document ID Returns an observable that resolves to a mutation result object containing the ID of the created document.
Document to either create or replace
Mutation options
Create a document if it does not exist, or replace a document with the same document ID Returns an observable that resolves to a mutation result object containing the created document ID.
Document to either create or replace
Mutation options
Create a document if it does not exist, or replace a document with the same document ID Returns an observable that resolves to the created document.
Document to either create or replace
Optionaloptions: BaseMutationOptionsMutation options
Deletes a document with the given document ID. Returns an observable that resolves to the deleted document.
Document ID to delete
Options for the mutation
Deletes a document with the given document ID. Returns an observable that resolves to an array containing the deleted document.
Document ID to delete
Options for the mutation
Deletes a document with the given document ID. Returns an observable that resolves to a mutation result object containing the deleted document ID.
Document ID to delete
Options for the mutation
Deletes a document with the given document ID. Returns an observable that resolves to a mutation result object containing the deleted document ID.
Document ID to delete
Options for the mutation
Deletes a document with the given document ID. Returns an observable that resolves to the deleted document.
Document ID to delete
Optionaloptions: BaseMutationOptionsOptions for the mutation
Deletes one or more documents matching the given query or document ID. Returns an observable that resolves to first deleted document.
An object with either an id or query key defining what to delete
Options for the mutation
Deletes one or more documents matching the given query or document ID. Returns an observable that resolves to an array containing the deleted documents.
An object with either an id or query key defining what to delete
Options for the mutation
Deletes one or more documents matching the given query or document ID. Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
An object with either an id or query key defining what to delete
Options for the mutation
Deletes one or more documents matching the given query or document ID. Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
An object with either an id or query key defining what to delete
Options for the mutation
Deletes one or more documents matching the given query or document ID. Returns an observable that resolves to first deleted document.
An object with either an id or query key defining what to delete
Optionaloptions: BaseMutationOptionsOptions for the mutation
Deletes the draft or release version of a document.
Version action parameters:
releaseId - The ID of the release to discard the document from.publishedId - The published ID of the document to discard.Optionalpurge: booleanif true the document history is also discarded.
Optionaloptions: BaseActionOptionsAdditional action options.
an observable that resolves to the transactionId.
releaseId will discard the draft version of the published document.Perform a GROQ-query against the configured dataset.
GROQ-query to perform
Optionalparams: QueryWithoutParams | QPerform a GROQ-query against the configured dataset.
GROQ-query to perform
Optional query parameters
Optionaloptions: FilteredResponseQueryOptionsOptional request options
Perform a GROQ-query against the configured dataset.
GROQ-query to perform
Optional query parameters
Request options
Perform a GROQ-query against the configured dataset.
GROQ-query to perform
Optional query parameters
Request options
Get a Sanity API URL for the data operation and path provided
Data operation (eg query, mutate, listen or similar)
Optionalpath: stringPath to append after the operation
Fetch a single document with the given ID.
Document ID to fetch
Request options
Fetch a single document with the given ID.
Document ID to fetch
Optionaloptions: {Request options
Fetch multiple documents in one request.
Should be used sparingly - performing a query is usually a better option.
The order/position of documents is preserved based on the original array of IDs.
If any of the documents are missing, they will be replaced by a null entry in the returned array
Document IDs to fetch
Optionaloptions: { tag?: string }Request options
Get a Sanity API URL for the URI provided
URI/path to build URL for
OptionalcanUseCdn: booleanWhether or not to allow using the API CDN for this route
Perform mutation operations against the configured dataset Returns an observable that resolves to the first mutated document.
Mutation operations to execute
Mutation options
Perform mutation operations against the configured dataset. Returns an observable that resolves to an array of the mutated documents.
Mutation operations to execute
Mutation options
Perform mutation operations against the configured dataset Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
Mutation operations to execute
Mutation options
Perform mutation operations against the configured dataset Returns an observable that resolves to a mutation result object containing the mutated document IDs.
Mutation operations to execute
Mutation options
Perform mutation operations against the configured dataset Returns an observable that resolves to the first mutated document.
Mutation operations to execute
Optionaloptions: BaseMutationOptionsMutation options
Create a new buildable patch of operations to perform
Document ID to patch
Optionaloperations: PatchOperationsOptional object of patch operations to initialize the patch instance with
Patch instance - call .commit() to perform the operations defined
Create a new buildable patch of operations to perform
Array of document IDs to patch
Optionaloperations: PatchOperationsOptional object of patch operations to initialize the patch instance with
Patch instance - call .commit() to perform the operations defined
Create a new buildable patch of operations to perform
An object with query and optional params, defining which document(s) to patch
Optionaloperations: PatchOperationsOptional object of patch operations to initialize the patch instance with
Patch instance - call .commit() to perform the operations defined
Replaces an existing version document.
Optionaloptions: BaseActionOptionsAdditional action options.
an observable that resolves to the transactionId.
_type property.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.releaseId will replace the draft version of the published document.client.observable.replaceVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be patched:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.replaceVersion({
document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
// `publishedId` and `releaseId` are not required since `document._id` has been specified
})
// The following document will be patched:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.replaceVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
})
// The following document will be patched:
// {
// _id: 'drafts.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Replaces an existing version document.
Optionaloptions: BaseActionOptionsAdditional action options.
an observable that resolves to the transactionId.
_type property.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.releaseId will replace the draft version of the published document.client.observable.replaceVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be patched:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.replaceVersion({
document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
// `publishedId` and `releaseId` are not required since `document._id` has been specified
})
// The following document will be patched:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.replaceVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
})
// The following document will be patched:
// {
// _id: 'drafts.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Perform an HTTP request against the Sanity API
Request options
Create a new transaction of mutations
Used to indicate when a document within a release should be unpublished when the release is run.
Version action parameters:
releaseId - The ID of the release to unpublish the document from.publishedId - The published ID of the document to unpublish.Optionaloptions: BaseActionOptionsAdditional action options.
an observable that resolves to the transactionId.
Clone the client with a new (partial) configuration.
OptionalnewConfig: Partial<ClientConfig>New client configuration properties, shallowly merged with existing configuration
Creates a new version of a published document.
Optionaloptions: BaseActionOptionsAdditional action options.
an observable that resolves to the transactionId.
_type property.releaseId will create a new draft version of the published document.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.client.create method.client.observable.createVersion({
// The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.createVersion({
document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
// `publishedId` and `releaseId` are not required since `document._id` has been specified
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.createVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
})
// The following document will be created:
// {
// _id: 'drafts.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Creates a new version of a published document.
Optionaloptions: BaseActionOptionsAdditional action options.
an observable that resolves to the transactionId.
_type property.releaseId will create a new draft version of the published document.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.client.create method.client.observable.createVersion({
// The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.createVersion({
document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
// `publishedId` and `releaseId` are not required since `document._id` has been specified
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.createVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
})
// The following document will be created:
// {
// _id: 'drafts.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Creates a new version of a published document.
Optionaloptions: BaseActionOptionsAdditional action options.
an observable that resolves to the transactionId.
_type property.releaseId will create a new draft version of the published document.document._id is defined, it should be a draft or release version ID that matches the version ID generated from publishedId and releaseId.document._id is not defined, it will be generated from publishedId and releaseId.client.create method.client.observable.createVersion({
// The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
releaseId: 'myRelease',
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.createVersion({
document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
// `publishedId` and `releaseId` are not required since `document._id` has been specified
})
// The following document will be created:
// {
// _id: 'versions.myRelease.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
client.observable.createVersion({
document: {_type: 'myDocument', title: 'My Document'},
publishedId: 'myDocument',
})
// The following document will be created:
// {
// _id: 'drafts.myDocument',
// _type: 'myDocument',
// title: 'My Document',
// }
Deprecated
-- Use
import {ObservableSanityClient} from '@sanity/client'instead