2022-01-18 17:53:44 +03:00
|
|
|
{-# LANGUAGE ApplicativeDo #-}
|
2022-08-24 14:58:53 +03:00
|
|
|
{-# LANGUAGE QuasiQuotes #-}
|
2022-05-26 14:54:30 +03:00
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
2021-04-22 00:44:37 +03:00
|
|
|
{-# LANGUAGE UndecidableInstances #-}
|
2021-09-24 01:56:37 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2022-02-08 12:24:34 +03:00
|
|
|
-- | Postgres Instances Schema
|
|
|
|
--
|
|
|
|
-- Defines a 'Hasura.GraphQL.Schema.Backend.BackendSchema' type class instance for Postgres.
|
2021-05-21 05:46:58 +03:00
|
|
|
module Hasura.Backends.Postgres.Instances.Schema
|
2022-07-18 18:15:34 +03:00
|
|
|
(
|
2021-09-24 01:56:37 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Aeson qualified as J
|
2022-06-08 18:31:28 +03:00
|
|
|
import Data.Aeson.Key qualified as K
|
2022-07-06 10:54:57 +03:00
|
|
|
import Data.Aeson.Types (JSONPathElement (..))
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Has
|
|
|
|
import Data.HashMap.Strict qualified as Map
|
|
|
|
import Data.HashMap.Strict.Extended qualified as M
|
|
|
|
import Data.List.NonEmpty qualified as NE
|
|
|
|
import Data.Parser.JSONPath
|
2022-05-26 14:54:30 +03:00
|
|
|
import Data.Text.Casing qualified as C
|
2021-09-24 01:56:37 +03:00
|
|
|
import Data.Text.Extended
|
2022-09-21 14:34:39 +03:00
|
|
|
import Hasura.Backends.Postgres.SQL.DML as Postgres hiding (CountType, incOp)
|
|
|
|
import Hasura.Backends.Postgres.SQL.Types as Postgres hiding (FunctionName, TableName)
|
|
|
|
import Hasura.Backends.Postgres.SQL.Value as Postgres
|
2021-12-15 20:07:21 +03:00
|
|
|
import Hasura.Backends.Postgres.Schema.OnConflict
|
2022-06-29 19:03:25 +03:00
|
|
|
import Hasura.Backends.Postgres.Schema.Select
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Backends.Postgres.Types.BoolExp
|
|
|
|
import Hasura.Backends.Postgres.Types.Column
|
2021-12-09 12:05:42 +03:00
|
|
|
import Hasura.Backends.Postgres.Types.Insert as PGIR
|
2021-11-18 21:02:58 +03:00
|
|
|
import Hasura.Backends.Postgres.Types.Update as PGIR
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Base.Error
|
An `ErrorMessage` type, to encapsulate.
This introduces an `ErrorMessage` newtype which wraps `Text` in a manner which is designed to be easy to construct, and difficult to deconstruct.
It provides functionality similar to `Data.Text.Extended`, but designed _only_ for error messages. Error messages are constructed through `fromString`, concatenation, or the `toErrorValue` function, which is designed to be overridden for all meaningful domain types that might show up in an error message. Notably, there are not and should never be instances of `ToErrorValue` for `String`, `Text`, `Int`, etc. This is so that we correctly represent the value in a way that is specific to its type. For example, all `Name` values (from the _graphql-parser-hs_ library) are single-quoted now; no exceptions.
I have mostly had to add `instance ToErrorValue` for various backend types (and also add newtypes where necessary). Some of these are not strictly necessary for this changeset, as I had bigger aspirations when I started. These aspirations have been tempered by trying and failing twice.
As such, in this changeset, I have started by introducing this type to the `parseError` and `parseErrorWith` functions. In the future, I would like to extend this to the `QErr` record and the various `throwError` functions, but this is a much larger task and should probably be done in stages.
For now, `toErrorMessage` and `fromErrorMessage` are provided for conversion to and from `Text`, but the intent is to stop exporting these once all error messages are converted to the new type.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5018
GitOrigin-RevId: 84b37e238992e4312255a87ca44f41af65e2d89a
2022-07-18 23:26:01 +03:00
|
|
|
import Hasura.Base.ErrorMessage (toErrorMessage)
|
|
|
|
import Hasura.Base.ToErrorValue
|
2022-10-18 11:42:38 +03:00
|
|
|
import Hasura.GraphQL.ApolloFederation (ApolloFederationParserFunction)
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Schema.Backend
|
|
|
|
( BackendSchema,
|
2022-06-30 18:22:19 +03:00
|
|
|
BackendTableSelectSchema,
|
2023-01-10 04:54:40 +03:00
|
|
|
BackendUpdateOperatorsSchema,
|
2021-09-24 01:56:37 +03:00
|
|
|
ComparisonExp,
|
|
|
|
MonadBuildSchema,
|
|
|
|
)
|
|
|
|
import Hasura.GraphQL.Schema.Backend qualified as BS
|
|
|
|
import Hasura.GraphQL.Schema.BoolExp
|
2022-08-24 14:58:53 +03:00
|
|
|
import Hasura.GraphQL.Schema.BoolExp.AggregationPredicates as Agg
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Schema.Build qualified as GSB
|
|
|
|
import Hasura.GraphQL.Schema.Common
|
2021-10-01 15:52:19 +03:00
|
|
|
import Hasura.GraphQL.Schema.Mutation qualified as GSB
|
2022-07-12 17:00:15 +03:00
|
|
|
import Hasura.GraphQL.Schema.NamingCase
|
2022-07-14 20:57:28 +03:00
|
|
|
import Hasura.GraphQL.Schema.Options qualified as Options
|
server: Metadata origin for definitions (type parameter version v2)
The code that builds the GraphQL schema, and `buildGQLContext` in particular, is partial: not every value of `(ServerConfigCtx, GraphQLQueryType, SourceCache, HashMap RemoteSchemaName (RemoteSchemaCtx, MetadataObject), ActionCache, AnnotatedCustomTypes)` results in a valid GraphQL schema. When it fails, we want to be able to return better error messages than we currently do.
The key thing that is missing is a way to trace back GraphQL type information to their origin from the Hasura metadata. Currently, we have a number of correctness checks of our GraphQL schema. But these correctness checks only have access to pure GraphQL type information, and hence can only report errors in terms of that. Possibly the worst is the "conflicting definitions" error, which, in practice, can only be debugged by Hasura engineers. This is terrible DX for customers.
This PR allows us to print better error messages, by adding a field to the `Definition` type that traces the GraphQL type to its origin in the metadata. So the idea is simple: just add `MetadataObjId`, or `Maybe` that, or some other sum type of that, to `Definition`.
However, we want to avoid having to import a `Hasura.RQL` module from `Hasura.GraphQL.Parser`. So we instead define this additional field of `Definition` through a new type parameter, which is threaded through in `Hasura.GraphQL.Parser`. We then define type synonyms in `Hasura.GraphQL.Schema.Parser` that fill in this type parameter, so that it is not visible for the majority of the codebase.
The idea of associating metadata information to `Definition`s really comes to fruition when combined with hasura/graphql-engine-mono#4517. Their combination would allow us to use the API of fatal errors (just like the current `MonadError QErr`) to report _inconsistencies_ in the metadata. Such inconsistencies are then _automatically_ ignored. So no ad-hoc decisions need to be made on how to cut out inconsistent metadata from the GraphQL schema. This will allow us to report much better errors, as well as improve the likelihood of a successful HGE startup.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4770
Co-authored-by: Samir Talwar <47582+SamirTalwar@users.noreply.github.com>
GitOrigin-RevId: 728402b0cae83ae8e83463a826ceeb609001acae
2022-06-28 18:52:26 +03:00
|
|
|
import Hasura.GraphQL.Schema.Parser
|
|
|
|
( Definition,
|
|
|
|
FieldParser,
|
|
|
|
InputFieldsParser,
|
|
|
|
Kind (..),
|
|
|
|
MonadParse,
|
|
|
|
Parser,
|
|
|
|
memoize,
|
2022-10-03 23:09:42 +03:00
|
|
|
memoizeOn,
|
2022-09-14 00:21:07 +03:00
|
|
|
type (<:),
|
server: Metadata origin for definitions (type parameter version v2)
The code that builds the GraphQL schema, and `buildGQLContext` in particular, is partial: not every value of `(ServerConfigCtx, GraphQLQueryType, SourceCache, HashMap RemoteSchemaName (RemoteSchemaCtx, MetadataObject), ActionCache, AnnotatedCustomTypes)` results in a valid GraphQL schema. When it fails, we want to be able to return better error messages than we currently do.
The key thing that is missing is a way to trace back GraphQL type information to their origin from the Hasura metadata. Currently, we have a number of correctness checks of our GraphQL schema. But these correctness checks only have access to pure GraphQL type information, and hence can only report errors in terms of that. Possibly the worst is the "conflicting definitions" error, which, in practice, can only be debugged by Hasura engineers. This is terrible DX for customers.
This PR allows us to print better error messages, by adding a field to the `Definition` type that traces the GraphQL type to its origin in the metadata. So the idea is simple: just add `MetadataObjId`, or `Maybe` that, or some other sum type of that, to `Definition`.
However, we want to avoid having to import a `Hasura.RQL` module from `Hasura.GraphQL.Parser`. So we instead define this additional field of `Definition` through a new type parameter, which is threaded through in `Hasura.GraphQL.Parser`. We then define type synonyms in `Hasura.GraphQL.Schema.Parser` that fill in this type parameter, so that it is not visible for the majority of the codebase.
The idea of associating metadata information to `Definition`s really comes to fruition when combined with hasura/graphql-engine-mono#4517. Their combination would allow us to use the API of fatal errors (just like the current `MonadError QErr`) to report _inconsistencies_ in the metadata. Such inconsistencies are then _automatically_ ignored. So no ad-hoc decisions need to be made on how to cut out inconsistent metadata from the GraphQL schema. This will allow us to report much better errors, as well as improve the likelihood of a successful HGE startup.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4770
Co-authored-by: Samir Talwar <47582+SamirTalwar@users.noreply.github.com>
GitOrigin-RevId: 728402b0cae83ae8e83463a826ceeb609001acae
2022-06-28 18:52:26 +03:00
|
|
|
)
|
|
|
|
import Hasura.GraphQL.Schema.Parser qualified as P
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.GraphQL.Schema.Select
|
2021-11-26 16:47:12 +03:00
|
|
|
import Hasura.GraphQL.Schema.Update qualified as SU
|
2023-01-10 04:54:40 +03:00
|
|
|
import Hasura.GraphQL.Schema.Update.Batch qualified as SUB
|
2023-02-22 12:22:22 +03:00
|
|
|
import Hasura.LogicalModel.Schema qualified as LogicalModels
|
2022-06-23 12:14:24 +03:00
|
|
|
import Hasura.Name qualified as Name
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.Prelude
|
2021-12-09 12:05:42 +03:00
|
|
|
import Hasura.RQL.IR.BoolExp
|
|
|
|
import Hasura.RQL.IR.Root (RemoteRelationshipField)
|
2023-01-10 04:54:40 +03:00
|
|
|
import Hasura.RQL.IR.Root qualified as IR
|
2021-12-09 12:05:42 +03:00
|
|
|
import Hasura.RQL.IR.Select
|
|
|
|
( QueryDB (QDBConnection),
|
|
|
|
)
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.RQL.IR.Select qualified as IR
|
Role-invariant schema constructors
We build the GraphQL schema by combining building blocks such as `tableSelectionSet` and `columnParser`. These building blocks individually build `{InputFields,Field,}Parser` objects. Those object specify the valid GraphQL schema.
Since the GraphQL schema is role-dependent, at some point we need to know what fragment of the GraphQL schema a specific role is allowed to access, and this is stored in `{Sel,Upd,Ins,Del}PermInfo` objects.
We have passed around these permission objects as function arguments to the schema building blocks since we first started dealing with permissions during the PDV refactor - see hasura/graphql-engine@5168b99e463199b1934d8645bd6cd37eddb64ae1 in hasura/graphql-engine#4111. This means that, for instance, `tableSelectionSet` has as its type:
```haskell
tableSelectionSet ::
forall b r m n.
MonadBuildSchema b r m n =>
SourceName ->
TableInfo b ->
SelPermInfo b ->
m (Parser 'Output n (AnnotatedFields b))
```
There are three reasons to change this.
1. We often pass a `Maybe (xPermInfo b)` instead of a proper `xPermInfo b`, and it's not clear what the intended semantics of this is. Some potential improvements on the data types involved are discussed in issue hasura/graphql-engine-mono#3125.
2. In most cases we also already pass a `TableInfo b`, and together with the `MonadRole` that is usually also in scope, this means that we could look up the required permissions regardless: so passing the permissions explicitly undermines the "single source of truth" principle. Breaking this principle also makes the code more difficult to read.
3. We are working towards role-based parsers (see hasura/graphql-engine-mono#2711), where the `{InputFields,Field,}Parser` objects are constructed in a role-invariant way, so that we have a single object that can be used for all roles. In particular, this means that the schema building blocks _need_ to be constructed in a role-invariant way. While this PR doesn't accomplish that, it does reduce the amount of role-specific arguments being passed, thus fixing hasura/graphql-engine-mono#3068.
Concretely, this PR simply drops the `xPermInfo b` argument from almost all schema building blocks. Instead these objects are looked up from the `TableInfo b` as-needed. The resulting code is considerably simpler and shorter.
One way to interpret this change is as follows. Before this PR, we figured out permissions at the top-level in `Hasura.GraphQL.Schema`, passing down the obtained `xPermInfo` objects as required. After this PR, we have a bottom-up approach where the schema building blocks themselves decide whether they want to be included for a particular role.
So this moves some permission logic out of `Hasura.GraphQL.Schema`, which is very complex.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3608
GitOrigin-RevId: 51a744f34ec7d57bc8077667ae7f9cb9c4f6c962
2022-02-17 11:16:20 +03:00
|
|
|
import Hasura.RQL.IR.Update qualified as IR
|
2022-05-31 01:07:02 +03:00
|
|
|
import Hasura.RQL.IR.Value qualified as IR
|
2021-12-09 12:05:42 +03:00
|
|
|
import Hasura.RQL.Types.Backend (Backend (..))
|
|
|
|
import Hasura.RQL.Types.Column
|
|
|
|
import Hasura.RQL.Types.Function (FunctionInfo)
|
Remove circular dependency in schema building code
### Description
The main goal of this PR is, as stated, to remove the circular dependency in the schema building code. This cycle arises from the existence of remote relationships: when we build the schema for a source A, a remote relationship might force us to jump to the schema of a source B, or some remote schema. As a result, we end up having to do a dispatch from a "leaf" of the schema, similar to the one done at the root. In turn, this forces us to carry along in the schema a lot of information required for that dispatch, AND it forces us to import the instances in scope, creating an import loop.
As discussed in #4489, this PR implements the "dependency injection" solution: we pass to the schema a function to call to do the dispatch, and to get a generated field for a remote relationship. That way, this function can be chosen at the root level, and the leaves need not be aware of the overall context.
This PR grew a bit bigger than that, however; in an attempt to try and remove the `SourceCache` from the schema altogether, it changed a lot of functions across the schema building code, to thread along the `SourceInfo b` of the source being built. This avoids having to do cache lookups within a given source. A few cases remain, such as relay, that we might try to tackle in a subsequent PR.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4557
GitOrigin-RevId: 9388e48372877520a72a9fd1677005df9f7b2d72
2022-05-27 20:21:22 +03:00
|
|
|
import Hasura.RQL.Types.Source
|
2022-05-26 14:54:30 +03:00
|
|
|
import Hasura.RQL.Types.SourceCustomization
|
2023-01-10 04:54:40 +03:00
|
|
|
import Hasura.RQL.Types.Table (TableInfo (..), UpdPermInfo (..))
|
2022-08-19 17:19:54 +03:00
|
|
|
import Hasura.SQL.Backend (BackendType (Postgres), PostgresKind (Citus, Cockroach, Vanilla))
|
2021-09-24 01:56:37 +03:00
|
|
|
import Hasura.SQL.Types
|
|
|
|
import Language.GraphQL.Draft.Syntax qualified as G
|
2022-08-24 14:58:53 +03:00
|
|
|
import Language.GraphQL.Draft.Syntax.QQ qualified as G
|
2021-02-23 20:37:27 +03:00
|
|
|
|
|
|
|
----------------------------------------------------------------
|
|
|
|
-- BackendSchema instance
|
|
|
|
|
2021-04-22 00:44:37 +03:00
|
|
|
-- | This class is an implementation detail of 'BackendSchema'.
|
|
|
|
-- Some functions of 'BackendSchema' differ across different Postgres "kinds",
|
|
|
|
-- or call to functions (such as those related to Relay) that have not been
|
|
|
|
-- generalized to all kinds of Postgres and still explicitly work on Vanilla
|
2021-11-18 21:02:58 +03:00
|
|
|
-- Postgres. This class allows each "kind" to specify its own specific
|
2021-04-22 00:44:37 +03:00
|
|
|
-- implementation. All common code is directly part of `BackendSchema`.
|
2021-11-18 21:02:58 +03:00
|
|
|
--
|
|
|
|
-- Note: Users shouldn't ever put this as a constraint. Use `BackendSchema
|
|
|
|
-- ('Postgres pgKind)` instead.
|
2021-04-22 00:44:37 +03:00
|
|
|
class PostgresSchema (pgKind :: PostgresKind) where
|
2021-09-24 01:56:37 +03:00
|
|
|
pgkBuildTableRelayQueryFields ::
|
2022-08-03 22:08:34 +03:00
|
|
|
forall r m n.
|
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
MkRootFieldName ->
|
2021-09-24 01:56:37 +03:00
|
|
|
TableName ('Postgres pgKind) ->
|
|
|
|
TableInfo ('Postgres pgKind) ->
|
2022-05-26 14:54:30 +03:00
|
|
|
C.GQLNameIdentifier ->
|
2021-09-24 01:56:37 +03:00
|
|
|
NESeq (ColumnInfo ('Postgres pgKind)) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue ('Postgres pgKind)))]
|
2021-09-24 01:56:37 +03:00
|
|
|
pgkBuildFunctionRelayQueryFields ::
|
2022-08-03 22:08:34 +03:00
|
|
|
forall r m n.
|
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
MkRootFieldName ->
|
2021-09-24 01:56:37 +03:00
|
|
|
FunctionName ('Postgres pgKind) ->
|
|
|
|
FunctionInfo ('Postgres pgKind) ->
|
|
|
|
TableName ('Postgres pgKind) ->
|
|
|
|
NESeq (ColumnInfo ('Postgres pgKind)) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue ('Postgres pgKind)))]
|
2021-09-24 01:56:37 +03:00
|
|
|
pgkRelayExtension ::
|
|
|
|
Maybe (XRelay ('Postgres pgKind))
|
2022-10-18 11:42:38 +03:00
|
|
|
pgkBuildTableQueryAndSubscriptionFields ::
|
|
|
|
forall r m n.
|
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
AggregationPredicatesSchema ('Postgres pgKind),
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
MkRootFieldName ->
|
|
|
|
TableName ('Postgres pgKind) ->
|
|
|
|
TableInfo ('Postgres pgKind) ->
|
|
|
|
C.GQLNameIdentifier ->
|
|
|
|
SchemaT
|
|
|
|
r
|
|
|
|
m
|
|
|
|
( [FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue ('Postgres pgKind)))],
|
|
|
|
[FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue ('Postgres pgKind)))],
|
|
|
|
Maybe (G.Name, Parser 'Output n (ApolloFederationParserFunction n))
|
|
|
|
)
|
|
|
|
pgkBuildTableStreamingSubscriptionFields ::
|
|
|
|
forall r m n.
|
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
AggregationPredicatesSchema ('Postgres pgKind),
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
MkRootFieldName ->
|
|
|
|
TableName ('Postgres pgKind) ->
|
|
|
|
TableInfo ('Postgres pgKind) ->
|
|
|
|
C.GQLNameIdentifier ->
|
|
|
|
SchemaT r m [FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue ('Postgres pgKind)))]
|
2021-04-22 00:44:37 +03:00
|
|
|
|
|
|
|
instance PostgresSchema 'Vanilla where
|
2021-09-24 01:56:37 +03:00
|
|
|
pgkBuildTableRelayQueryFields = buildTableRelayQueryFields
|
2021-04-22 00:44:37 +03:00
|
|
|
pgkBuildFunctionRelayQueryFields = buildFunctionRelayQueryFields
|
2021-06-09 16:02:15 +03:00
|
|
|
pgkRelayExtension = Just ()
|
2022-10-18 11:42:38 +03:00
|
|
|
pgkBuildTableQueryAndSubscriptionFields = GSB.buildTableQueryAndSubscriptionFields
|
|
|
|
pgkBuildTableStreamingSubscriptionFields = GSB.buildTableStreamingSubscriptionFields
|
2021-04-22 00:44:37 +03:00
|
|
|
|
2021-05-21 05:46:58 +03:00
|
|
|
instance PostgresSchema 'Citus where
|
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
|
|
|
pgkBuildTableRelayQueryFields _ _ _ _ _ = pure []
|
|
|
|
pgkBuildFunctionRelayQueryFields _ _ _ _ _ = pure []
|
2021-06-09 16:02:15 +03:00
|
|
|
pgkRelayExtension = Nothing
|
2022-10-18 11:42:38 +03:00
|
|
|
pgkBuildTableQueryAndSubscriptionFields = GSB.buildTableQueryAndSubscriptionFields
|
|
|
|
pgkBuildTableStreamingSubscriptionFields = GSB.buildTableStreamingSubscriptionFields
|
2021-05-21 05:46:58 +03:00
|
|
|
|
2022-08-19 17:19:54 +03:00
|
|
|
instance PostgresSchema 'Cockroach where
|
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
|
|
|
pgkBuildTableRelayQueryFields _ _ _ _ _ = pure []
|
|
|
|
pgkBuildFunctionRelayQueryFields _ _ _ _ _ = pure []
|
2022-10-21 22:10:28 +03:00
|
|
|
pgkRelayExtension = Nothing
|
2022-10-27 20:26:03 +03:00
|
|
|
pgkBuildTableQueryAndSubscriptionFields = GSB.buildTableQueryAndSubscriptionFields
|
|
|
|
pgkBuildTableStreamingSubscriptionFields = GSB.buildTableStreamingSubscriptionFields
|
2022-10-18 11:42:38 +03:00
|
|
|
|
2021-05-21 05:46:58 +03:00
|
|
|
-- postgres schema
|
2021-04-22 00:44:37 +03:00
|
|
|
|
2022-09-23 16:48:38 +03:00
|
|
|
instance (BackendSchema ('Postgres pgKind)) => AggregationPredicatesSchema ('Postgres pgKind) where
|
|
|
|
aggregationPredicatesParser = Agg.defaultAggregationPredicatesParser aggregationFunctions
|
2022-08-24 14:58:53 +03:00
|
|
|
|
|
|
|
-- | The aggregation functions that are supported by postgres variants.
|
2022-09-23 16:48:38 +03:00
|
|
|
aggregationFunctions :: [Agg.FunctionSignature ('Postgres pgKind)]
|
|
|
|
aggregationFunctions =
|
2022-08-24 14:58:53 +03:00
|
|
|
[ Agg.FunctionSignature
|
2022-09-23 16:48:38 +03:00
|
|
|
{ fnName = "avg",
|
|
|
|
fnGQLName = [G.name|avg|],
|
|
|
|
fnReturnType = PGDouble,
|
|
|
|
fnArguments = Agg.SingleArgument PGDouble
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
|
|
|
{ fnName = "bool_and",
|
|
|
|
fnGQLName = [G.name|bool_and|],
|
|
|
|
fnReturnType = PGBoolean,
|
|
|
|
fnArguments = Agg.SingleArgument PGBoolean
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
|
|
|
{ fnName = "bool_or",
|
|
|
|
fnGQLName = [G.name|bool_or|],
|
|
|
|
fnReturnType = PGBoolean,
|
|
|
|
fnArguments = Agg.SingleArgument PGBoolean
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
2022-08-24 14:58:53 +03:00
|
|
|
{ fnName = "count",
|
|
|
|
fnGQLName = [G.name|count|],
|
|
|
|
fnReturnType = PGInteger,
|
|
|
|
fnArguments = Agg.ArgumentsStar
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
2022-09-23 16:48:38 +03:00
|
|
|
{ fnName = "max",
|
|
|
|
fnGQLName = [G.name|max|],
|
|
|
|
fnReturnType = PGDouble,
|
|
|
|
fnArguments = Agg.SingleArgument PGDouble
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
|
|
|
{ fnName = "min",
|
|
|
|
fnGQLName = [G.name|min|],
|
|
|
|
fnReturnType = PGDouble,
|
|
|
|
fnArguments = Agg.SingleArgument PGDouble
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
|
|
|
{ fnName = "sum",
|
|
|
|
fnGQLName = [G.name|sum|],
|
|
|
|
fnReturnType = PGDouble,
|
|
|
|
fnArguments = Agg.SingleArgument PGDouble
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
|
|
|
{ fnName = "corr",
|
|
|
|
fnGQLName = [G.name|corr|],
|
|
|
|
fnReturnType = PGDouble,
|
2022-08-24 14:58:53 +03:00
|
|
|
fnArguments =
|
|
|
|
Agg.Arguments
|
|
|
|
( NE.fromList
|
|
|
|
[ Agg.ArgumentSignature
|
2022-09-23 16:48:38 +03:00
|
|
|
{ argType = PGDouble,
|
|
|
|
argName = [G.name|Y|]
|
|
|
|
},
|
|
|
|
Agg.ArgumentSignature
|
|
|
|
{ argType = PGDouble,
|
|
|
|
argName = [G.name|X|]
|
2022-08-24 14:58:53 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
2022-09-23 16:48:38 +03:00
|
|
|
{ fnName = "covar_samp",
|
|
|
|
fnGQLName = [G.name|covar_samp|],
|
2022-08-24 14:58:53 +03:00
|
|
|
fnReturnType = PGDouble,
|
|
|
|
fnArguments =
|
|
|
|
Agg.Arguments
|
|
|
|
( NE.fromList
|
|
|
|
[ Agg.ArgumentSignature
|
|
|
|
{ argType = PGDouble,
|
|
|
|
argName = [G.name|Y|]
|
|
|
|
},
|
|
|
|
Agg.ArgumentSignature
|
|
|
|
{ argType = PGDouble,
|
|
|
|
argName = [G.name|X|]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|
2022-09-23 16:48:38 +03:00
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
|
|
|
{ fnName = "stddev_samp",
|
|
|
|
fnGQLName = [G.name|stddev_samp|],
|
|
|
|
fnReturnType = PGDouble,
|
|
|
|
fnArguments = Agg.SingleArgument PGDouble
|
|
|
|
},
|
|
|
|
Agg.FunctionSignature
|
|
|
|
{ fnName = "var_samp",
|
|
|
|
fnGQLName = [G.name|var_samp|],
|
|
|
|
fnReturnType = PGDouble,
|
|
|
|
fnArguments = Agg.SingleArgument PGDouble
|
2022-08-24 14:58:53 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-06-30 18:22:19 +03:00
|
|
|
instance
|
|
|
|
( PostgresSchema pgKind,
|
2022-10-06 12:07:14 +03:00
|
|
|
Backend ('Postgres pgKind)
|
2022-06-30 18:22:19 +03:00
|
|
|
) =>
|
|
|
|
BS.BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
where
|
|
|
|
tableArguments = defaultTableArgs
|
|
|
|
selectTable = defaultSelectTable
|
|
|
|
selectTableAggregate = defaultSelectTableAggregate
|
|
|
|
tableSelectionSet = defaultTableSelectionSet
|
|
|
|
|
2023-02-15 20:55:06 +03:00
|
|
|
instance
|
|
|
|
( PostgresSchema pgKind,
|
|
|
|
Backend ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
BS.BackendCustomTypeSelectSchema ('Postgres pgKind)
|
|
|
|
where
|
2023-03-06 19:38:18 +03:00
|
|
|
logicalModelArguments = defaultLogicalModelArgs
|
|
|
|
logicalModelSelectionSet = defaultLogicalModelSelectionSet
|
2023-02-15 20:55:06 +03:00
|
|
|
|
2021-04-22 00:44:37 +03:00
|
|
|
instance
|
2021-11-08 21:11:44 +03:00
|
|
|
( Backend ('Postgres pgKind),
|
2021-09-24 01:56:37 +03:00
|
|
|
PostgresSchema pgKind
|
|
|
|
) =>
|
|
|
|
BackendSchema ('Postgres pgKind)
|
|
|
|
where
|
2021-02-23 20:37:27 +03:00
|
|
|
-- top level parsers
|
2022-10-18 11:42:38 +03:00
|
|
|
buildTableQueryAndSubscriptionFields = pgkBuildTableQueryAndSubscriptionFields
|
2021-09-24 01:56:37 +03:00
|
|
|
buildTableRelayQueryFields = pgkBuildTableRelayQueryFields
|
2022-10-18 11:42:38 +03:00
|
|
|
buildTableStreamingSubscriptionFields = pgkBuildTableStreamingSubscriptionFields
|
2021-12-09 12:05:42 +03:00
|
|
|
buildTableInsertMutationFields = GSB.buildTableInsertMutationFields backendInsertParser
|
Role-invariant schema constructors
We build the GraphQL schema by combining building blocks such as `tableSelectionSet` and `columnParser`. These building blocks individually build `{InputFields,Field,}Parser` objects. Those object specify the valid GraphQL schema.
Since the GraphQL schema is role-dependent, at some point we need to know what fragment of the GraphQL schema a specific role is allowed to access, and this is stored in `{Sel,Upd,Ins,Del}PermInfo` objects.
We have passed around these permission objects as function arguments to the schema building blocks since we first started dealing with permissions during the PDV refactor - see hasura/graphql-engine@5168b99e463199b1934d8645bd6cd37eddb64ae1 in hasura/graphql-engine#4111. This means that, for instance, `tableSelectionSet` has as its type:
```haskell
tableSelectionSet ::
forall b r m n.
MonadBuildSchema b r m n =>
SourceName ->
TableInfo b ->
SelPermInfo b ->
m (Parser 'Output n (AnnotatedFields b))
```
There are three reasons to change this.
1. We often pass a `Maybe (xPermInfo b)` instead of a proper `xPermInfo b`, and it's not clear what the intended semantics of this is. Some potential improvements on the data types involved are discussed in issue hasura/graphql-engine-mono#3125.
2. In most cases we also already pass a `TableInfo b`, and together with the `MonadRole` that is usually also in scope, this means that we could look up the required permissions regardless: so passing the permissions explicitly undermines the "single source of truth" principle. Breaking this principle also makes the code more difficult to read.
3. We are working towards role-based parsers (see hasura/graphql-engine-mono#2711), where the `{InputFields,Field,}Parser` objects are constructed in a role-invariant way, so that we have a single object that can be used for all roles. In particular, this means that the schema building blocks _need_ to be constructed in a role-invariant way. While this PR doesn't accomplish that, it does reduce the amount of role-specific arguments being passed, thus fixing hasura/graphql-engine-mono#3068.
Concretely, this PR simply drops the `xPermInfo b` argument from almost all schema building blocks. Instead these objects are looked up from the `TableInfo b` as-needed. The resulting code is considerably simpler and shorter.
One way to interpret this change is as follows. Before this PR, we figured out permissions at the top-level in `Hasura.GraphQL.Schema`, passing down the obtained `xPermInfo` objects as required. After this PR, we have a bottom-up approach where the schema building blocks themselves decide whether they want to be included for a particular role.
So this moves some permission logic out of `Hasura.GraphQL.Schema`, which is very complex.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3608
GitOrigin-RevId: 51a744f34ec7d57bc8077667ae7f9cb9c4f6c962
2022-02-17 11:16:20 +03:00
|
|
|
buildTableUpdateMutationFields = pgkBuildTableUpdateMutationFields
|
2021-02-23 20:37:27 +03:00
|
|
|
buildTableDeleteMutationFields = GSB.buildTableDeleteMutationFields
|
2022-06-29 19:03:25 +03:00
|
|
|
buildFunctionQueryFields = buildFunctionQueryFieldsPG
|
2021-09-24 01:56:37 +03:00
|
|
|
buildFunctionRelayQueryFields = pgkBuildFunctionRelayQueryFields
|
2022-06-29 19:03:25 +03:00
|
|
|
buildFunctionMutationFields = buildFunctionMutationFieldsPG
|
2023-02-21 16:45:12 +03:00
|
|
|
buildLogicalModelRootFields = LogicalModels.defaultBuildLogicalModelRootFields
|
2021-06-15 18:53:20 +03:00
|
|
|
|
2021-12-09 12:05:42 +03:00
|
|
|
mkRelationshipParser = GSB.mkDefaultRelationshipParser backendInsertParser ()
|
2021-06-15 18:53:20 +03:00
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
-- backend extensions
|
2021-09-24 01:56:37 +03:00
|
|
|
relayExtension = pgkRelayExtension @pgKind
|
|
|
|
nodesAggExtension = Just ()
|
2022-04-22 22:53:12 +03:00
|
|
|
streamSubscriptionExtension = Just ()
|
2021-06-15 18:53:20 +03:00
|
|
|
|
2022-10-21 22:10:28 +03:00
|
|
|
-- individual components
|
2021-09-24 01:56:37 +03:00
|
|
|
columnParser = columnParser
|
2022-09-14 00:21:07 +03:00
|
|
|
enumParser = enumParser @pgKind
|
|
|
|
possiblyNullable = possiblyNullable
|
2022-05-03 11:58:56 +03:00
|
|
|
scalarSelectionArgumentsParser = pgScalarSelectionArgumentsParser
|
2022-05-26 14:54:30 +03:00
|
|
|
|
|
|
|
-- NOTE: We don't use @orderByOperators@ directly as this will cause memory
|
|
|
|
-- growth, instead we use separate functions, according to @jberryman on the
|
|
|
|
-- memory growth, "This is turning a CAF Into a function, And the output is
|
|
|
|
-- likely no longer going to be shared even for the same arguments, and even
|
|
|
|
-- though the domain is extremely small (just HasuraCase or GraphqlCase)."
|
2022-06-10 06:59:00 +03:00
|
|
|
orderByOperators _sourceInfo = \case
|
2022-05-26 14:54:30 +03:00
|
|
|
HasuraCase -> orderByOperatorsHasuraCase
|
|
|
|
GraphqlCase -> orderByOperatorsGraphqlCase
|
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
|
|
|
comparisonExps = comparisonExps
|
2022-01-18 17:53:44 +03:00
|
|
|
countTypeInput = countTypeInput
|
2022-09-21 14:34:39 +03:00
|
|
|
aggregateOrderByCountType = Postgres.PGInteger
|
2021-09-24 01:56:37 +03:00
|
|
|
computedField = computedFieldPG
|
2021-06-15 18:53:20 +03:00
|
|
|
|
2023-01-10 04:54:40 +03:00
|
|
|
instance Backend ('Postgres pgKind) => BackendUpdateOperatorsSchema ('Postgres pgKind) where
|
|
|
|
type UpdateOperators ('Postgres pgKind) = UpdateOpExpression
|
|
|
|
|
|
|
|
parseUpdateOperators = pgkParseUpdateOperators
|
|
|
|
|
2021-12-09 12:05:42 +03:00
|
|
|
backendInsertParser ::
|
|
|
|
forall pgKind m r n.
|
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
TableInfo ('Postgres pgKind) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (InputFieldsParser n (PGIR.BackendInsert 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
|
|
|
backendInsertParser tableInfo =
|
|
|
|
fmap BackendInsert <$> onConflictFieldParser tableInfo
|
2021-10-01 15:52:19 +03:00
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
----------------------------------------------------------------
|
|
|
|
-- Top level parsers
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
buildTableRelayQueryFields ::
|
2022-08-03 22:08:34 +03:00
|
|
|
forall r m n pgKind.
|
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
MkRootFieldName ->
|
2021-09-24 01:56:37 +03:00
|
|
|
TableName ('Postgres pgKind) ->
|
|
|
|
TableInfo ('Postgres pgKind) ->
|
2022-05-26 14:54:30 +03:00
|
|
|
C.GQLNameIdentifier ->
|
2021-09-24 01:56:37 +03:00
|
|
|
NESeq (ColumnInfo ('Postgres pgKind)) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField IR.UnpreparedValue) (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
|
|
|
buildTableRelayQueryFields mkRootFieldName tableName tableInfo gqlName pkeyColumns = do
|
|
|
|
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
|
|
|
let customization = _siCustomization sourceInfo
|
|
|
|
tCase = _rscNamingConvention customization
|
|
|
|
fieldDesc = Just $ G.Description $ "fetch data from the table: " <>> tableName
|
2022-08-03 22:08:34 +03:00
|
|
|
rootFieldName = runMkRootFieldName mkRootFieldName $ applyFieldNameCaseIdentifier tCase (mkRelayConnectionField gqlName)
|
2021-09-24 01:56:37 +03:00
|
|
|
fmap afold $
|
2021-12-09 12:05:42 +03:00
|
|
|
optionalFieldParser QDBConnection $
|
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
|
|
|
selectTableConnection tableInfo rootFieldName fieldDesc pkeyColumns
|
Role-invariant schema constructors
We build the GraphQL schema by combining building blocks such as `tableSelectionSet` and `columnParser`. These building blocks individually build `{InputFields,Field,}Parser` objects. Those object specify the valid GraphQL schema.
Since the GraphQL schema is role-dependent, at some point we need to know what fragment of the GraphQL schema a specific role is allowed to access, and this is stored in `{Sel,Upd,Ins,Del}PermInfo` objects.
We have passed around these permission objects as function arguments to the schema building blocks since we first started dealing with permissions during the PDV refactor - see hasura/graphql-engine@5168b99e463199b1934d8645bd6cd37eddb64ae1 in hasura/graphql-engine#4111. This means that, for instance, `tableSelectionSet` has as its type:
```haskell
tableSelectionSet ::
forall b r m n.
MonadBuildSchema b r m n =>
SourceName ->
TableInfo b ->
SelPermInfo b ->
m (Parser 'Output n (AnnotatedFields b))
```
There are three reasons to change this.
1. We often pass a `Maybe (xPermInfo b)` instead of a proper `xPermInfo b`, and it's not clear what the intended semantics of this is. Some potential improvements on the data types involved are discussed in issue hasura/graphql-engine-mono#3125.
2. In most cases we also already pass a `TableInfo b`, and together with the `MonadRole` that is usually also in scope, this means that we could look up the required permissions regardless: so passing the permissions explicitly undermines the "single source of truth" principle. Breaking this principle also makes the code more difficult to read.
3. We are working towards role-based parsers (see hasura/graphql-engine-mono#2711), where the `{InputFields,Field,}Parser` objects are constructed in a role-invariant way, so that we have a single object that can be used for all roles. In particular, this means that the schema building blocks _need_ to be constructed in a role-invariant way. While this PR doesn't accomplish that, it does reduce the amount of role-specific arguments being passed, thus fixing hasura/graphql-engine-mono#3068.
Concretely, this PR simply drops the `xPermInfo b` argument from almost all schema building blocks. Instead these objects are looked up from the `TableInfo b` as-needed. The resulting code is considerably simpler and shorter.
One way to interpret this change is as follows. Before this PR, we figured out permissions at the top-level in `Hasura.GraphQL.Schema`, passing down the obtained `xPermInfo` objects as required. After this PR, we have a bottom-up approach where the schema building blocks themselves decide whether they want to be included for a particular role.
So this moves some permission logic out of `Hasura.GraphQL.Schema`, which is very complex.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3608
GitOrigin-RevId: 51a744f34ec7d57bc8077667ae7f9cb9c4f6c962
2022-02-17 11:16:20 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
buildFunctionRelayQueryFields ::
|
2022-08-03 22:08:34 +03:00
|
|
|
forall r m n pgKind.
|
|
|
|
( MonadBuildSchema ('Postgres pgKind) r m n,
|
|
|
|
BackendTableSelectSchema ('Postgres pgKind)
|
|
|
|
) =>
|
|
|
|
MkRootFieldName ->
|
2021-09-24 01:56:37 +03:00
|
|
|
FunctionName ('Postgres pgKind) ->
|
|
|
|
FunctionInfo ('Postgres pgKind) ->
|
|
|
|
TableName ('Postgres pgKind) ->
|
|
|
|
NESeq (ColumnInfo ('Postgres pgKind)) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m [FieldParser n (QueryDB ('Postgres pgKind) (RemoteRelationshipField IR.UnpreparedValue) (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
|
|
|
buildFunctionRelayQueryFields mkRootFieldName functionName functionInfo tableName pkeyColumns = do
|
2021-11-26 00:07:53 +03:00
|
|
|
let fieldDesc = Just $ G.Description $ "execute function " <> functionName <<> " which returns " <>> tableName
|
2021-09-24 01:56:37 +03:00
|
|
|
fmap afold $
|
2021-12-09 12:05:42 +03:00
|
|
|
optionalFieldParser QDBConnection $
|
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 functionInfo fieldDesc pkeyColumns
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2023-01-10 04:54:40 +03:00
|
|
|
pgkBuildTableUpdateMutationFields ::
|
|
|
|
forall r m n pgKind.
|
|
|
|
(MonadBuildSchema ('Postgres pgKind) r m n, PostgresSchema pgKind) =>
|
|
|
|
Scenario ->
|
|
|
|
TableInfo ('Postgres pgKind) ->
|
|
|
|
C.GQLNameIdentifier ->
|
|
|
|
SchemaT r m [P.FieldParser n (IR.AnnotatedUpdateG ('Postgres pgKind) (IR.RemoteRelationshipField IR.UnpreparedValue) (IR.UnpreparedValue ('Postgres pgKind)))]
|
|
|
|
pgkBuildTableUpdateMutationFields scenario tableInfo gqlName = do
|
|
|
|
updateRootFields <- GSB.buildSingleBatchTableUpdateMutationFields SingleBatch scenario tableInfo gqlName
|
|
|
|
updateManyRootField <- SUB.updateTableMany MultipleBatches scenario tableInfo gqlName
|
|
|
|
pure $ updateRootFields ++ (maybeToList updateManyRootField)
|
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
----------------------------------------------------------------
|
|
|
|
-- Individual components
|
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
columnParser ::
|
2022-09-14 00:21:07 +03:00
|
|
|
forall pgKind r m n.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
2021-09-24 01:56:37 +03:00
|
|
|
ColumnType ('Postgres pgKind) ->
|
|
|
|
G.Nullability ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (Parser 'Both n (IR.ValueWithOrigin (ColumnValue ('Postgres pgKind))))
|
2022-10-03 23:09:42 +03:00
|
|
|
columnParser columnType nullability = case columnType of
|
|
|
|
ColumnScalar scalarType -> memoizeOn 'columnParser (scalarType, nullability) do
|
|
|
|
-- We convert the value to JSON and use the FromJSON instance. This avoids
|
|
|
|
-- having two separate ways of parsing a value in the codebase, which
|
|
|
|
-- could lead to inconsistencies.
|
|
|
|
--
|
|
|
|
-- The mapping from postgres type to GraphQL scalar name is done by
|
|
|
|
-- 'mkScalarTypeName'. This is confusing, and we might want to fix it
|
|
|
|
-- later, as we will parse values differently here than how they'd be
|
|
|
|
-- parsed in other places using the same scalar name; for instance, we
|
|
|
|
-- will accept strings for postgres columns of type "Integer", despite the
|
|
|
|
-- fact that they will be represented as GraphQL ints, which otherwise do
|
|
|
|
-- not accept strings.
|
|
|
|
--
|
|
|
|
-- TODO: introduce new dedicated scalars for Postgres column types.
|
|
|
|
name <- mkScalarTypeName scalarType
|
|
|
|
let schemaType = P.TNamed P.NonNullable $ P.Definition name Nothing Nothing [] P.TIScalar
|
|
|
|
pure $
|
|
|
|
peelWithOrigin $
|
|
|
|
fmap (ColumnValue columnType) $
|
|
|
|
possiblyNullable scalarType nullability $
|
|
|
|
P.Parser
|
|
|
|
{ pType = schemaType,
|
|
|
|
pParser =
|
|
|
|
P.valueToJSON (P.toGraphQLType schemaType) >=> \case
|
|
|
|
J.Null -> P.parseError $ "unexpected null value for type " <> toErrorValue name
|
|
|
|
value ->
|
|
|
|
runAesonParser (parsePGValue scalarType) value
|
|
|
|
`onLeft` (P.parseErrorWith P.ParseFailed . toErrorMessage . qeError)
|
|
|
|
}
|
|
|
|
ColumnEnumReference (EnumReference tableName enumValues tableCustomName) ->
|
|
|
|
case nonEmpty (Map.toList enumValues) of
|
|
|
|
Just enumValuesList ->
|
|
|
|
peelWithOrigin . fmap (ColumnValue columnType)
|
|
|
|
<$> enumParser @pgKind tableName enumValuesList tableCustomName nullability
|
|
|
|
Nothing -> throw400 ValidationFailed "empty enum values"
|
2022-09-14 00:21:07 +03:00
|
|
|
|
|
|
|
enumParser ::
|
|
|
|
forall pgKind r m n.
|
|
|
|
(MonadBuildSchema ('Postgres pgKind) r m n) =>
|
|
|
|
TableName ('Postgres pgKind) ->
|
|
|
|
NonEmpty (EnumValue, EnumValueInfo) ->
|
|
|
|
Maybe G.Name ->
|
|
|
|
G.Nullability ->
|
|
|
|
SchemaT r m (Parser 'Both n (ScalarValue ('Postgres pgKind)))
|
|
|
|
enumParser tableName enumValues tableCustomName nullability = 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
|
|
|
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
|
|
|
let customization = _siCustomization sourceInfo
|
|
|
|
tCase = _rscNamingConvention customization
|
2022-09-14 00:21:07 +03:00
|
|
|
tableGQLName <- liftEither (getIdentifierQualifiedObject tableName)
|
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 name = addEnumSuffix customization tableGQLName tableCustomName
|
2022-09-14 00:21:07 +03:00
|
|
|
pure $ possiblyNullable PGText nullability $ P.enum name Nothing (mkEnumValue tCase <$> enumValues)
|
2021-02-23 20:37:27 +03:00
|
|
|
where
|
2022-09-14 00:21:07 +03:00
|
|
|
mkEnumValue :: NamingCase -> (EnumValue, EnumValueInfo) -> (P.Definition P.EnumValueInfo, ScalarValue ('Postgres pgKind))
|
2022-05-26 14:54:30 +03:00
|
|
|
mkEnumValue tCase (EnumValue value, EnumValueInfo description) =
|
2022-07-25 18:53:25 +03:00
|
|
|
( P.Definition (applyEnumValueCase tCase value) (G.Description <$> description) Nothing [] P.EnumValueInfo,
|
2021-09-24 01:56:37 +03:00
|
|
|
PGValText $ G.unName value
|
2021-02-23 20:37:27 +03:00
|
|
|
)
|
|
|
|
|
2022-09-14 00:21:07 +03:00
|
|
|
possiblyNullable ::
|
|
|
|
(MonadParse m, 'Input <: k) =>
|
|
|
|
ScalarType ('Postgres pgKind) ->
|
|
|
|
G.Nullability ->
|
|
|
|
Parser k m (ScalarValue ('Postgres pgKind)) ->
|
|
|
|
Parser k m (ScalarValue ('Postgres pgKind))
|
|
|
|
possiblyNullable scalarType (G.Nullability isNullable)
|
|
|
|
| isNullable = fmap (fromMaybe $ PGNull scalarType) . P.nullable
|
|
|
|
| otherwise = id
|
|
|
|
|
2022-05-03 11:58:56 +03:00
|
|
|
pgScalarSelectionArgumentsParser ::
|
2021-09-24 01:56:37 +03:00
|
|
|
MonadParse n =>
|
|
|
|
ColumnType ('Postgres pgKind) ->
|
2022-05-03 11:58:56 +03:00
|
|
|
InputFieldsParser n (Maybe (ScalarSelectionArguments ('Postgres pgKind)))
|
|
|
|
pgScalarSelectionArgumentsParser columnType
|
2022-09-21 14:34:39 +03:00
|
|
|
| isScalarColumnWhere Postgres.isJSONType columnType =
|
2022-11-02 23:53:23 +03:00
|
|
|
P.fieldOptional fieldName description P.string `P.bindFields` fmap join . traverse toColExp
|
2021-02-23 20:37:27 +03:00
|
|
|
| otherwise = pure Nothing
|
|
|
|
where
|
2022-06-23 12:14:24 +03:00
|
|
|
fieldName = Name._path
|
2021-02-23 20:37:27 +03:00
|
|
|
description = Just "JSON select path"
|
|
|
|
toColExp textValue = case parseJSONPath textValue of
|
An `ErrorMessage` type, to encapsulate.
This introduces an `ErrorMessage` newtype which wraps `Text` in a manner which is designed to be easy to construct, and difficult to deconstruct.
It provides functionality similar to `Data.Text.Extended`, but designed _only_ for error messages. Error messages are constructed through `fromString`, concatenation, or the `toErrorValue` function, which is designed to be overridden for all meaningful domain types that might show up in an error message. Notably, there are not and should never be instances of `ToErrorValue` for `String`, `Text`, `Int`, etc. This is so that we correctly represent the value in a way that is specific to its type. For example, all `Name` values (from the _graphql-parser-hs_ library) are single-quoted now; no exceptions.
I have mostly had to add `instance ToErrorValue` for various backend types (and also add newtypes where necessary). Some of these are not strictly necessary for this changeset, as I had bigger aspirations when I started. These aspirations have been tempered by trying and failing twice.
As such, in this changeset, I have started by introducing this type to the `parseError` and `parseErrorWith` functions. In the future, I would like to extend this to the `QErr` record and the various `throwError` functions, but this is a much larger task and should probably be done in stages.
For now, `toErrorMessage` and `fromErrorMessage` are provided for conversion to and from `Text`, but the intent is to stop exporting these once all error messages are converted to the new type.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5018
GitOrigin-RevId: 84b37e238992e4312255a87ca44f41af65e2d89a
2022-07-18 23:26:01 +03:00
|
|
|
Left err -> P.parseError $ "parse json path error: " <> toErrorMessage err
|
2021-09-24 01:56:37 +03:00
|
|
|
Right [] -> pure Nothing
|
2022-09-21 14:34:39 +03:00
|
|
|
Right jPaths -> pure $ Just $ Postgres.ColumnOp Postgres.jsonbPathOp $ Postgres.SEArray $ map elToColExp jPaths
|
|
|
|
elToColExp (Key k) = Postgres.SELit $ K.toText k
|
|
|
|
elToColExp (Index i) = Postgres.SELit $ tshow i
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2022-05-26 14:54:30 +03:00
|
|
|
orderByOperatorsHasuraCase ::
|
2022-06-10 06:59:00 +03:00
|
|
|
(G.Name, NonEmpty (Definition P.EnumValueInfo, (BasicOrderType ('Postgres pgKind), NullsOrderType ('Postgres pgKind))))
|
2022-05-26 14:54:30 +03:00
|
|
|
orderByOperatorsHasuraCase = orderByOperators HasuraCase
|
|
|
|
|
|
|
|
orderByOperatorsGraphqlCase ::
|
2022-06-10 06:59:00 +03:00
|
|
|
(G.Name, NonEmpty (Definition P.EnumValueInfo, (BasicOrderType ('Postgres pgKind), NullsOrderType ('Postgres pgKind))))
|
2022-05-26 14:54:30 +03:00
|
|
|
orderByOperatorsGraphqlCase = orderByOperators GraphqlCase
|
|
|
|
|
|
|
|
-- | Do NOT use this function directly, this should be used via
|
|
|
|
-- @orderByOperatorsHasuraCase@ or @orderByOperatorsGraphqlCase@
|
2021-09-24 01:56:37 +03:00
|
|
|
orderByOperators ::
|
2022-05-26 14:54:30 +03:00
|
|
|
NamingCase ->
|
2022-06-10 06:59:00 +03:00
|
|
|
(G.Name, NonEmpty (Definition P.EnumValueInfo, (BasicOrderType ('Postgres pgKind), NullsOrderType ('Postgres pgKind))))
|
2022-05-26 14:54:30 +03:00
|
|
|
orderByOperators tCase =
|
2022-06-23 12:14:24 +03:00
|
|
|
(Name._order_by,) $
|
2022-06-10 06:59:00 +03:00
|
|
|
NE.fromList
|
2022-07-04 08:40:16 +03:00
|
|
|
[ ( define (applyEnumValueCase tCase Name._asc) "in ascending order, nulls last",
|
2022-09-21 14:34:39 +03:00
|
|
|
(Postgres.OTAsc, Postgres.NullsLast)
|
2022-06-10 06:59:00 +03:00
|
|
|
),
|
2022-07-04 08:40:16 +03:00
|
|
|
( define (applyEnumValueCase tCase Name._asc_nulls_first) "in ascending order, nulls first",
|
2022-09-21 14:34:39 +03:00
|
|
|
(Postgres.OTAsc, Postgres.NullsFirst)
|
2022-06-10 06:59:00 +03:00
|
|
|
),
|
2022-07-04 08:40:16 +03:00
|
|
|
( define (applyEnumValueCase tCase Name._asc_nulls_last) "in ascending order, nulls last",
|
2022-09-21 14:34:39 +03:00
|
|
|
(Postgres.OTAsc, Postgres.NullsLast)
|
2022-06-10 06:59:00 +03:00
|
|
|
),
|
2022-07-04 08:40:16 +03:00
|
|
|
( define (applyEnumValueCase tCase Name._desc) "in descending order, nulls first",
|
2022-09-21 14:34:39 +03:00
|
|
|
(Postgres.OTDesc, Postgres.NullsFirst)
|
2022-06-10 06:59:00 +03:00
|
|
|
),
|
2022-07-04 08:40:16 +03:00
|
|
|
( define (applyEnumValueCase tCase Name._desc_nulls_first) "in descending order, nulls first",
|
2022-09-21 14:34:39 +03:00
|
|
|
(Postgres.OTDesc, Postgres.NullsFirst)
|
2022-06-10 06:59:00 +03:00
|
|
|
),
|
2022-07-04 08:40:16 +03:00
|
|
|
( define (applyEnumValueCase tCase Name._desc_nulls_last) "in descending order, nulls last",
|
2022-09-21 14:34:39 +03:00
|
|
|
(Postgres.OTDesc, Postgres.NullsLast)
|
2022-06-10 06:59:00 +03:00
|
|
|
)
|
|
|
|
]
|
2021-02-23 20:37:27 +03:00
|
|
|
where
|
2022-07-25 18:53:25 +03:00
|
|
|
define name desc = P.Definition name (Just desc) Nothing [] P.EnumValueInfo
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
comparisonExps ::
|
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
2021-09-24 01:56:37 +03:00
|
|
|
ColumnType ('Postgres pgKind) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (Parser 'Input n [ComparisonExp ('Postgres pgKind)])
|
2022-05-31 01:07:02 +03:00
|
|
|
comparisonExps = memoize 'comparisonExps \columnType -> 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
|
|
|
sourceInfo :: SourceInfo ('Postgres pgKind) <- asks getter
|
|
|
|
let customization = _siCustomization sourceInfo
|
|
|
|
tCase = _rscNamingConvention customization
|
|
|
|
|
2021-02-23 20:37:27 +03:00
|
|
|
-- see Note [Columns in comparison expression are never nullable]
|
2022-07-14 20:57:28 +03:00
|
|
|
collapseIfNull <- retrieve Options.soDangerousBooleanCollapse
|
2021-04-08 11:25:11 +03:00
|
|
|
|
|
|
|
-- parsers used for comparison arguments
|
2021-09-24 01:56:37 +03:00
|
|
|
geogInputParser <- geographyWithinDistanceInput
|
|
|
|
geomInputParser <- geometryWithinDistanceInput
|
|
|
|
ignInputParser <- intersectsGeomNbandInput
|
|
|
|
ingInputParser <- intersectsNbandGeomInput
|
|
|
|
typedParser <- columnParser columnType (G.Nullability False)
|
2021-02-23 20:37:27 +03:00
|
|
|
nullableTextParser <- columnParser (ColumnScalar PGText) (G.Nullability True)
|
2021-09-24 01:56:37 +03:00
|
|
|
textParser <- columnParser (ColumnScalar PGText) (G.Nullability False)
|
2021-02-25 14:05:51 +03:00
|
|
|
-- `lquery` represents a regular-expression-like pattern for matching `ltree` values.
|
2021-09-24 01:56:37 +03:00
|
|
|
lqueryParser <- columnParser (ColumnScalar PGLquery) (G.Nullability False)
|
2021-02-25 14:05:51 +03:00
|
|
|
-- `ltxtquery` represents a full-text-search-like pattern for matching `ltree` values.
|
2021-09-24 01:56:37 +03:00
|
|
|
ltxtqueryParser <- columnParser (ColumnScalar PGLtxtquery) (G.Nullability False)
|
2022-07-04 08:40:16 +03:00
|
|
|
maybeCastParser <- castExp columnType tCase
|
2022-06-23 12:14:24 +03:00
|
|
|
let name = applyTypeNameCaseCust tCase $ P.getName typedParser <> Name.__comparison_exp
|
2021-09-24 01:56:37 +03:00
|
|
|
desc =
|
|
|
|
G.Description $
|
|
|
|
"Boolean expression to compare columns of type "
|
|
|
|
<> P.getName typedParser
|
2022-10-18 11:42:38 +03:00
|
|
|
<<> ". All fields are combined with logical 'AND'."
|
2022-05-31 01:07:02 +03:00
|
|
|
textListParser = fmap IR.openValueOrigin <$> P.list textParser
|
|
|
|
columnListParser = fmap IR.openValueOrigin <$> P.list typedParser
|
2022-05-26 14:54:30 +03:00
|
|
|
-- Naming conventions
|
2021-09-24 01:56:37 +03:00
|
|
|
pure $
|
|
|
|
P.object name (Just desc) $
|
|
|
|
fmap catMaybes $
|
|
|
|
sequenceA $
|
|
|
|
concat
|
|
|
|
[ flip (maybe []) maybeCastParser $ \castParser ->
|
2022-06-23 12:14:24 +03:00
|
|
|
[ P.fieldOptional Name.__cast Nothing (ACast <$> castParser)
|
2021-09-24 01:56:37 +03:00
|
|
|
],
|
|
|
|
-- Common ops for all types
|
|
|
|
equalityOperators
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-05-31 01:07:02 +03:00
|
|
|
(IR.mkParameter <$> typedParser)
|
2022-06-29 16:35:59 +03:00
|
|
|
(mkListParameter columnType <$> columnListParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
-- Comparison ops for non Raster types
|
|
|
|
guard (isScalarColumnWhere (/= PGRaster) columnType)
|
|
|
|
*> comparisonOperators
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-05-31 01:07:02 +03:00
|
|
|
(IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
-- Ops for Raster types
|
|
|
|
guard (isScalarColumnWhere (== PGRaster) columnType)
|
|
|
|
*> [ mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "intersects", "rast"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
Nothing
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTIntersectsRast . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "intersects", "nband", "geom"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
Nothing
|
|
|
|
(ABackendSpecific . ASTIntersectsNbandGeom <$> ingInputParser),
|
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "intersects", "geom", "nband"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
Nothing
|
|
|
|
(ABackendSpecific . ASTIntersectsGeomNband <$> ignInputParser)
|
|
|
|
],
|
|
|
|
-- Ops for String like types
|
|
|
|
guard (isScalarColumnWhere isStringType columnType)
|
|
|
|
*> [ mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__like)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column match the given pattern")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ALIKE . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__nlike)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column NOT match the given pattern")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ANLIKE . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__ilike)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column match the given case-insensitive pattern")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AILIKE . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__nilike)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column NOT match the given case-insensitive pattern")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ANILIKE . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__similar)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column match the given SQL regular expression")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASIMILAR . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__nsimilar)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column NOT match the given SQL regular expression")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ANSIMILAR . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__regex)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column match the given POSIX regular expression, case sensitive")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AREGEX . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__iregex)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column match the given POSIX regular expression, case insensitive")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AIREGEX . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__nregex)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column NOT match the given POSIX regular expression, case sensitive")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ANREGEX . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__niregex)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column NOT match the given POSIX regular expression, case insensitive")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ANIREGEX . IR.mkParameter <$> typedParser)
|
2021-09-24 01:56:37 +03:00
|
|
|
],
|
|
|
|
-- Ops for JSONB type
|
|
|
|
guard (isScalarColumnWhere (== PGJSONB) columnType)
|
|
|
|
*> [ mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__contains)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column contain the given json value at the top level")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AContains . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_contained", "in"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "is the column contained in the given json value")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AContainedIn . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_has", "key"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the string exist as a top-level key in the column")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AHasKey . IR.mkParameter <$> nullableTextParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_has", "keys", "any"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "do any of these strings exist as top-level keys in the column")
|
|
|
|
(ABackendSpecific . AHasKeysAny . mkListLiteral (ColumnScalar PGText) <$> textListParser),
|
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_has", "keys", "all"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "do all of these strings exist as top-level keys in the column")
|
|
|
|
(ABackendSpecific . AHasKeysAll . mkListLiteral (ColumnScalar PGText) <$> textListParser)
|
|
|
|
],
|
|
|
|
-- Ops for Geography type
|
|
|
|
guard (isScalarColumnWhere (== PGGeography) columnType)
|
|
|
|
*> [ mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "intersects"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column spatially intersect the given geography value")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTIntersects . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "d", "within"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "is the column within a given distance from the given geography value")
|
|
|
|
(ABackendSpecific . ASTDWithinGeog <$> geogInputParser)
|
|
|
|
],
|
|
|
|
-- Ops for Geometry type
|
|
|
|
guard (isScalarColumnWhere (== PGGeometry) columnType)
|
|
|
|
*> [ mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "contains"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column contain the given geometry value")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTContains . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "crosses"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column cross the given geometry value")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTCrosses . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "equals"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "is the column equal to given geometry value (directionality is ignored)")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTEquals . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "overlaps"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column 'spatially overlap' (intersect but not completely contain) the given geometry value")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTOverlaps . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "touches"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column have atleast one point in common with the given geometry value")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTTouches . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "within"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "is the column contained in the given geometry value")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTWithin . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "intersects"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column spatially intersect the given geometry value")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ASTIntersects . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "3d", "intersects"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does the column spatially intersect the given geometry value in 3D")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AST3DIntersects . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "d", "within"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "is the column within a given distance from the given geometry value")
|
|
|
|
(ABackendSpecific . ASTDWithinGeom <$> geomInputParser),
|
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_st", "3d", "d", "within"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "is the column within a given 3D distance from the given geometry value")
|
|
|
|
(ABackendSpecific . AST3DDWithinGeom <$> geomInputParser)
|
|
|
|
],
|
|
|
|
-- Ops for Ltree type
|
|
|
|
guard (isScalarColumnWhere (== PGLtree) columnType)
|
|
|
|
*> [ mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__ancestor)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "is the left argument an ancestor of right (or equal)?")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AAncestor . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_ancestor", "any"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does array contain an ancestor of `ltree`?")
|
|
|
|
(ABackendSpecific . AAncestorAny . mkListLiteral columnType <$> columnListParser),
|
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__descendant)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "is the left argument a descendant of right (or equal)?")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . ADescendant . IR.mkParameter <$> typedParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_descendant", "any"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does array contain a descendant of `ltree`?")
|
|
|
|
(ABackendSpecific . ADescendantAny . mkListLiteral columnType <$> columnListParser),
|
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName Name.__matches)
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does `ltree` match `lquery`?")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AMatches . IR.mkParameter <$> lqueryParser),
|
2021-09-24 01:56:37 +03:00
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_matches", "any"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does `ltree` match any `lquery` in array?")
|
|
|
|
(ABackendSpecific . AMatchesAny . mkListLiteral (ColumnScalar PGLquery) <$> textListParser),
|
|
|
|
mkBoolOperator
|
2022-05-26 14:54:30 +03:00
|
|
|
tCase
|
2021-09-24 01:56:37 +03:00
|
|
|
collapseIfNull
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_matches", "fulltext"]))
|
2021-09-24 01:56:37 +03:00
|
|
|
(Just "does `ltree` match `ltxtquery`?")
|
2022-05-31 01:07:02 +03:00
|
|
|
(ABackendSpecific . AMatchesFulltext . IR.mkParameter <$> ltxtqueryParser)
|
2021-09-24 01:56:37 +03:00
|
|
|
]
|
|
|
|
]
|
2021-02-23 20:37:27 +03:00
|
|
|
where
|
2022-05-31 01:07:02 +03:00
|
|
|
mkListLiteral :: ColumnType ('Postgres pgKind) -> [ColumnValue ('Postgres pgKind)] -> IR.UnpreparedValue ('Postgres pgKind)
|
2021-09-24 01:56:37 +03:00
|
|
|
mkListLiteral columnType columnValues =
|
2022-05-31 01:07:02 +03:00
|
|
|
IR.UVLiteral $
|
2021-09-24 01:56:37 +03:00
|
|
|
SETyAnn
|
|
|
|
(SEArray $ txtEncoder . cvValue <$> columnValues)
|
|
|
|
(mkTypeAnn $ CollectableTypeArray $ unsafePGColumnToBackend columnType)
|
2022-06-29 16:35:59 +03:00
|
|
|
mkListParameter :: ColumnType ('Postgres pgKind) -> [ColumnValue ('Postgres pgKind)] -> IR.UnpreparedValue ('Postgres pgKind)
|
|
|
|
mkListParameter columnType columnValues = do
|
|
|
|
let scalarType = unsafePGColumnToBackend columnType
|
|
|
|
IR.UVParameter Nothing $
|
|
|
|
ColumnValue
|
2022-09-21 14:34:39 +03:00
|
|
|
(ColumnScalar $ Postgres.PGArray scalarType)
|
|
|
|
(Postgres.PGValArray $ cvValue <$> columnValues)
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2022-09-06 19:48:04 +03:00
|
|
|
castExp :: ColumnType ('Postgres pgKind) -> NamingCase -> SchemaT r m (Maybe (Parser 'Input n (CastExp ('Postgres pgKind) (IR.UnpreparedValue ('Postgres pgKind)))))
|
2022-07-04 08:40:16 +03:00
|
|
|
castExp sourceType tCase = do
|
2021-02-23 20:37:27 +03:00
|
|
|
let maybeScalars = case sourceType of
|
|
|
|
ColumnScalar PGGeography -> Just (PGGeography, PGGeometry)
|
2021-09-24 01:56:37 +03:00
|
|
|
ColumnScalar PGGeometry -> Just (PGGeometry, PGGeography)
|
2022-03-10 10:32:04 +03:00
|
|
|
ColumnScalar PGJSONB -> Just (PGJSONB, PGText)
|
2021-09-24 01:56:37 +03:00
|
|
|
_ -> Nothing
|
2021-02-23 20:37:27 +03:00
|
|
|
|
|
|
|
forM maybeScalars $ \(sourceScalar, targetScalar) -> do
|
2022-08-17 15:46:36 +03:00
|
|
|
scalarTypeName <- C.fromAutogeneratedName <$> mkScalarTypeName sourceScalar
|
2021-09-24 01:56:37 +03:00
|
|
|
targetName <- mkScalarTypeName targetScalar
|
2021-02-23 20:37:27 +03:00
|
|
|
targetOpExps <- comparisonExps $ ColumnScalar targetScalar
|
2021-09-24 01:56:37 +03:00
|
|
|
let field = P.fieldOptional targetName Nothing $ (targetScalar,) <$> targetOpExps
|
2022-08-17 15:46:36 +03:00
|
|
|
sourceName = applyTypeNameCaseIdentifier tCase (scalarTypeName <> (C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["cast", "exp"])))
|
Refactor type name customization
Source typename customization (hasura/graphql-engine@aac64f2c81faa6a3aef4d0cf5fae97289ac4383e) introduced a mechanism to change certain names in the GraphQL schema that is exposed. In particular it allows last-minute modification of:
1. the names of some types, and
2. the names of some root fields.
The above two items are assigned distinct customization algorithms, and at times both algorithms are in scope. So a need to distinguish them is needed.
In the original design, this was addressed by introducing a newtype wrapper `Typename` around GraphQL `Name`s, dedicated to the names of types. However, in the majority of the codebase, type names are also represented by `Name`. For this reason, it was unavoidable to allow for easy conversion. This was supported by a `HasName Typename` instance, as well as by publishing the constructors of `Typename`.
This means that the type safety that newtypes can add is lost. In particular, it is now very easy to confuse type name customization with root field name customization.
This refactors the above design by instead introducing newtypes around the customization operations:
```haskell
newtype MkTypename = MkTypename {runMkTypename :: Name -> Name}
deriving (Semigroup, Monoid) via (Endo Name)
newtype MkRootFieldName = MkRootFieldName {runMkRootFieldName :: Name -> Name}
deriving (Semigroup, Monoid) via (Endo Name)
```
The `Monoid` instance allows easy composition of customization operations, piggybacking off of the type of `Endo`maps.
This design allows safe co-existence of the two customization algorithms, while avoiding the syntactic overhead of packing and unpacking newtypes.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2989
GitOrigin-RevId: da3a353a9b003ee40c8d0a1e02872e99d2edd3ca
2021-11-30 12:51:46 +03:00
|
|
|
pure $ P.object sourceName Nothing $ M.fromList . maybeToList <$> field
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
geographyWithinDistanceInput ::
|
2021-10-29 17:42:07 +03:00
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SchemaT r m (Parser 'Input n (DWithinGeogOp (IR.UnpreparedValue ('Postgres pgKind))))
|
2021-02-23 20:37:27 +03:00
|
|
|
geographyWithinDistanceInput = do
|
|
|
|
geographyParser <- columnParser (ColumnScalar PGGeography) (G.Nullability False)
|
|
|
|
-- FIXME
|
|
|
|
-- It doesn't make sense for this value to be nullable; it only is for
|
|
|
|
-- backwards compatibility; if an explicit Null value is given, it will be
|
|
|
|
-- forwarded to the underlying SQL function, that in turns treat a null value
|
|
|
|
-- as an error. We can fix this by rejecting explicit null values, by marking
|
|
|
|
-- this field non-nullable in a future release.
|
2021-09-24 01:56:37 +03:00
|
|
|
booleanParser <- columnParser (ColumnScalar PGBoolean) (G.Nullability True)
|
|
|
|
floatParser <- columnParser (ColumnScalar PGFloat) (G.Nullability False)
|
|
|
|
pure $
|
2022-06-23 12:14:24 +03:00
|
|
|
P.object Name._st_d_within_geography_input Nothing $
|
2022-10-18 11:42:38 +03:00
|
|
|
DWithinGeogOp
|
|
|
|
<$> (IR.mkParameter <$> P.field Name._distance Nothing floatParser)
|
2022-06-23 12:14:24 +03:00
|
|
|
<*> (IR.mkParameter <$> P.field Name._from Nothing geographyParser)
|
|
|
|
<*> (IR.mkParameter <$> P.fieldWithDefault Name._use_spheroid Nothing (G.VBoolean True) booleanParser)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
|
|
|
geometryWithinDistanceInput ::
|
2021-10-29 17:42:07 +03:00
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SchemaT r m (Parser 'Input n (DWithinGeomOp (IR.UnpreparedValue ('Postgres pgKind))))
|
2021-02-23 20:37:27 +03:00
|
|
|
geometryWithinDistanceInput = do
|
|
|
|
geometryParser <- columnParser (ColumnScalar PGGeometry) (G.Nullability False)
|
2021-09-24 01:56:37 +03:00
|
|
|
floatParser <- columnParser (ColumnScalar PGFloat) (G.Nullability False)
|
|
|
|
pure $
|
2022-06-23 12:14:24 +03:00
|
|
|
P.object Name._st_d_within_input Nothing $
|
2022-10-18 11:42:38 +03:00
|
|
|
DWithinGeomOp
|
|
|
|
<$> (IR.mkParameter <$> P.field Name._distance Nothing floatParser)
|
2022-06-23 12:14:24 +03:00
|
|
|
<*> (IR.mkParameter <$> P.field Name._from Nothing geometryParser)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
|
|
|
intersectsNbandGeomInput ::
|
2021-10-29 17:42:07 +03:00
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SchemaT r m (Parser 'Input n (STIntersectsNbandGeommin (IR.UnpreparedValue ('Postgres pgKind))))
|
2021-02-23 20:37:27 +03:00
|
|
|
intersectsNbandGeomInput = do
|
|
|
|
geometryParser <- columnParser (ColumnScalar PGGeometry) (G.Nullability False)
|
2021-09-24 01:56:37 +03:00
|
|
|
integerParser <- columnParser (ColumnScalar PGInteger) (G.Nullability False)
|
|
|
|
pure $
|
2022-06-23 12:14:24 +03:00
|
|
|
P.object Name._st_intersects_nband_geom_input Nothing $
|
2022-10-18 11:42:38 +03:00
|
|
|
STIntersectsNbandGeommin
|
|
|
|
<$> (IR.mkParameter <$> P.field Name._nband Nothing integerParser)
|
2022-06-23 12:14:24 +03:00
|
|
|
<*> (IR.mkParameter <$> P.field Name._geommin Nothing geometryParser)
|
2021-09-24 01:56:37 +03:00
|
|
|
|
|
|
|
intersectsGeomNbandInput ::
|
2021-10-29 17:42:07 +03:00
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SchemaT r m (Parser 'Input n (STIntersectsGeomminNband (IR.UnpreparedValue ('Postgres pgKind))))
|
2021-02-23 20:37:27 +03:00
|
|
|
intersectsGeomNbandInput = do
|
|
|
|
geometryParser <- columnParser (ColumnScalar PGGeometry) (G.Nullability False)
|
2021-09-24 01:56:37 +03:00
|
|
|
integerParser <- columnParser (ColumnScalar PGInteger) (G.Nullability False)
|
|
|
|
pure $
|
2022-06-23 12:14:24 +03:00
|
|
|
P.object Name._st_intersects_geom_nband_input Nothing $
|
2021-09-24 01:56:37 +03:00
|
|
|
STIntersectsGeomminNband
|
2022-06-23 12:14:24 +03:00
|
|
|
<$> (IR.mkParameter <$> P.field Name._geommin Nothing geometryParser)
|
|
|
|
<*> (fmap IR.mkParameter <$> P.fieldOptional Name._nband Nothing integerParser)
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2022-01-18 17:53:44 +03:00
|
|
|
countTypeInput ::
|
|
|
|
MonadParse n =>
|
|
|
|
Maybe (Parser 'Both n (Column ('Postgres pgKind))) ->
|
|
|
|
InputFieldsParser n (IR.CountDistinct -> CountType ('Postgres pgKind))
|
|
|
|
countTypeInput = \case
|
|
|
|
Just columnEnum -> do
|
2022-06-23 12:14:24 +03:00
|
|
|
columns <- P.fieldOptional Name._columns Nothing (P.list columnEnum)
|
2022-01-18 17:53:44 +03:00
|
|
|
pure $ flip mkCountType columns
|
|
|
|
Nothing -> pure $ flip mkCountType Nothing
|
|
|
|
where
|
|
|
|
mkCountType :: IR.CountDistinct -> Maybe [Column ('Postgres pgKind)] -> CountType ('Postgres pgKind)
|
2022-09-21 14:34:39 +03:00
|
|
|
mkCountType _ Nothing = Postgres.CTStar
|
|
|
|
mkCountType IR.SelectCountDistinct (Just cols) = Postgres.CTDistinct cols
|
|
|
|
mkCountType IR.SelectCountNonDistinct (Just cols) = Postgres.CTSimple cols
|
2021-02-23 20:37:27 +03:00
|
|
|
|
2021-11-18 21:02:58 +03:00
|
|
|
-- | Update operator that prepends a value to a column containing jsonb arrays.
|
|
|
|
--
|
|
|
|
-- Note: Currently this is Postgres specific because json columns have not been ported
|
|
|
|
-- to other backends yet.
|
|
|
|
prependOp ::
|
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SU.UpdateOperator ('Postgres pgKind) r m n (IR.UnpreparedValue ('Postgres pgKind))
|
2021-11-26 16:47:12 +03:00
|
|
|
prependOp = SU.UpdateOperator {..}
|
2021-11-18 21:02:58 +03:00
|
|
|
where
|
2022-01-19 11:37:50 +03:00
|
|
|
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
2021-11-18 21:02:58 +03:00
|
|
|
|
2022-04-18 22:43:00 +03:00
|
|
|
updateOperatorParser tableGQLName _tableName columns = do
|
2021-11-18 21:02:58 +03:00
|
|
|
let typedParser columnInfo =
|
2022-05-31 01:07:02 +03:00
|
|
|
fmap IR.mkParameter
|
2021-11-18 21:02:58 +03:00
|
|
|
<$> BS.columnParser
|
2022-01-19 11:37:50 +03:00
|
|
|
(ciType columnInfo)
|
|
|
|
(G.Nullability $ ciIsNullable columnInfo)
|
2021-11-18 21:02:58 +03:00
|
|
|
|
|
|
|
desc = "prepend existing jsonb value of filtered columns with new jsonb value"
|
|
|
|
|
2021-11-26 16:47:12 +03:00
|
|
|
SU.updateOperator
|
2021-11-18 21:02:58 +03:00
|
|
|
tableGQLName
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName $$(G.litName "prepend"))
|
|
|
|
(C.fromAutogeneratedName $$(G.litName "_prepend"))
|
2021-11-18 21:02:58 +03:00
|
|
|
typedParser
|
|
|
|
columns
|
|
|
|
desc
|
|
|
|
desc
|
|
|
|
|
|
|
|
-- | Update operator that appends a value to a column containing jsonb arrays.
|
|
|
|
--
|
|
|
|
-- Note: Currently this is Postgres specific because json columns have not been ported
|
|
|
|
-- to other backends yet.
|
|
|
|
appendOp ::
|
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SU.UpdateOperator ('Postgres pgKind) r m n (IR.UnpreparedValue ('Postgres pgKind))
|
2021-11-26 16:47:12 +03:00
|
|
|
appendOp = SU.UpdateOperator {..}
|
2021-11-18 21:02:58 +03:00
|
|
|
where
|
2022-01-19 11:37:50 +03:00
|
|
|
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
2021-11-18 21:02:58 +03:00
|
|
|
|
2022-04-18 22:43:00 +03:00
|
|
|
updateOperatorParser tableGQLName _tableName columns = do
|
2021-11-18 21:02:58 +03:00
|
|
|
let typedParser columnInfo =
|
2022-05-31 01:07:02 +03:00
|
|
|
fmap IR.mkParameter
|
2021-11-18 21:02:58 +03:00
|
|
|
<$> BS.columnParser
|
2022-01-19 11:37:50 +03:00
|
|
|
(ciType columnInfo)
|
|
|
|
(G.Nullability $ ciIsNullable columnInfo)
|
2021-11-18 21:02:58 +03:00
|
|
|
|
|
|
|
desc = "append existing jsonb value of filtered columns with new jsonb value"
|
2021-11-26 16:47:12 +03:00
|
|
|
SU.updateOperator
|
2021-11-18 21:02:58 +03:00
|
|
|
tableGQLName
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedName $$(G.litName "append"))
|
|
|
|
(C.fromAutogeneratedName $$(G.litName "_append"))
|
2021-11-18 21:02:58 +03:00
|
|
|
typedParser
|
|
|
|
columns
|
|
|
|
desc
|
|
|
|
desc
|
|
|
|
|
|
|
|
-- | Update operator that deletes a value at a specified key from a column
|
|
|
|
-- containing jsonb objects.
|
|
|
|
--
|
|
|
|
-- Note: Currently this is Postgres specific because json columns have not been ported
|
|
|
|
-- to other backends yet.
|
|
|
|
deleteKeyOp ::
|
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SU.UpdateOperator ('Postgres pgKind) r m n (IR.UnpreparedValue ('Postgres pgKind))
|
2021-11-26 16:47:12 +03:00
|
|
|
deleteKeyOp = SU.UpdateOperator {..}
|
2021-11-18 21:02:58 +03:00
|
|
|
where
|
2022-01-19 11:37:50 +03:00
|
|
|
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
2021-11-18 21:02:58 +03:00
|
|
|
|
2022-04-18 22:43:00 +03:00
|
|
|
updateOperatorParser tableGQLName _tableName columns = do
|
2022-09-06 19:48:04 +03:00
|
|
|
let nullableTextParser _ = fmap IR.mkParameter <$> BS.columnParser (ColumnScalar PGText) (G.Nullability True)
|
2021-11-18 21:02:58 +03:00
|
|
|
desc = "delete key/value pair or string element. key/value pairs are matched based on their key value"
|
|
|
|
|
2021-11-26 16:47:12 +03:00
|
|
|
SU.updateOperator
|
2021-11-18 21:02:58 +03:00
|
|
|
tableGQLName
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["delete", "key"]))
|
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_delete", "key"]))
|
2021-11-18 21:02:58 +03:00
|
|
|
nullableTextParser
|
|
|
|
columns
|
|
|
|
desc
|
|
|
|
desc
|
|
|
|
|
|
|
|
-- | Update operator that deletes a value at a specific index from a column
|
|
|
|
-- containing jsonb arrays.
|
|
|
|
--
|
|
|
|
-- Note: Currently this is Postgres specific because json columns have not been ported
|
|
|
|
-- to other backends yet.
|
|
|
|
deleteElemOp ::
|
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SU.UpdateOperator ('Postgres pgKind) r m n (IR.UnpreparedValue ('Postgres pgKind))
|
2021-11-26 16:47:12 +03:00
|
|
|
deleteElemOp = SU.UpdateOperator {..}
|
2021-11-18 21:02:58 +03:00
|
|
|
where
|
2022-01-19 11:37:50 +03:00
|
|
|
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
2021-11-18 21:02:58 +03:00
|
|
|
|
2022-04-18 22:43:00 +03:00
|
|
|
updateOperatorParser tableGQLName _tableName columns = do
|
2022-09-06 19:48:04 +03:00
|
|
|
let nonNullableIntParser _ = fmap IR.mkParameter <$> BS.columnParser (ColumnScalar PGInteger) (G.Nullability False)
|
2021-11-18 21:02:58 +03:00
|
|
|
desc =
|
|
|
|
"delete the array element with specified index (negative integers count from the end). "
|
|
|
|
<> "throws an error if top level container is not an array"
|
|
|
|
|
2021-11-26 16:47:12 +03:00
|
|
|
SU.updateOperator
|
2021-11-18 21:02:58 +03:00
|
|
|
tableGQLName
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["delete", "elem"]))
|
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_delete", "elem"]))
|
2021-11-18 21:02:58 +03:00
|
|
|
nonNullableIntParser
|
|
|
|
columns
|
|
|
|
desc
|
|
|
|
desc
|
|
|
|
|
|
|
|
-- | Update operator that deletes a field at a certan path from a column
|
|
|
|
-- containing jsonb objects.
|
|
|
|
--
|
|
|
|
-- Note: Currently this is Postgres specific because json columns have not been ported
|
|
|
|
-- to other backends yet.
|
|
|
|
deleteAtPathOp ::
|
|
|
|
forall pgKind m n r.
|
2022-09-06 19:48:04 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
|
|
|
SU.UpdateOperator ('Postgres pgKind) r m n [IR.UnpreparedValue ('Postgres pgKind)]
|
2021-11-26 16:47:12 +03:00
|
|
|
deleteAtPathOp = SU.UpdateOperator {..}
|
2021-11-18 21:02:58 +03:00
|
|
|
where
|
2022-01-19 11:37:50 +03:00
|
|
|
updateOperatorApplicableColumn = isScalarColumnWhere (== PGJSONB) . ciType
|
2021-11-18 21:02:58 +03:00
|
|
|
|
2022-04-18 22:43:00 +03:00
|
|
|
updateOperatorParser tableGQLName _tableName columns = do
|
2022-09-06 19:48:04 +03:00
|
|
|
let nonNullableTextListParser _ = P.list . fmap IR.mkParameter <$> BS.columnParser (ColumnScalar PGText) (G.Nullability False)
|
2021-11-18 21:02:58 +03:00
|
|
|
desc = "delete the field or element with specified path (for JSON arrays, negative integers count from the end)"
|
|
|
|
|
2021-11-26 16:47:12 +03:00
|
|
|
SU.updateOperator
|
2021-11-18 21:02:58 +03:00
|
|
|
tableGQLName
|
2022-08-17 15:46:36 +03:00
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["delete", "at", "path"]))
|
|
|
|
(C.fromAutogeneratedTuple $$(G.litGQLIdentifier ["_delete", "at", "path"]))
|
2021-11-18 21:02:58 +03:00
|
|
|
nonNullableTextListParser
|
|
|
|
columns
|
|
|
|
desc
|
|
|
|
desc
|
|
|
|
|
2021-12-29 06:51:01 +03:00
|
|
|
-- | The update operators that we support on Postgres.
|
2023-01-10 04:54:40 +03:00
|
|
|
pgkParseUpdateOperators ::
|
2021-11-18 21:02:58 +03:00
|
|
|
forall pgKind m n r.
|
Role-invariant schema constructors
We build the GraphQL schema by combining building blocks such as `tableSelectionSet` and `columnParser`. These building blocks individually build `{InputFields,Field,}Parser` objects. Those object specify the valid GraphQL schema.
Since the GraphQL schema is role-dependent, at some point we need to know what fragment of the GraphQL schema a specific role is allowed to access, and this is stored in `{Sel,Upd,Ins,Del}PermInfo` objects.
We have passed around these permission objects as function arguments to the schema building blocks since we first started dealing with permissions during the PDV refactor - see hasura/graphql-engine@5168b99e463199b1934d8645bd6cd37eddb64ae1 in hasura/graphql-engine#4111. This means that, for instance, `tableSelectionSet` has as its type:
```haskell
tableSelectionSet ::
forall b r m n.
MonadBuildSchema b r m n =>
SourceName ->
TableInfo b ->
SelPermInfo b ->
m (Parser 'Output n (AnnotatedFields b))
```
There are three reasons to change this.
1. We often pass a `Maybe (xPermInfo b)` instead of a proper `xPermInfo b`, and it's not clear what the intended semantics of this is. Some potential improvements on the data types involved are discussed in issue hasura/graphql-engine-mono#3125.
2. In most cases we also already pass a `TableInfo b`, and together with the `MonadRole` that is usually also in scope, this means that we could look up the required permissions regardless: so passing the permissions explicitly undermines the "single source of truth" principle. Breaking this principle also makes the code more difficult to read.
3. We are working towards role-based parsers (see hasura/graphql-engine-mono#2711), where the `{InputFields,Field,}Parser` objects are constructed in a role-invariant way, so that we have a single object that can be used for all roles. In particular, this means that the schema building blocks _need_ to be constructed in a role-invariant way. While this PR doesn't accomplish that, it does reduce the amount of role-specific arguments being passed, thus fixing hasura/graphql-engine-mono#3068.
Concretely, this PR simply drops the `xPermInfo b` argument from almost all schema building blocks. Instead these objects are looked up from the `TableInfo b` as-needed. The resulting code is considerably simpler and shorter.
One way to interpret this change is as follows. Before this PR, we figured out permissions at the top-level in `Hasura.GraphQL.Schema`, passing down the obtained `xPermInfo` objects as required. After this PR, we have a bottom-up approach where the schema building blocks themselves decide whether they want to be included for a particular role.
So this moves some permission logic out of `Hasura.GraphQL.Schema`, which is very complex.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3608
GitOrigin-RevId: 51a744f34ec7d57bc8077667ae7f9cb9c4f6c962
2022-02-17 11:16:20 +03:00
|
|
|
MonadBuildSchema ('Postgres pgKind) r m n =>
|
2021-11-18 21:02:58 +03:00
|
|
|
TableInfo ('Postgres pgKind) ->
|
|
|
|
UpdPermInfo ('Postgres pgKind) ->
|
2022-09-06 19:48:04 +03:00
|
|
|
SchemaT r m (InputFieldsParser n (HashMap (Column ('Postgres pgKind)) (UpdateOpExpression (IR.UnpreparedValue ('Postgres pgKind)))))
|
2023-01-10 04:54:40 +03:00
|
|
|
pgkParseUpdateOperators tableInfo updatePermissions = do
|
2021-11-26 16:47:12 +03:00
|
|
|
SU.buildUpdateOperators
|
|
|
|
(PGIR.UpdateSet <$> SU.presetColumns updatePermissions)
|
|
|
|
[ PGIR.UpdateSet <$> SU.setOp,
|
|
|
|
PGIR.UpdateInc <$> SU.incOp,
|
2021-11-25 00:39:42 +03:00
|
|
|
PGIR.UpdatePrepend <$> prependOp,
|
|
|
|
PGIR.UpdateAppend <$> appendOp,
|
|
|
|
PGIR.UpdateDeleteKey <$> deleteKeyOp,
|
|
|
|
PGIR.UpdateDeleteElem <$> deleteElemOp,
|
|
|
|
PGIR.UpdateDeleteAtPath <$> deleteAtPathOp
|
2021-11-18 21:02:58 +03:00
|
|
|
]
|
|
|
|
tableInfo
|