graphql-engine/server
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
..
bench-wrk server: generalize integration tests 2021-03-11 18:18:41 +00:00
packaging build: use the debian buster version in the docker image 2021-05-27 07:50:15 +00:00
src-bench-cache server: make more use of hlint (#6059) 2020-10-28 16:40:33 +00:00
src-exec server: reorganise version embedding for fewer [TH] rebuilds 2021-06-29 16:40:47 +00:00
src-lib [gardening] Introduce PartialArbitrary 2021-07-05 22:04:38 +00:00
src-rsr Use exceptions to handle compatibility with pg 9.6 in 2.0 upgrade migration 2021-06-24 02:20:11 +00:00
src-test server: reorganise version embedding for fewer [TH] rebuilds 2021-06-29 16:40:47 +00:00
tests-py server: add query field to http-log and websocket-log 2021-07-02 13:05:57 +00:00
.dockerignore update packages (#251) 2018-08-08 13:10:13 +05:30
.gitignore server/citus: feature branch 2021-05-21 02:47:51 +00:00
.hlint.yaml ci: improve hlint messages 2021-05-04 21:52:55 +00:00
.stylish-haskell.yaml ci: run stylish haskell on all incoming PRs 2021-01-21 23:37:26 +00:00
cabal.project server: Updates 'pg-client-hs', fixes explicit conversions 2021-06-18 17:00:24 +00:00
cabal.project.ci update resource limits on circleci [force ci] 2021-01-29 14:36:07 +00:00
cabal.project.dev server: Bump GHC version to 8.10.2 (#5659) 2020-08-26 23:16:23 -05:00
cabal.project.dev-sh dev.sh: restore code coverage functionality 2020-01-23 18:35:18 -05:00
cabal.project.dev-sh.freeze dev.sh: restore code coverage functionality 2020-01-23 18:35:18 -05:00
cabal.project.dev-sh.local ci: improve compilation times by building a dynamic executable 2021-03-22 21:43:43 +00:00
cabal.project.freeze server: graceful shutdown for event and cron triggers and async action (II) 2021-05-14 09:39:33 +00:00
commit_diff.txt Rewrite GraphQL schema generation and query parsing (close #2801) (#4111) 2020-08-21 12:27:01 -05:00
CONTRIBUTING.md update contributing.md with server dependencies 2021-05-25 14:00:33 +00:00
graphql-engine.cabal [gardening] Introduce PartialArbitrary 2021-07-05 22:04:38 +00:00
Makefile server: add MSSQL support 2021-02-23 17:38:36 +00:00
sample.hie.yaml Merge oss/master onto mono/main 2020-11-12 22:37:19 +05:30
Setup.hs move raven into graphql-engine repo 2018-06-28 00:32:00 +05:30
STYLE.md server: Add a Haskell style guide (#2175) 2020-04-08 02:31:30 -05:00