Skip to content

Conversation

@rdunk
Copy link
Collaborator

@rdunk rdunk commented Aug 14, 2025

πŸ”— Linked issue

N/A

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Introduces support for proxying requests made using useSanityQuery, this will allow apps that need to query private datasets to do so without having to use server components, and they can largely follow the same patterns as those used by apps that query public datasets.

It will be up to the user to implement their own server handler for proxying requests. However this PR also ships a useful helper (validateSanityQuery, see example in playground app) which makes this quite simple and means one handler can be used for all (most?) queries, rather than needing to create server handlers for each unique GROQ query users want to execute. The module now statically analyses all GROQ queries in the app at build time, so the helper can validate incoming queries against a whitelist to prevent use of this endpoint for other queries.

@netlify
Copy link

netlify bot commented Aug 14, 2025

βœ… Deploy Preview for nuxt-sanity-module ready!

Name Link
πŸ”¨ Latest commit 85c34a2
πŸ” Latest deploy log https://app.netlify.com/projects/nuxt-sanity-module/deploys/68c9486efe8a6b00085fb119
😎 Deploy Preview https://deploy-preview-1286--nuxt-sanity-module.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@rdunk rdunk force-pushed the feat/proxy-requests branch 5 times, most recently from 0ba1f8f to 4dc067c Compare August 18, 2025 12:46
@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 18, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@nuxtjs/sanity@1286

commit: 85c34a2

@rdunk rdunk force-pushed the feat/proxy-requests branch from 4dc067c to 7d9ee0b Compare August 18, 2025 13:18
@rdunk rdunk marked this pull request as ready for review August 18, 2025 16:32
@rdunk rdunk requested a review from danielroe as a code owner August 18, 2025 16:32
@rdunk rdunk force-pushed the feat/proxy-requests branch 2 times, most recently from a92101c to bb09f6b Compare August 23, 2025 10:00
if (writeTimer) clearTimeout(writeTimer)
writeTimer = setTimeout(async () => {
try {
await writeFile(queriesFilePath, JSON.stringify(queryArr), 'utf8')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to use addServerTemplate so this becomes a virtual file and we don't need to read from disk

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, I wasn't sure how to make this work with addServerTemplate so I'm all ears here!

Currently we only read from the disk at runtime in dev so we can have an up-to-date list, as we find queries incrementally using a Vite plugin during transform, which obviously processes files on demand. In prod, the Rollup plugin exposes a virtual module (#sanity-groq-queries) that reads that file at build time and inlines the contents, so there shouldn't be any runtime reading from disk, AFAIK.

I originally tried this using addServerTemplate, but realized that updateTemplates won't refresh virtual Nitro templates, so was struggling to make things work in dev. Is there another way to do that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @danielroe! Can I bump you on this one? πŸ˜…

@rdunk rdunk force-pushed the feat/proxy-requests branch 2 times, most recently from 314ef79 to f832e7a Compare September 1, 2025 12:13
@rdunk rdunk force-pushed the feat/proxy-requests branch from f832e7a to 1cf6123 Compare September 4, 2025 11:46
@rdunk rdunk force-pushed the feat/proxy-requests branch from 1cf6123 to 85c34a2 Compare September 16, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants