-
Notifications
You must be signed in to change notification settings - Fork 5
Rename resolve[d]
to resolve[d]Mock
#160
Description
As @mckelveygreg made clear in #158, some things about "resolve" are unclear:
s.resolved<...>
should be the type but with references resolved. Right now it's both parsed AND resolved. These should be two separate types.docType.resolve(mock)
doesn't describe that it's for mocks, so it implies it does something you'd want in application code, which is untrue.docType.resolve
anddocType.parse
should be independent. Resolving also parses, which is unexpected. We should be able to do both to the same doc, but it's unclear how this API should go.
This was a consequence of the main use case I made this library for, which is not everyone's use case:
- I query each document independently and fully. No expanded references, no projections, etc. Since I cache and traverse through application logic rather than in groq's syntax, none of this is an issue to me.
- Parsing everything right after querying is easy and non-conflicing with any types.
- Mocking for tests is easy, resolving the types there is mainly because my application logic does join these together and I'd like to have that in my tests.
However we go about fixing this, there's definitely breaking changes (which is fine). I think making s.resolved<...>
the same as s.infer<...>
, except references are the type of the resolved document should be easy.
The bigger issue is parsing. Parsing expects the value of the doc, and it essentially needs to handle a doc that has expanded references as well (and return the correct types). Expanded references are only one thing that a query can do that's "non-standard", which starts opening the door into parsing any valid query. Doing the work for this specific use case will likely cover a lot of use cases, but ultimately end up opening the door into individually solving the various groq query use cases.
Having a query builder that utilizes these types will get us type safe queries, typed outputs from those queries, and a parser that traverses all the way through to the query outputs. This will make the "typing docs with resolved references" an irrelevant problem: if we can type our queries, we'll type whichever references we happen to resolve, along with whatever else we want to do in our groq queries.
My big issue with this is groq is not small. Typing docs was relatively straightforward and not fragile, creating a typed query builder for everything groq can do is not going to easy or straightforward, will grow scope massively, and be prone to bugs.