GROQ: New GROQ functions to interact with Global Document References (GDR)

This update adds improved ways of interacting with and detecting Global Document References (GDR). At this time, these are mostly limited to queries that interact with Media Library assets.

✨ Highlights

Get incoming GDR count

You can now use the documents::incomingGlobalDocumentReferenceCount() function in GROQ to check if a document has incoming GDRs. This only returns the number of GDRs referencing the current document scope.

// Find all documents being referenced by at least 1 GDR, and return the document's ID and reference count
*[documents::incomingGlobalDocumentReferenceCount() > 0] {
_id,
"incomingGDRCount": documents::incomingGlobalDocumentReferenceCount()
}

Resolve GDR references

In case you missed it, you can also use documents::get(media), where media is the reference, to resolve GDRs similar to the -> syntax used with normal references.

*[_type == "post"][0]{
_id,
mainImage{
"url": asset->url,
"mlAsset": documents::get(media)
}
}