graphql-engine/server/src-lib/Hasura/RQL/DDL
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
..
Metadata [gardening] Introduce PartialArbitrary 2021-07-05 22:04:38 +00:00
Permission server: cleanup backend types in permissions 2021-06-09 19:43:27 +00:00
Relationship server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
RemoteRelationship server: support remote relationships on SQL Server and BigQuery (#1497) 2021-06-11 03:27:39 +00:00
RemoteSchema server: rewrite remote input parsers to deal with partial variable expansion (fix hasura/graphql-engine#6656) 2021-05-24 20:13:47 +00:00
Schema Generalize set_table_customization to other backends (close #1501) 2021-06-17 13:22:54 +00:00
Action.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
ApiLimit.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
ComputedField.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
CustomTypes.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
Deps.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
Endpoint.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
EventTrigger.hs Fix/custom table name 2021-05-18 13:37:27 +00:00
GraphqlSchemaIntrospection.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
Headers.hs server: misc cleanups 2021-06-15 15:06:37 +00:00
InheritedRoles.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
Metadata.hs Fix for 6913 - Undefined ENV variable during a replace metadata throws on allow_inconsistent_metadata 2021-05-28 04:32:33 +00:00
Permission.hs server: cleanup backend types in permissions 2021-06-09 19:43:27 +00:00
QueryCollection.hs server: introduce Hasura.Base (take 2) 2021-05-11 15:19:33 +00:00
Relationship.hs Server: Use a bespoke type for nullability instead of Bool 2021-05-28 10:40:15 +00:00
RemoteRelationship.hs server: support remote relationships on SQL Server and BigQuery (#1497) 2021-06-11 03:27:39 +00:00
RemoteSchema.hs server, console, docs: add update_remote_schema API 2021-06-21 17:42:40 +00:00
ScheduledTrigger.hs 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
Schema.hs server: misc cleanups 2021-06-15 15:06:37 +00:00