mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
42e5205eb5
### 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
66 lines
2.5 KiB
Haskell
66 lines
2.5 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.Schema.Action
|
|
import Hasura.GraphQL.Schema.Common
|
|
import Hasura.GraphQL.Schema.Parser
|
|
import Hasura.Prelude
|
|
import Hasura.RQL.IR
|
|
import Hasura.RQL.Types.Action
|
|
import Hasura.RQL.Types.CustomTypes
|
|
import Hasura.RQL.Types.Metadata.Object
|
|
|
|
buildActionQueryFields ::
|
|
MonadBuildActionSchema r m n =>
|
|
AnnotatedCustomTypes ->
|
|
ActionInfo ->
|
|
SchemaT r m [FieldParser n (QueryRootField UnpreparedValue)]
|
|
buildActionQueryFields customTypes actionInfo =
|
|
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
|
|
|
|
buildActionMutationFields ::
|
|
MonadBuildActionSchema r m n =>
|
|
AnnotatedCustomTypes ->
|
|
ActionInfo ->
|
|
SchemaT r m [FieldParser n (MutationRootField UnpreparedValue)]
|
|
buildActionMutationFields customTypes actionInfo =
|
|
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
|
|
|
|
buildActionSubscriptionFields ::
|
|
MonadBuildActionSchema r m n =>
|
|
AnnotatedCustomTypes ->
|
|
ActionInfo ->
|
|
SchemaT r m [FieldParser n (QueryRootField UnpreparedValue)]
|
|
buildActionSubscriptionFields customTypes actionInfo =
|
|
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)))
|