mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 01:44:03 +03:00
6ed800abaa
### Context One of the ways we use the Backend type families is to use `Void` for all types for which a backend has no representation; this allows us to make some branches of our metadata and IR unrepresentable, making some functions total, where they would have to handle those unsupported cases otherwise. However, one of the biggest features, functions, cannot be cut that way, due to one of the constraints on `FunctionName b`: the metadata generator requires it to have an `Arbitrary` instance, and `Arbitrary` does not have a recovery mechanism which would allow for a `Void` instance... ### Description This PR solves this problem and removes the `Arbitrary` constraints in `Backend`. To do so, it introduces a new typeclass: `PartialArbitrary`, which is very similar to `Arbitrary`, except that it returns a `Maybe (Gen a)`, allowing for `Void` to have a well-formed instance. An `Arbitrary` instance for `Metadata` can easily be retrieved with `arbitrary = fromJust . partialArbitrary`. Furthermore, `PartialArbitrary` has a generic implementation, inspired by the one in `generic-arbitrary`, which automatically prunes branches that return `Nothing`, allowing to automatically construct most types. Types that don't have a type parameter and therefore can't contain `Void` can easily get their `PartialArbitrary` instance from `Arbitrary` with `partialArbitrary = Just arbitrary`. This is what a default overlappable instance provides. In conjunction with other cleanups in #1666, **this allows for Void function names**. ### Notes While this solves the stated problem, there are other possible solutions we could explore, such as: - switching from QuickCheck to a library that supports that kind of pruning natively - removing the test altogether, and dropping all notion of Arbitrary from the code There are also several things we could do with the Generator module: - move it out of RQL.DDL.Metadata, to some place that makes more sense - move ALL Arbitrary instances in the code to it, since nothing else uses Arbitrary - or, to the contrary, move all those Arbitrary instances alongside their types, to avoid an orphan instance https://github.com/hasura/graphql-engine-mono/pull/1667 GitOrigin-RevId: 88e304ea453840efb5c0d39294639b8b30eefb81 |
||
---|---|---|
.. | ||
Partial.hs |