graphql-engine/server/src-lib/Hasura/GraphQL/Schema/Postgres.hs
Antoine Leblanc e3c2bf53a5 Move, document, and prune action types and custom types types.
### Description

This PR is a first step in a series of cleanups of action relationships. This first step does not contain any behavioral change, and it simply reorganizes / prunes / rearranges / documents the code. Mainly:
- it divides some files in RQL.Types between metadata types, schema cache types, execution types;
- it renames some types for consistency;
- it minimizes exports and prunes unnecessary types;
- it moves some types in places where they make more sense;
- it replaces uses of `DMap BackendTag` with `BackendMap`.

Most of the "movement" within files re-organizes declarations in a "top-down" fashion, by moving all TH splices to the end of the file, which avoids order or declarations mattering.

### Optional list types

One main type change this PR makes is a replacement of variant list types in `CustomTypes.hs`; we had `Maybe [a]`, or sometimes `Maybe (NonEmpty a)`. This PR harmonizes all of them to `[a]`, as most of the code would use them as such, by doing `fromMaybe []` or `maybe [] toList`.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4613
GitOrigin-RevId: bc624e10df587eba862ff27a5e8021b32d0d78a2
2022-06-07 15:45:00 +00:00

57 lines
2.2 KiB
Haskell

-- | Postgres-specific schema combinators. Those should be moved to
-- the corresponding instance of `BackendSchema`, when actions are
-- generalized.
module Hasura.GraphQL.Schema.Postgres
( buildActionQueryFields,
buildActionSubscriptionFields,
buildActionMutationFields,
)
where
import Hasura.GraphQL.Parser hiding (EnumValueInfo, field)
import Hasura.GraphQL.Schema.Action
import Hasura.GraphQL.Schema.Backend (MonadBuildSchema)
import Hasura.Prelude
import Hasura.RQL.IR
import Hasura.RQL.Types.Action
import Hasura.RQL.Types.CustomTypes
import Hasura.SQL.Backend
buildActionQueryFields ::
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
AnnotatedCustomTypes ->
ActionInfo ->
m [FieldParser n (QueryRootField UnpreparedValue)]
buildActionQueryFields customTypes actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery ->
fmap (fmap (RFAction . AQQuery)) <$> actionExecute customTypes actionInfo
ActionMutation ActionSynchronous -> pure Nothing
ActionMutation ActionAsynchronous ->
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery (_actObjectTypes customTypes) actionInfo
buildActionMutationFields ::
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
AnnotatedCustomTypes ->
ActionInfo ->
m [FieldParser n (MutationRootField UnpreparedValue)]
buildActionMutationFields customTypes actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery -> pure Nothing
ActionMutation ActionSynchronous ->
fmap (fmap (RFAction . AMSync)) <$> actionExecute customTypes actionInfo
ActionMutation ActionAsynchronous ->
fmap (fmap (RFAction . AMAsync)) <$> actionAsyncMutation (_actInputTypes customTypes) actionInfo
buildActionSubscriptionFields ::
MonadBuildSchema ('Postgres 'Vanilla) r m n =>
AnnotatedCustomTypes ->
ActionInfo ->
m [FieldParser n (QueryRootField UnpreparedValue)]
buildActionSubscriptionFields customTypes actionInfo =
maybeToList <$> case _adType (_aiDefinition actionInfo) of
ActionQuery -> pure Nothing
ActionMutation ActionSynchronous -> pure Nothing
ActionMutation ActionAsynchronous ->
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery (_actObjectTypes customTypes) actionInfo