graphql-engine/server/src-lib/Hasura
Auke Booij 8888e06bbb Spell out the TH in Hasura.SQL.{Tag,AnyBackend}
The module `Hasura.SQL.AnyBackend` was introduced (in #751) to centralize the logic for case-switching behavior that depends on the particular flavor of relational DB backend (Postgres vs MSSQL vs BigQuery vs MySQL vs DataConnectors). This allows us to write a bunch of code in a backend-agnostic way, even if runtime behavior does depend on the chosen backend. At the same time, it allows us to write backend-specific code without having to care (too much) about the existence of other backends.

In #851 this module was rewritten to use Template Haskell.

I've heard that one of the reasons for the use of TH was that this would make it easier to keep backends out of the compilation product entirely. This would allow customers, especially on OSS, to benefit from simpler software licensing.

However:
1. This conditional compilation never materialized.
2. It's not clear whether writing this particular module based on TH would be sufficient for conditional compilation. And in any case, it can be done using CPP pragmas as well.
3. The TH code is extraordinarily complex. Since its introduction, it has been documented extraordinarily well, but it's still very difficult to maintain and/or refactor, due to its non-idiomatic nature.
4. Hasura's company objectives are now Cloud-oriented, so that software licensing issues work differently, and in particular, do not depend on what's part of the compilation product.

So this PR reverts on #851 by spelling out the code generated by TH. This is a net-negative diff size. IOW we used to generate less code than the size of the code doing the generating. This makes the code readable and maintainable.

The generated code has been modified in one way, which I'll now describe.

In the scenario that support for a new backend is introduced, a constructor is added to the `BackendType` type. This would then cause `liftTag` to be partial, thus raising a compiler warning. Resolving this requires adding corresponding constructors to the `BackendTag` and `AnyBackend` types. This would then require amending **almost** all other methods.

The exceptions are `composeAnyBackend` and `unpackAnyBackend`. These methods test whether two values are compatible, i.e. belong to the same backend. Both have a default case that in one way or another ignores the input values. Using TH here ensures that all values that belong together are caught. But after spelling out the TH, the presence of the default case means that no compiler warning is thrown for a missing match of matching values. So in the default case, we now do an explicit check for equality. If there _is_ an equality, that means that there is a missing `case`. So this is reported as an `error` (which is very crude, but it should be).

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5333
GitOrigin-RevId: 5aaf0a93394bd740aa7371526d3175c8142b3541
2022-08-11 09:11:07 +00:00
..
Backends server: accept extensions_schema while adding a source 2022-08-10 09:42:09 +00:00
Base server: Move ErrorMessage to its own package. 2022-07-27 04:38:12 +00:00
Cache server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
Eventing Move soEventsHttpPoolSize and soEventsFetchInterval defaulting into arg parser 2022-08-10 19:18:11 +00:00
GraphQL Run the reader context per schema block 2022-08-08 13:05:51 +00:00
Incremental server: Move the schema parsers to their own library. 2022-08-05 13:53:39 +00:00
Metadata server: convert Metadata to DTO (smaller PR) 2022-08-01 12:50:00 +00:00
RQL move strictness where it is needed 2022-08-11 07:53:44 +00:00
Server Move soEventsHttpPoolSize and soEventsFetchInterval defaulting into arg parser 2022-08-10 19:18:11 +00:00
SQL Spell out the TH in Hasura.SQL.{Tag,AnyBackend} 2022-08-11 09:11:07 +00:00
App.hs Move soEventsHttpPoolSize and soEventsFetchInterval defaulting into arg parser 2022-08-10 19:18:11 +00:00
EncJSON.hs Fix JSON encoding issue (fix hasura/graphql-engine#7543 and hasura/graphql-engine#8200) 2022-04-05 19:11:30 +00:00
GC.hs server: add explicit export lists in OSS server and enforce with warning 2021-11-04 16:09:38 +00:00
HTTP.hs Add Data Connector agent request logging, improve error messages, and add tracing support [GDW-83] 2022-07-11 08:05:40 +00:00
Incremental.hs server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
Logging.hs Add Data Connector agent request logging, improve error messages, and add tracing support [GDW-83] 2022-07-11 08:05:40 +00:00
Name.hs server: support for Apollo federation 2022-07-25 15:54:41 +00:00
Prelude.hs Use witherable, remove catMaybes/mapMaybe 2022-07-29 14:53:16 +00:00
QueryTags.hs server: support query tags for MSSQL data sources 2022-04-28 19:34:45 +00:00
Session.hs Weeding (2/?) 2022-06-09 16:40:49 +00:00
Tracing.hs Add Data Connector agent request logging, improve error messages, and add tracing support [GDW-83] 2022-07-11 08:05:40 +00:00