feat(codegen): Allow query reponse types to be overridden through SanityQueries #858
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is one of two PR's that implements my feature request (sanity-io/sanity#6934) in
sanity-io/sanity
, with the help of some pointers from @sgulseth.The companion PR that implements the code generation for the newly introduced
SanityQueries
lives at sanity-io/sanity#6997.It sets up the
@sanity/client
package to have an interfaceSanityQueries
that@sanity/codegen
(or other packages) can hook into assign custom query types automatically based on the queries that are found in the codebase.This makes it possible to write code that is fully self-typing:
I have tried to set things up so that they are backwards compatible. Users can still manually
pass the types they want to the query, and the type signatures don't change. I have not touched any existing tests and type tests.
For a way to test the type changes, create a file like the above example and ensure all the types line up with what's expected.
There is also a TS Playground that summarizes the changes made by this PR and the companion PR.