-
Notifications
You must be signed in to change notification settings - Fork 42
feat: support proxying useSanityQuery requests #1286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
β Deploy Preview for nuxt-sanity-module ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
0ba1f8f to
4dc067c
Compare
commit: |
4dc067c to
7d9ee0b
Compare
a92101c to
bb09f6b
Compare
| if (writeTimer) clearTimeout(writeTimer) | ||
| writeTimer = setTimeout(async () => { | ||
| try { | ||
| await writeFile(queriesFilePath, JSON.stringify(queryArr), 'utf8') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? π
314ef79 to
f832e7a
Compare
f832e7a to
1cf6123
Compare
1cf6123 to
85c34a2
Compare
π Linked issue
N/A
β Type of 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.