2022-06-29 19:03:25 +03:00
|
|
|
{-# LANGUAGE ApplicativeDo #-}
|
|
|
|
{-# LANGUAGE ViewPatterns #-}
|
|
|
|
|
|
|
|
module Hasura.Backends.Postgres.Schema.Select
|
|
|
|
( selectFunction,
|
|
|
|
selectFunctionAggregate,
|
|
|
|
selectFunctionConnection,
|
|
|
|
computedFieldPG,
|
|
|
|
buildFunctionQueryFieldsPG,
|
|
|
|
buildFunctionMutationFieldsPG,
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Control.Lens hiding (index)
|
2022-07-19 09:55:42 +03:00
|
|
|
import Data.Has (getter)
|
2022-06-29 19:03:25 +03:00
|
|
|
import Data.HashMap.Strict.Extended qualified as Map
|
|
|
|
import Data.Sequence qualified as Seq
|
2022-08-17 15:46:36 +03:00
|
|
|
import Data.Text.Casing qualified as C
|
2022-06-29 19:03:25 +03:00
|
|
|
import Data.Text.Extended
|
|
|
|
import Data.Traversable (mapAccumL)
|
2022-09-21 14:34:39 +03:00
|
|
|
import Hasura.Backends.Postgres.SQL.Types qualified as Postgres
|
|
|
|
import Hasura.Backends.Postgres.Types.ComputedField qualified as Postgres
|
|
|
|
import Hasura.Backends.Postgres.Types.Function qualified as Postgres
|
2022-06-29 19:03:25 +03:00
|
|
|
import Hasura.Base.Error
|
|
|
|
import Hasura.GraphQL.Schema.Backend
|
2022-08-22 18:57:46 +03:00
|
|
|
import Hasura.GraphQL.Schema.BoolExp
|
2022-06-29 19:03:25 +03:00
|
|
|
import Hasura.GraphQL.Schema.Common
|
2022-07-14 20:57:28 +03:00
|
|
|
import Hasura.GraphQL.Schema.Options qualified as Options
|
2022-06-29 19:03:25 +03:00
|
|
|
import Hasura.GraphQL.Schema.Parser
|
|
|
|
( FieldParser,
|
|
|
|
InputFieldsParser,
|
|
|
|
)
|
2022-07-27 15:24:50 +03:00
|
|
|
import Hasura.GraphQL.Schema.Parser qualified as P
|
2022-06-29 19:03:25 +03:00
|
|
|
import Hasura.GraphQL.Schema.Select
|
|
|
|
import Hasura.GraphQL.Schema.Table
|
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
|
|
|
import Hasura.GraphQL.Schema.Typename
|
2022-06-29 19:03:25 +03:00
|
|
|
import Hasura.Name qualified as Name
|
|
|
|
import Hasura.Prelude
|
|
|
|
import Hasura.RQL.IR
|
|
|
|
import Hasura.RQL.IR qualified as IR
|
|
|
|
import Hasura.RQL.Types.Backend
|
|
|
|
import Hasura.RQL.Types.Column
|
|
|
|
import Hasura.RQL.Types.Common
|
|
|
|
import Hasura.RQL.Types.ComputedField
|
|
|
|
import Hasura.RQL.Types.Function
|
|
|
|
import Hasura.RQL.Types.SchemaCache hiding (askTableInfo)
|
|
|
|
import Hasura.RQL.Types.Source
|
2022-08-17 15:46:36 +03:00
|
|
|
import Hasura.RQL.Types.SourceCustomization
|
2022-06-29 19:03:25 +03:00
|
|
|
import Hasura.RQL.Types.Table
|
|
|
|
import Hasura.SQL.Backend
|
|
|
|
import Language.GraphQL.Draft.Syntax qualified as G
|
|
|
|
|
|
|
|
-- | User-defined function (AKA custom function)
|
|
|
|
selectFunction ::
|
|
|
|
forall r m n pgKind.
|
2022-08-03 22:08:34 +03:00
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
MkRootFieldName ->
|
2022-06-29 19:03:25 +03:00
|
|
|
-- | SQL function info
|
|
|
|
FunctionInfo ('Postgres pgKind) ->
|
|
|
|
-- | field description, if any
|
|
|
|
Maybe G.Description ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (Maybe (FieldParser n (SelectExp ('Postgres pgKind))))
|
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
|
|
|
selectFunction mkRootFieldName fi@FunctionInfo {..} description = runMaybeT do
|
|
|
|
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
roleName <- retrieve scRole
|
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
|
|
|
let customization = _siCustomization sourceInfo
|
|
|
|
tCase = _rscNamingConvention customization
|
|
|
|
tableInfo <- lift $ askTableInfo _fiReturnType
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
selectPermissions <- hoistMaybe $ tableSelectPermissions roleName tableInfo
|
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
|
|
|
selectionSetParser <- MaybeT $ returnFunctionParser tableInfo
|
2022-06-29 19:03:25 +03:00
|
|
|
lift do
|
2022-07-14 20:57:28 +03:00
|
|
|
stringifyNumbers <- retrieve Options.soStringifyNumbers
|
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
|
|
|
tableArgsParser <- tableArguments tableInfo
|
|
|
|
functionArgsParser <- customSQLFunctionArgs fi _fiGQLName _fiGQLArgsName
|
2022-06-29 19:03:25 +03:00
|
|
|
let argsParser = liftA2 (,) functionArgsParser tableArgsParser
|
2022-08-03 22:08:34 +03:00
|
|
|
functionFieldName = runMkRootFieldName mkRootFieldName _fiGQLName
|
2022-06-29 19:03:25 +03:00
|
|
|
pure $
|
|
|
|
P.subselection functionFieldName description argsParser selectionSetParser
|
|
|
|
<&> \((funcArgs, tableArgs'), fields) ->
|
|
|
|
IR.AnnSelectG
|
|
|
|
{ IR._asnFields = fields,
|
|
|
|
IR._asnFrom = IR.FromFunction _fiSQLName funcArgs Nothing,
|
|
|
|
IR._asnPerm = tablePermissionsInfo selectPermissions,
|
|
|
|
IR._asnArgs = tableArgs',
|
2022-07-19 09:55:42 +03:00
|
|
|
IR._asnStrfyNum = stringifyNumbers,
|
|
|
|
IR._asnNamingConvention = Just tCase
|
2022-06-29 19:03:25 +03:00
|
|
|
}
|
|
|
|
where
|
|
|
|
returnFunctionParser =
|
|
|
|
case _fiJsonAggSelect of
|
|
|
|
JASSingleObject -> tableSelectionSet
|
|
|
|
JASMultipleRows -> tableSelectionList
|
|
|
|
|
|
|
|
selectFunctionAggregate ::
|
|
|
|
forall r m n pgKind.
|
2022-08-03 22:08:34 +03:00
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
MkRootFieldName ->
|
2022-06-29 19:03:25 +03:00
|
|
|
-- | SQL function info
|
|
|
|
FunctionInfo ('Postgres pgKind) ->
|
|
|
|
-- | field description, if any
|
|
|
|
Maybe G.Description ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (Maybe (FieldParser n (AggSelectExp ('Postgres pgKind))))
|
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
|
|
|
selectFunctionAggregate mkRootFieldName fi@FunctionInfo {..} description = runMaybeT do
|
|
|
|
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
roleName <- retrieve scRole
|
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
|
|
|
let customization = _siCustomization sourceInfo
|
|
|
|
tCase = _rscNamingConvention customization
|
|
|
|
mkTypename = runMkTypename $ _rscTypeNames customization
|
|
|
|
targetTableInfo <- askTableInfo _fiReturnType
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
selectPermissions <- hoistMaybe $ tableSelectPermissions roleName targetTableInfo
|
2022-06-29 19:03:25 +03:00
|
|
|
guard $ spiAllowAgg selectPermissions
|
|
|
|
xNodesAgg <- hoistMaybe $ nodesAggExtension @('Postgres pgKind)
|
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
|
|
|
tableInfo <- askTableInfo _fiReturnType
|
|
|
|
nodesParser <- MaybeT $ tableSelectionList tableInfo
|
2022-06-29 19:03:25 +03:00
|
|
|
lift do
|
2022-07-14 20:57:28 +03:00
|
|
|
stringifyNumbers <- retrieve Options.soStringifyNumbers
|
2022-08-17 15:46:36 +03:00
|
|
|
tableGQLName <- getTableIdentifierName tableInfo
|
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
|
|
|
tableArgsParser <- tableArguments tableInfo
|
|
|
|
functionArgsParser <- customSQLFunctionArgs fi _fiGQLAggregateName _fiGQLArgsName
|
|
|
|
aggregateParser <- tableAggregationFields tableInfo
|
2022-08-03 22:08:34 +03:00
|
|
|
let aggregateFieldName = runMkRootFieldName mkRootFieldName _fiGQLAggregateName
|
|
|
|
argsParser = liftA2 (,) functionArgsParser tableArgsParser
|
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
|
|
|
selectionName = mkTypename (applyTypeNameCaseIdentifier tCase $ mkTableAggregateTypeName tableGQLName)
|
2022-06-29 19:03:25 +03:00
|
|
|
aggregationParser =
|
|
|
|
fmap (parsedSelectionsToFields IR.TAFExp) $
|
|
|
|
P.nonNullableParser $
|
|
|
|
P.selectionSet
|
|
|
|
selectionName
|
|
|
|
Nothing
|
|
|
|
[ IR.TAFNodes xNodesAgg <$> P.subselection_ Name._nodes Nothing nodesParser,
|
|
|
|
IR.TAFAgg <$> P.subselection_ Name._aggregate Nothing aggregateParser
|
|
|
|
]
|
|
|
|
pure $
|
|
|
|
P.subselection aggregateFieldName description argsParser aggregationParser
|
|
|
|
<&> \((funcArgs, tableArgs'), fields) ->
|
|
|
|
IR.AnnSelectG
|
|
|
|
{ IR._asnFields = fields,
|
|
|
|
IR._asnFrom = IR.FromFunction _fiSQLName funcArgs Nothing,
|
|
|
|
IR._asnPerm = tablePermissionsInfo selectPermissions,
|
|
|
|
IR._asnArgs = tableArgs',
|
2022-07-19 09:55:42 +03:00
|
|
|
IR._asnStrfyNum = stringifyNumbers,
|
|
|
|
IR._asnNamingConvention = Just tCase
|
2022-06-29 19:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
selectFunctionConnection ::
|
|
|
|
forall pgKind r m n.
|
2022-06-30 18:22:19 +03:00
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
2022-08-22 18:57:46 +03:00
|
|
|
AggregationPredicatesSchema ('Postgres pgKind),
|
2022-06-30 18:22:19 +03:00
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
2022-08-03 22:08:34 +03:00
|
|
|
MkRootFieldName ->
|
2022-06-29 19:03:25 +03:00
|
|
|
-- | SQL function info
|
|
|
|
FunctionInfo ('Postgres pgKind) ->
|
|
|
|
-- | field description, if any
|
|
|
|
Maybe G.Description ->
|
|
|
|
-- | primary key columns of the target table
|
|
|
|
PrimaryKeyColumns ('Postgres pgKind) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (Maybe (FieldParser n (ConnectionSelectExp ('Postgres pgKind))))
|
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
|
|
|
selectFunctionConnection mkRootFieldName fi@FunctionInfo {..} description pkeyColumns = runMaybeT do
|
|
|
|
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
roleName <- retrieve scRole
|
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
|
|
|
let customization = _siCustomization sourceInfo
|
|
|
|
tCase = _rscNamingConvention customization
|
|
|
|
returnTableInfo <- lift $ askTableInfo _fiReturnType
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
selectPermissions <- hoistMaybe $ tableSelectPermissions roleName returnTableInfo
|
2022-06-29 19:03:25 +03:00
|
|
|
xRelayInfo <- hoistMaybe $ relayExtension @('Postgres pgKind)
|
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
|
|
|
tableInfo <- lift $ askTableInfo _fiReturnType
|
|
|
|
selectionSetParser <- MaybeT $ tableConnectionSelectionSet tableInfo
|
2022-06-29 19:03:25 +03:00
|
|
|
lift do
|
2022-08-03 22:08:34 +03:00
|
|
|
let fieldName = runMkRootFieldName mkRootFieldName $ _fiGQLName <> Name.__connection
|
2022-07-14 20:57:28 +03:00
|
|
|
stringifyNumbers <- retrieve Options.soStringifyNumbers
|
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
|
|
|
tableConnectionArgsParser <- tableConnectionArgs pkeyColumns tableInfo
|
|
|
|
functionArgsParser <- customSQLFunctionArgs fi _fiGQLName _fiGQLArgsName
|
2022-06-29 19:03:25 +03:00
|
|
|
let argsParser = liftA2 (,) functionArgsParser tableConnectionArgsParser
|
|
|
|
pure $
|
|
|
|
P.subselection fieldName description argsParser selectionSetParser
|
|
|
|
<&> \((funcArgs, (args, split, slice)), fields) ->
|
|
|
|
IR.ConnectionSelect
|
|
|
|
{ IR._csXRelay = xRelayInfo,
|
|
|
|
IR._csPrimaryKeyColumns = pkeyColumns,
|
|
|
|
IR._csSplit = split,
|
|
|
|
IR._csSlice = slice,
|
|
|
|
IR._csSelect =
|
|
|
|
IR.AnnSelectG
|
|
|
|
{ IR._asnFields = fields,
|
|
|
|
IR._asnFrom = IR.FromFunction _fiSQLName funcArgs Nothing,
|
|
|
|
IR._asnPerm = tablePermissionsInfo selectPermissions,
|
|
|
|
IR._asnArgs = args,
|
2022-07-19 09:55:42 +03:00
|
|
|
IR._asnStrfyNum = stringifyNumbers,
|
|
|
|
IR._asnNamingConvention = Just tCase
|
2022-06-29 19:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-- | Computed field parser
|
|
|
|
computedFieldPG ::
|
|
|
|
forall pgKind r m n.
|
2022-08-22 18:57:46 +03:00
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
2022-06-29 19:03:25 +03:00
|
|
|
ComputedFieldInfo ('Postgres pgKind) ->
|
|
|
|
TableName ('Postgres pgKind) ->
|
|
|
|
TableInfo ('Postgres pgKind) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (Maybe (FieldParser n (AnnotatedField ('Postgres pgKind))))
|
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
|
|
|
computedFieldPG ComputedFieldInfo {..} parentTable tableInfo = runMaybeT do
|
|
|
|
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
roleName <- retrieve scRole
|
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
|
|
|
let sourceName = _siName sourceInfo
|
|
|
|
customization = _siCustomization sourceInfo
|
|
|
|
tCase = _rscNamingConvention customization
|
2022-07-14 20:57:28 +03:00
|
|
|
stringifyNumbers <- retrieve Options.soStringifyNumbers
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
selectPermissions <- hoistMaybe $ tableSelectPermissions roleName tableInfo
|
2022-06-29 19:03:25 +03:00
|
|
|
fieldName <- lift $ textToName $ computedFieldNameToText _cfiName
|
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
|
|
|
functionArgsParser <- lift $ computedFieldFunctionArgs sourceName _cfiFunction
|
2022-06-29 19:03:25 +03:00
|
|
|
case _cfiReturnType of
|
2022-09-21 14:34:39 +03:00
|
|
|
Postgres.CFRScalar scalarReturnType -> do
|
2022-06-29 19:03:25 +03:00
|
|
|
caseBoolExpMaybe <-
|
|
|
|
hoistMaybe (Map.lookup _cfiName (spiComputedFields selectPermissions))
|
|
|
|
let caseBoolExpUnpreparedValue =
|
|
|
|
(fmap . fmap) partialSQLExpToUnpreparedValue <$> caseBoolExpMaybe
|
|
|
|
fieldArgsParser = do
|
|
|
|
args <- functionArgsParser
|
|
|
|
colOp <- scalarSelectionArgumentsParser @('Postgres pgKind) $ ColumnScalar scalarReturnType
|
|
|
|
pure $
|
|
|
|
IR.AFComputedField
|
|
|
|
_cfiXComputedFieldInfo
|
|
|
|
_cfiName
|
|
|
|
( IR.CFSScalar
|
|
|
|
( IR.ComputedFieldScalarSelect
|
|
|
|
{ IR._cfssFunction = _cffName _cfiFunction,
|
|
|
|
IR._cfssType = scalarReturnType,
|
|
|
|
IR._cfssScalarArguments = colOp,
|
|
|
|
IR._cfssArguments = args
|
|
|
|
}
|
|
|
|
)
|
|
|
|
caseBoolExpUnpreparedValue
|
|
|
|
)
|
|
|
|
dummyParser <- lift $ columnParser @('Postgres pgKind) (ColumnScalar scalarReturnType) (G.Nullability True)
|
|
|
|
pure $ P.selection fieldName fieldDescription fieldArgsParser dummyParser
|
2022-09-21 14:34:39 +03:00
|
|
|
Postgres.CFRSetofTable tableName -> do
|
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
|
|
|
otherTableInfo <- lift $ askTableInfo tableName
|
Move RoleName into SchemaContext.
### Description
I am not 100% sure about this PR; while I think the code is better this way, I'm willing to be convinced otherwise.
In short, this PR moves the `RoleName` field into the `SchemaContext`, instead of being a nebulous `Has RoleName` constraint on the reader monad. The major upside of this is that it makes it an explicit named field, rather than something that must be given as part of a tuple of arguments when calling `runReader`.
However, the downside is that it breaks the helper permissions functions of `Schema.Table`, which relied on `Has RoleName r`. This PR makes the choice of passing the role name explicitly to all of those functions, which in turn means first explicitly fetching the role name in a lot of places. It makes it more explicit when a schema building block relies on the role name, but is a bit verbose...
### Alternatives
Some alternatives worth considering:
- attempting something like `Has context r, Has RoleName context`, which would allow them to be independent from the context but still fetch the role name from the reader, but might require type annotations to not be ambiguous
- keeping the permission functions the same, with `Has RoleName r`, and introducing a bunch of newtypes instead of using tuples to explicitly implement all the required `Has` instances
- changing the permission functions to `Has SchemaContext r`, since they are functions used only to build the schema, and therefore may be allowed to be tied to the context.
What do y'all think?
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5073
GitOrigin-RevId: 8fd09fafb54905a4d115ef30842d35da0c3db5d2
2022-07-29 18:37:09 +03:00
|
|
|
remotePerms <- hoistMaybe $ tableSelectPermissions roleName otherTableInfo
|
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
|
|
|
selectionSetParser <- MaybeT (fmap (P.multiple . P.nonNullableParser) <$> tableSelectionSet otherTableInfo)
|
|
|
|
selectArgsParser <- lift $ tableArguments otherTableInfo
|
2022-06-29 19:03:25 +03:00
|
|
|
let fieldArgsParser = liftA2 (,) functionArgsParser selectArgsParser
|
|
|
|
pure $
|
|
|
|
P.subselection fieldName fieldDescription fieldArgsParser selectionSetParser
|
|
|
|
<&> \((functionArgs', args), fields) ->
|
|
|
|
IR.AFComputedField _cfiXComputedFieldInfo _cfiName $
|
|
|
|
IR.CFSTable JASMultipleRows $
|
|
|
|
IR.AnnSelectG
|
|
|
|
{ IR._asnFields = fields,
|
|
|
|
IR._asnFrom = IR.FromFunction (_cffName _cfiFunction) functionArgs' Nothing,
|
|
|
|
IR._asnPerm = tablePermissionsInfo remotePerms,
|
|
|
|
IR._asnArgs = args,
|
2022-07-19 09:55:42 +03:00
|
|
|
IR._asnStrfyNum = stringifyNumbers,
|
|
|
|
IR._asnNamingConvention = Just tCase
|
2022-06-29 19:03:25 +03:00
|
|
|
}
|
|
|
|
where
|
|
|
|
fieldDescription :: Maybe G.Description
|
|
|
|
fieldDescription = G.Description <$> _cfiDescription
|
|
|
|
|
|
|
|
computedFieldFunctionArgs ::
|
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
|
|
|
SourceName ->
|
2022-06-29 19:03:25 +03:00
|
|
|
ComputedFieldFunction ('Postgres pgKind) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (InputFieldsParser n (FunctionArgsExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))
|
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
|
|
|
computedFieldFunctionArgs sourceName ComputedFieldFunction {..} = do
|
|
|
|
functionArgs (FTAComputedField _cfiName sourceName parentTable) (IAUserProvided <$> _cffInputArgs)
|
2022-06-29 19:03:25 +03:00
|
|
|
<&> fmap addTableAndSessionArgument
|
|
|
|
where
|
|
|
|
addTableAndSessionArgument args@(FunctionArgsExp positional named) =
|
2022-09-21 14:34:39 +03:00
|
|
|
let withTable = case Postgres._cffaTableArgument _cffComputedFieldImplicitArgs of
|
|
|
|
Postgres.FTAFirst -> FunctionArgsExp (Postgres.AETableRow : positional) named
|
|
|
|
Postgres.FTANamed argName index -> IR.insertFunctionArg argName index Postgres.AETableRow args
|
|
|
|
sessionArgVal = Postgres.AESession IR.UVSession
|
|
|
|
in case Postgres._cffaSessionArgument _cffComputedFieldImplicitArgs of
|
2022-06-29 19:03:25 +03:00
|
|
|
Nothing -> withTable
|
2022-09-21 14:34:39 +03:00
|
|
|
Just (Postgres.FunctionSessionArgument argName index) ->
|
2022-06-29 19:03:25 +03:00
|
|
|
IR.insertFunctionArg argName index sessionArgVal withTable
|
|
|
|
|
|
|
|
-- | The custom SQL functions' input "args" field parser
|
|
|
|
-- > function_name(args: function_args)
|
|
|
|
customSQLFunctionArgs ::
|
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
FunctionInfo ('Postgres pgKind) ->
|
|
|
|
G.Name ->
|
|
|
|
G.Name ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (InputFieldsParser n (FunctionArgsExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))
|
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
|
|
|
customSQLFunctionArgs FunctionInfo {..} functionName functionArgsName =
|
2022-06-29 19:03:25 +03:00
|
|
|
functionArgs
|
|
|
|
( FTACustomFunction $
|
|
|
|
CustomFunctionNames
|
|
|
|
{ cfnFunctionName = functionName,
|
|
|
|
cfnArgsName = functionArgsName
|
|
|
|
}
|
|
|
|
)
|
|
|
|
_fiInputArgs
|
|
|
|
|
|
|
|
-- | Parses the arguments to the underlying sql function of a computed field or
|
|
|
|
-- a custom function. All arguments to the underlying sql function are parsed
|
|
|
|
-- as an "args" object. Named arguments are expected in a field with the same
|
|
|
|
-- name, while positional arguments are expected in an field named "arg_$n".
|
|
|
|
-- Note that collisions are possible, but ignored for now, if a named argument
|
|
|
|
-- is also named "arg_$n". (FIXME: link to an issue?)
|
|
|
|
--
|
|
|
|
-- If the function requires no argument, or if its only argument is not
|
|
|
|
-- user-provided (the session argument in the case of custom functions, the
|
|
|
|
-- table row argument in the case of computed fields), the args object will
|
|
|
|
-- be omitted.
|
|
|
|
functionArgs ::
|
|
|
|
forall r m n pgKind.
|
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
FunctionTrackedAs ('Postgres pgKind) ->
|
|
|
|
Seq.Seq (FunctionInputArgument ('Postgres pgKind)) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (InputFieldsParser n (FunctionArgsExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind))))
|
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
|
|
|
functionArgs functionTrackedAs (toList -> inputArgs) = do
|
|
|
|
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
|
|
|
let customization = _siCustomization sourceInfo
|
|
|
|
tCase = _rscNamingConvention customization
|
|
|
|
mkTypename = runMkTypename $ _rscTypeNames customization
|
|
|
|
-- First, we iterate through the original sql arguments in order, to find the
|
|
|
|
-- corresponding graphql names. At the same time, we create the input field
|
|
|
|
-- parsers, in three groups: session argument, optional arguments, and
|
|
|
|
-- mandatory arguments. Optional arguments have a default value, mandatory
|
|
|
|
-- arguments don't.
|
|
|
|
(names, session, optional, mandatory) = mconcat $ snd $ mapAccumL splitArguments 1 inputArgs
|
2022-06-29 19:03:25 +03:00
|
|
|
defaultArguments = FunctionArgsExp (snd <$> session) Map.empty
|
|
|
|
|
|
|
|
if
|
|
|
|
| length session > 1 ->
|
2022-11-02 23:53:23 +03:00
|
|
|
-- We somehow found more than one session argument; this should never
|
|
|
|
-- happen and is an error on our side.
|
|
|
|
throw500 "there shouldn't be more than one session argument"
|
2022-06-29 19:03:25 +03:00
|
|
|
| null optional && null mandatory ->
|
2022-11-02 23:53:23 +03:00
|
|
|
-- There are no user-provided arguments to the function: there will be
|
|
|
|
-- no args field.
|
|
|
|
pure $ pure defaultArguments
|
2022-06-29 19:03:25 +03:00
|
|
|
| otherwise -> do
|
2022-11-02 23:53:23 +03:00
|
|
|
-- There are user-provided arguments: we need to parse an args object.
|
|
|
|
argumentParsers <- sequenceA $ optional <> mandatory
|
|
|
|
objectName <-
|
|
|
|
mkTypename . applyTypeNameCaseIdentifier tCase
|
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
|
|
|
<$> case functionTrackedAs of
|
2022-11-02 23:53:23 +03:00
|
|
|
FTAComputedField computedFieldName _sourceName tableName -> do
|
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
|
|
|
tableInfo <- askTableInfo tableName
|
2022-11-02 23:53:23 +03:00
|
|
|
computedFieldGQLName <- textToName $ computedFieldNameToText computedFieldName
|
|
|
|
tableGQLName <- getTableIdentifierName @('Postgres pgKind) tableInfo
|
|
|
|
pure $ mkFunctionArgsTypeName computedFieldGQLName tableGQLName
|
|
|
|
FTACustomFunction (CustomFunctionNames {cfnArgsName}) ->
|
|
|
|
pure $ C.fromCustomName cfnArgsName
|
|
|
|
let fieldName = Name._args
|
|
|
|
fieldDesc =
|
|
|
|
case functionTrackedAs of
|
|
|
|
FTAComputedField computedFieldName _sourceName tableName ->
|
|
|
|
G.Description $
|
|
|
|
"input parameters for computed field "
|
|
|
|
<> computedFieldName <<> " defined on table " <>> tableName
|
|
|
|
FTACustomFunction (CustomFunctionNames {cfnFunctionName}) ->
|
|
|
|
G.Description $ "input parameters for function " <>> cfnFunctionName
|
|
|
|
objectParser =
|
|
|
|
P.object objectName Nothing (sequenceA argumentParsers) `P.bind` \arguments -> do
|
|
|
|
-- After successfully parsing, we create a dictionary of the parsed fields
|
|
|
|
-- and we re-iterate through the original list of sql arguments, now with
|
|
|
|
-- the knowledge of their graphql name.
|
|
|
|
let foundArguments = Map.fromList $ catMaybes arguments <> session
|
|
|
|
argsWithNames = zip names inputArgs
|
2022-06-29 19:03:25 +03:00
|
|
|
|
2022-11-02 23:53:23 +03:00
|
|
|
-- All elements (in the orignal sql order) that are found in the result map
|
|
|
|
-- are treated as positional arguments, whether they were originally named or
|
|
|
|
-- not.
|
|
|
|
(positional, left) <- spanMaybeM (\(name, _) -> pure $ Map.lookup name foundArguments) argsWithNames
|
2022-06-29 19:03:25 +03:00
|
|
|
|
2022-11-02 23:53:23 +03:00
|
|
|
-- If there are arguments left, it means we found one that was not passed
|
|
|
|
-- positionally. As a result, any remaining argument will have to be passed
|
|
|
|
-- by name. We fail with a parse error if we encounter a positional sql
|
|
|
|
-- argument (that does not have a name in the sql function), as:
|
|
|
|
-- * only the last positional arguments can be omitted;
|
|
|
|
-- * it has no name we can use.
|
|
|
|
-- We also fail if we find a mandatory argument that was not
|
|
|
|
-- provided by the user.
|
|
|
|
named <- Map.fromList . catMaybes <$> traverse (namedArgument foundArguments) left
|
|
|
|
pure $ FunctionArgsExp positional named
|
|
|
|
pure $ P.field fieldName (Just fieldDesc) objectParser
|
2022-06-29 19:03:25 +03:00
|
|
|
where
|
2022-09-21 14:34:39 +03:00
|
|
|
sessionPlaceholder :: Postgres.ArgumentExp (IR.UnpreparedValue b)
|
|
|
|
sessionPlaceholder = Postgres.AEInput IR.UVSession
|
2022-06-29 19:03:25 +03:00
|
|
|
|
|
|
|
splitArguments ::
|
|
|
|
Int ->
|
|
|
|
FunctionInputArgument ('Postgres pgKind) ->
|
|
|
|
( Int,
|
|
|
|
( [Text], -- graphql names, in order
|
2022-09-21 14:34:39 +03:00
|
|
|
[(Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind)))], -- session argument
|
|
|
|
[SchemaT r m (InputFieldsParser n (Maybe (Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind)))))], -- optional argument
|
|
|
|
[SchemaT r m (InputFieldsParser n (Maybe (Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind)))))] -- mandatory argument
|
2022-06-29 19:03:25 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
splitArguments positionalIndex (IASessionVariables name) =
|
|
|
|
let argName = getFuncArgNameTxt name
|
|
|
|
in (positionalIndex, ([argName], [(argName, sessionPlaceholder)], [], []))
|
|
|
|
splitArguments positionalIndex (IAUserProvided arg) =
|
2022-09-21 14:34:39 +03:00
|
|
|
let (argName, newIndex) = case Postgres.faName arg of
|
2022-06-29 19:03:25 +03:00
|
|
|
Nothing -> ("arg_" <> tshow positionalIndex, positionalIndex + 1)
|
|
|
|
Just name -> (getFuncArgNameTxt name, positionalIndex)
|
2022-09-21 14:34:39 +03:00
|
|
|
in if Postgres.unHasDefault $ Postgres.faHasDefault arg
|
2022-06-29 19:03:25 +03:00
|
|
|
then (newIndex, ([argName], [], [parseArgument arg argName], []))
|
|
|
|
else (newIndex, ([argName], [], [], [parseArgument arg argName]))
|
|
|
|
|
2022-09-21 14:34:39 +03:00
|
|
|
parseArgument :: FunctionArgument ('Postgres pgKind) -> Text -> SchemaT r m (InputFieldsParser n (Maybe (Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind)))))
|
2022-06-29 19:03:25 +03:00
|
|
|
parseArgument arg name = do
|
2022-09-21 14:34:39 +03:00
|
|
|
typedParser <- columnParser (ColumnScalar $ Postgres.mkFunctionArgScalarType $ Postgres.faType arg) (G.Nullability True)
|
2022-06-29 19:03:25 +03:00
|
|
|
fieldName <- textToName name
|
|
|
|
|
|
|
|
-- Since all postgres function arguments are nullable, we define the
|
|
|
|
-- GraphQL fields in nullable types. As explained in Note [When are fields
|
|
|
|
-- optional?], this implies that they can be omitted. For backwards
|
|
|
|
-- compatibility reasons, and also to avoid surprises, we prefer to reject
|
|
|
|
-- the query if a mandatory argument is missing rather than filling the
|
|
|
|
-- blanks for the user.
|
|
|
|
--
|
|
|
|
-- As explained in Note [The value of omitted fields], we can still reject
|
|
|
|
-- queries when such nullable fields are omitted, and accept them when an
|
|
|
|
-- explicit value of `null` is used, as long as we don't set a default
|
|
|
|
-- value, not even `null`.
|
|
|
|
let argParser = P.fieldOptional fieldName Nothing typedParser
|
2022-09-21 14:34:39 +03:00
|
|
|
pure $ argParser `mapField` ((name,) . Postgres.AEInput . IR.mkParameter)
|
2022-06-29 19:03:25 +03:00
|
|
|
|
|
|
|
namedArgument ::
|
2022-09-21 14:34:39 +03:00
|
|
|
HashMap Text (Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind))) ->
|
2022-06-29 19:03:25 +03:00
|
|
|
(Text, FunctionInputArgument ('Postgres pgKind)) ->
|
2022-09-21 14:34:39 +03:00
|
|
|
n (Maybe (Text, Postgres.ArgumentExp (IR.UnpreparedValue ('Postgres pgKind))))
|
2022-06-29 19:03:25 +03:00
|
|
|
namedArgument dictionary (name, inputArgument) = case inputArgument of
|
|
|
|
IASessionVariables _ -> pure $ Just (name, sessionPlaceholder)
|
|
|
|
IAUserProvided arg -> case Map.lookup name dictionary of
|
2022-09-21 14:34:39 +03:00
|
|
|
Just parsedValue -> case Postgres.faName arg of
|
2022-06-29 19:03:25 +03:00
|
|
|
Just _ -> pure $ Just (name, parsedValue)
|
2022-07-27 15:24:50 +03:00
|
|
|
Nothing -> P.parseErrorWith P.NotSupported "Only last set of positional arguments can be omitted"
|
2022-06-29 19:03:25 +03:00
|
|
|
Nothing ->
|
2022-09-21 14:34:39 +03:00
|
|
|
whenMaybe (not $ Postgres.unHasDefault $ Postgres.faHasDefault arg) $
|
2022-07-27 15:24:50 +03:00
|
|
|
P.parseErrorWith P.NotSupported "Non default arguments cannot be omitted"
|
2022-06-29 19:03:25 +03:00
|
|
|
|
|
|
|
buildFunctionQueryFieldsPG ::
|
|
|
|
forall r m n pgKind.
|
2022-08-03 22:08:34 +03:00
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
MkRootFieldName ->
|
2022-06-29 19:03:25 +03:00
|
|
|
FunctionName ('Postgres pgKind) ->
|
|
|
|
FunctionInfo ('Postgres pgKind) ->
|
|
|
|
TableName ('Postgres pgKind) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField UnpreparedValue) (UnpreparedValue ('Postgres pgKind)))]
|
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
|
|
|
buildFunctionQueryFieldsPG mkRootFieldName functionName functionInfo tableName = do
|
2022-06-29 19:03:25 +03:00
|
|
|
let -- select function
|
|
|
|
funcDesc =
|
|
|
|
Just . G.Description $
|
2022-11-02 23:53:23 +03:00
|
|
|
flip fromMaybe (_fiComment functionInfo) $
|
|
|
|
"execute function " <> functionName <<> " which returns " <>> tableName
|
2022-06-29 19:03:25 +03:00
|
|
|
-- select function agg
|
2022-08-03 22:08:34 +03:00
|
|
|
funcAggDesc =
|
|
|
|
Just $ G.Description $ "execute function " <> functionName <<> " and query aggregates on result of table type " <>> tableName
|
2022-06-29 19:03:25 +03:00
|
|
|
|
|
|
|
queryResultType =
|
|
|
|
case _fiJsonAggSelect functionInfo of
|
|
|
|
JASMultipleRows -> QDBMultipleRows
|
|
|
|
JASSingleObject -> QDBSingleRow
|
|
|
|
|
|
|
|
catMaybes
|
|
|
|
<$> sequenceA
|
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
|
|
|
[ optionalFieldParser (queryResultType) $ selectFunction mkRootFieldName functionInfo funcDesc,
|
|
|
|
optionalFieldParser (QDBAggregation) $ selectFunctionAggregate mkRootFieldName functionInfo funcAggDesc
|
2022-06-29 19:03:25 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
buildFunctionMutationFieldsPG ::
|
|
|
|
forall r m n pgKind.
|
2022-08-03 22:08:34 +03:00
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
MkRootFieldName ->
|
2022-06-29 19:03:25 +03:00
|
|
|
FunctionName ('Postgres pgKind) ->
|
|
|
|
FunctionInfo ('Postgres pgKind) ->
|
|
|
|
TableName ('Postgres pgKind) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (MutationDB ('Postgres pgKind) (RemoteRelationshipField UnpreparedValue) (UnpreparedValue ('Postgres pgKind)))]
|
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
|
|
|
buildFunctionMutationFieldsPG mkRootFieldName functionName functionInfo tableName = do
|
2022-06-29 19:03:25 +03:00
|
|
|
let funcDesc = Just $ G.Description $ "execute VOLATILE function " <> functionName <<> " which returns " <>> tableName
|
|
|
|
jsonAggSelect = _fiJsonAggSelect functionInfo
|
|
|
|
catMaybes
|
|
|
|
<$> sequenceA
|
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
|
|
|
[ optionalFieldParser (MDBFunction jsonAggSelect) $ selectFunction mkRootFieldName functionInfo funcDesc
|
2022-06-29 19:03:25 +03:00
|
|
|
-- TODO: do we want aggregate mutation functions?
|
|
|
|
]
|