graphql-engine/server/src-lib/Hasura
Antoine Leblanc 6ed800abaa [gardening] Introduce PartialArbitrary
### 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
2021-07-05 22:04:38 +00:00
..
Backends Bigquery/drop dataloader 2021-06-28 13:30:40 +00:00
Base server: include more detail in inconsistent metadata error messages (fix #6684) 2021-05-19 05:02:53 +00:00
Cache server: cleanup of language extensions [gardening] 2021-04-16 06:55:56 +00:00
Eventing server: Log action and event names (close #1603) 2021-07-05 07:48:39 +00:00
GraphQL server: log request type (batched/single) in http-log 2021-07-05 09:46:29 +00:00
Incremental server: IR for DB-DB joins 2021-06-17 23:13:05 +00:00
Metadata server: fix cron trigger bug of new events not getting generated when cron trigger is imported via metadata 2021-05-26 16:20:19 +00:00
RQL [gardening] Introduce PartialArbitrary 2021-07-05 22:04:38 +00:00
Server [gardening] remove ToJSON constraint in spockAction (fix #1581) 2021-07-05 18:47:55 +00:00
SQL [gardening] Introduce PartialArbitrary 2021-07-05 22:04:38 +00:00
App.hs server: log request type (batched/single) in http-log 2021-07-05 09:46:29 +00:00
EncJSON.hs server: heterogeneous execution of GraphQL queries (#5869) 2020-10-07 10:23:17 +00:00
GC.hs server: simplify shutdown logic, improve resource management (#218) (#195) 2020-12-21 18:56:57 +00:00
HTTP.hs improve debug information in actions errors response (close #4031) (#4432) 2020-04-24 13:25:51 +05:30
Incremental.hs Build the GraphQL context after pruning dangling dependents 2020-01-30 18:17:29 -06:00
Logging.hs server: generalized LogQueryLog (fix #708) 2021-03-13 14:41:44 +00:00
Prelude.hs server: IR for DB-DB joins 2021-06-17 23:13:05 +00:00
Session.hs Revert "remote schema typename customisation" 2021-06-10 09:57:16 +00:00
Tracing.hs Revert "remote schema typename customisation" 2021-06-10 09:57:16 +00:00