2021-02-23 20:37:27 +03:00
|
|
|
-- | Postgres-specific schema combinators. Those should be moved to
|
|
|
|
-- the corresponding instance of `BackendSchema`, when actions are
|
|
|
|
-- generalized.
|
2020-12-01 18:50:18 +03:00
|
|
|
module Hasura.GraphQL.Schema.Postgres
|
2021-02-23 20:37:27 +03:00
|
|
|
( buildActionQueryFields,
|
2021-02-14 09:07:52 +03:00
|
|
|
buildActionSubscriptionFields,
|
|
|
|
buildActionMutationFields,
|
2020-12-01 18:50:18 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2021-02-03 19:17:20 +03:00
|
|
|
import Hasura.GraphQL.Schema.Action
|
2022-09-06 19:48:04 +03:00
|
|
|
import Hasura.GraphQL.Schema.Common
|
2022-09-06 17:18:30 +03:00
|
|
|
import Hasura.GraphQL.Schema.Parser
|
2020-12-01 18:50:18 +03:00
|
|
|
import Hasura.Prelude
|
2021-06-11 06:26:50 +03:00
|
|
|
import Hasura.RQL.IR
|
2022-04-27 16:57:28 +03:00
|
|
|
import Hasura.RQL.Types.Action
|
|
|
|
import Hasura.RQL.Types.CustomTypes
|
2022-09-06 17:18:30 +03:00
|
|
|
import Hasura.RQL.Types.Metadata.Object
|
2020-12-01 18:50:18 +03:00
|
|
|
|
2021-02-03 19:17:20 +03:00
|
|
|
buildActionQueryFields ::
|
server: reduce schema contexts to the bare minimum
### Description
This monster of a PR took way too long. As the title suggests, it reduces the schema context carried in the readers to the very strict minimum. In practice, that means that to build a source, we only require:
- the global `SchemaContext`
- the global `SchemaOptions` (soon to be renamed `SchemaSourceOptions`)
- that source's `SourceInfo`
Furthermore, _we no longer carry "default" customization options throughout the schema_. All customization information is extracted from the `SourceInfo`, when required. This prevents an entire category of bugs we had previously encountered, such as parts of the code using uninitialized / unupdated customization info.
In turn, this meant that we could remove the explicit threading of the `SourceInfo` throughout the schema, since it is now always available through the reader context.
Finally, this meant making a few adjustments to relay and actions as well, such as the introduction of a new separate "context" for actions, and a change to how we create some of the action-specific postgres scalar parsers.
I'll highlight with review comments the areas of interest.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6709
GitOrigin-RevId: ea80fddcb24e2513779dd04b0b700a55f0028dd1
2022-11-17 13:34:05 +03:00
|
|
|
MonadBuildActionSchema r m n =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-02-14 09:07:52 +03:00
|
|
|
ActionInfo ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryRootField UnpreparedValue)]
|
2021-12-16 02:51:52 +03:00
|
|
|
buildActionQueryFields customTypes actionInfo =
|
2022-09-06 17:18:30 +03:00
|
|
|
maybeToList . applyActionOrigin actionInfo
|
|
|
|
<$> 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
|
2021-02-03 19:17:20 +03:00
|
|
|
|
|
|
|
buildActionMutationFields ::
|
server: reduce schema contexts to the bare minimum
### Description
This monster of a PR took way too long. As the title suggests, it reduces the schema context carried in the readers to the very strict minimum. In practice, that means that to build a source, we only require:
- the global `SchemaContext`
- the global `SchemaOptions` (soon to be renamed `SchemaSourceOptions`)
- that source's `SourceInfo`
Furthermore, _we no longer carry "default" customization options throughout the schema_. All customization information is extracted from the `SourceInfo`, when required. This prevents an entire category of bugs we had previously encountered, such as parts of the code using uninitialized / unupdated customization info.
In turn, this meant that we could remove the explicit threading of the `SourceInfo` throughout the schema, since it is now always available through the reader context.
Finally, this meant making a few adjustments to relay and actions as well, such as the introduction of a new separate "context" for actions, and a change to how we create some of the action-specific postgres scalar parsers.
I'll highlight with review comments the areas of interest.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6709
GitOrigin-RevId: ea80fddcb24e2513779dd04b0b700a55f0028dd1
2022-11-17 13:34:05 +03:00
|
|
|
MonadBuildActionSchema r m n =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-02-14 09:07:52 +03:00
|
|
|
ActionInfo ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (MutationRootField UnpreparedValue)]
|
2021-12-16 02:51:52 +03:00
|
|
|
buildActionMutationFields customTypes actionInfo =
|
2022-09-06 17:18:30 +03:00
|
|
|
maybeToList . applyActionOrigin actionInfo
|
|
|
|
<$> 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
|
2021-02-03 19:17:20 +03:00
|
|
|
|
|
|
|
buildActionSubscriptionFields ::
|
server: reduce schema contexts to the bare minimum
### Description
This monster of a PR took way too long. As the title suggests, it reduces the schema context carried in the readers to the very strict minimum. In practice, that means that to build a source, we only require:
- the global `SchemaContext`
- the global `SchemaOptions` (soon to be renamed `SchemaSourceOptions`)
- that source's `SourceInfo`
Furthermore, _we no longer carry "default" customization options throughout the schema_. All customization information is extracted from the `SourceInfo`, when required. This prevents an entire category of bugs we had previously encountered, such as parts of the code using uninitialized / unupdated customization info.
In turn, this meant that we could remove the explicit threading of the `SourceInfo` throughout the schema, since it is now always available through the reader context.
Finally, this meant making a few adjustments to relay and actions as well, such as the introduction of a new separate "context" for actions, and a change to how we create some of the action-specific postgres scalar parsers.
I'll highlight with review comments the areas of interest.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6709
GitOrigin-RevId: ea80fddcb24e2513779dd04b0b700a55f0028dd1
2022-11-17 13:34:05 +03:00
|
|
|
MonadBuildActionSchema r m n =>
|
2021-12-16 02:51:52 +03:00
|
|
|
AnnotatedCustomTypes ->
|
2021-02-14 09:07:52 +03:00
|
|
|
ActionInfo ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryRootField UnpreparedValue)]
|
2021-12-16 02:51:52 +03:00
|
|
|
buildActionSubscriptionFields customTypes actionInfo =
|
2022-09-06 17:18:30 +03:00
|
|
|
maybeToList . applyActionOrigin actionInfo
|
|
|
|
<$> case _adType (_aiDefinition actionInfo) of
|
|
|
|
ActionQuery -> pure Nothing
|
|
|
|
ActionMutation ActionSynchronous -> pure Nothing
|
|
|
|
ActionMutation ActionAsynchronous ->
|
|
|
|
fmap (fmap (RFAction . AQAsync)) <$> actionAsyncQuery (_actObjectTypes customTypes) actionInfo
|
|
|
|
|
|
|
|
applyActionOrigin ::
|
|
|
|
ActionInfo ->
|
|
|
|
Maybe (FieldParser n a) ->
|
|
|
|
Maybe (FieldParser n a)
|
|
|
|
applyActionOrigin actionInfo = fmap (setFieldParserOrigin (MOAction (_aiName actionInfo)))
|