graphql-engine/server/src-lib/Hasura/GraphQL/Schema
Auke Booij 29158900d8 Refactor type name customization
Source typename customization (hasura/graphql-engine@aac64f2c81) introduced a mechanism to change certain names in the GraphQL schema that is exposed. In particular it allows last-minute modification of:
1. the names of some types, and
2. the names of some root fields.

The above two items are assigned distinct customization algorithms, and at times both algorithms are in scope. So a need to distinguish them is needed.

In the original design, this was addressed by introducing a newtype wrapper `Typename` around GraphQL `Name`s, dedicated to the names of types. However, in the majority of the codebase, type names are also represented by `Name`. For this reason, it was unavoidable to allow for easy conversion. This was supported by a `HasName Typename` instance, as well as by publishing the constructors of `Typename`.

This means that the type safety that newtypes can add is lost. In particular, it is now very easy to confuse type name customization with root field name customization.

This refactors the above design by instead introducing newtypes around the customization operations:
```haskell
newtype MkTypename = MkTypename {runMkTypename :: Name -> Name}
  deriving (Semigroup, Monoid) via (Endo Name)

newtype MkRootFieldName = MkRootFieldName {runMkRootFieldName :: Name -> Name}
  deriving (Semigroup, Monoid) via (Endo Name)
```
The `Monoid` instance allows easy composition of customization operations, piggybacking off of the type of `Endo`maps.

This design allows safe co-existence of the two customization algorithms, while avoiding the syntactic overhead of packing and unpacking newtypes.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2989
GitOrigin-RevId: da3a353a9b003ee40c8d0a1e02872e99d2edd3ca
2021-11-30 09:52:53 +00:00
..
Action.hs Refactor type name customization 2021-11-30 09:52:53 +00:00
Backend.hs Refactor remote schema customization 2021-11-30 00:38:27 +00:00
BoolExp.hs Breaking up the Postgres implementation of the update-schema into reusable components 2021-11-18 18:03:57 +00:00
Build.hs Defining the MSSQL update schema using said components 2021-11-26 13:48:09 +00:00
Common.hs server: add explicit export lists in OSS server and enforce with warning 2021-11-04 16:09:38 +00:00
Instances.hs server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
Introspect.hs Refactor type name customization 2021-11-30 09:52:53 +00:00
Mutation.hs Defining the MSSQL update schema using said components 2021-11-26 13:48:09 +00:00
OrderBy.hs Refactor type name customization 2021-11-30 09:52:53 +00:00
Postgres.hs server, pro: actually reformat the code-base using ormolu 2021-09-23 22:57:37 +00:00
Remote.hs Refactor type name customization 2021-11-30 09:52:53 +00:00
RemoteSource.hs Source typename customization (close graphql-engine#6974) 2021-10-29 14:43:14 +00:00
RemoteSource.hs-boot server: add explicit export lists in OSS server and enforce with warning 2021-11-04 16:09:38 +00:00
Select.hs Refactor type name customization 2021-11-30 09:52:53 +00:00
Table.hs Breaking up the Postgres implementation of the update-schema into reusable components 2021-11-18 18:03:57 +00:00
Update.hs Defining the MSSQL update schema using said components 2021-11-26 13:48:09 +00:00