2021-12-13 19:48:10 +03:00
{- # LANGUAGE DeriveAnyClass # -}
2022-05-26 17:05:13 +03:00
{- # LANGUAGE DuplicateRecordFields # -}
2020-10-22 23:42:27 +03:00
{- # LANGUAGE UndecidableInstances # -}
2018-12-12 15:58:39 +03:00
2021-09-24 01:56:37 +03:00
-- | This modules defines the tree of Select types: how we represent a query internally, from its top
-- level 'QueryDB' down to each individual field. Most of those types have three type arguments:
--
-- b: BackendType
-- The backend that is targeted by that specific select (Postgres Vanilla, MSSQL...); we use the
-- type families in the Backend class to decide how different parts of the IR are represented in
-- different backends.
--
-- v: Type
-- The type of the leaf values in our AST; used almost exclusively for column values, over which
-- queries can be parameterized. The output of the parser phase will use @UnpreparedValue b@ for
-- the leaves, and most backends will then transform the AST to interpret those values and
-- consequently change @v@ to be @SQLExpression b@
--
-- r: BackendType -> Type
-- Joins across backends mean that the aforementioned @b@ parameter won't be the same throughout
-- the entire tree; at some point we will have an 'AnyBackend' used to encapsulate a branch that
-- uses a different @b@. We still want, however, to be able to parameterize the values of the
-- leaves in that separate branch, and that's what the @r@ parameter is for. We also use
-- 'UnpreparedValue' here during the parsing phase, meaning all leaf values will be
-- @UnpreparedValue b@ for their respective backend @b@, and most backends will then transform
-- their AST, cutting all such remote branches, and therefore using @Const Void@ for @r@.
2021-11-04 19:08:33 +03:00
module Hasura.RQL.IR.Select
2022-03-03 06:43:27 +03:00
( AggregateField ( .. ) ,
2021-11-04 19:08:33 +03:00
AggregateFields ,
AggregateOp ( .. ) ,
AnnAggregateSelect ,
AnnAggregateSelectG ,
AnnColumnField ( .. ) ,
AnnField ,
AnnFieldG ( .. ) ,
AnnFields ,
AnnFieldsG ,
2023-04-11 04:29:05 +03:00
AnnNestedObjectSelectG ( .. ) ,
AnnNestedObjectSelect ,
Nested array support for Data Connectors Backend and MongoDB
## Description
This change adds support for querying into nested arrays in Data Connector agents that support such a concept (currently MongoDB).
### DC API changes
- New API type `ColumnType` which allows representing the type of a "column" as either a scalar type, an object reference or an array of `ColumnType`s. This recursive definition allows arbitrary nesting of arrays of types.
- The `type` fields in the API types `ColumnInfo` and `ColumnInsertSchema` now take a `ColumnType` instead of a `ScalarType`.
- To ensure backwards compatibility, a `ColumnType` representing a scalar serialises and deserialises to the same representation as `ScalarType`.
- In queries, the `Field` type now has a new constructor `NestedArrayField`. This contains a nested `Field` along with optional `limit`, `offset`, `where` and `order_by` arguments. (These optional arguments are not yet used by either HGE or the MongoDB agent.)
### MongoDB Haskell agent changes
- The `/schema` endpoint will now recognise arrays within the JSON validation schema and generate corresponding arrays in the DC schema.
- The `/query` endpoint will now handle `NestedArrayField`s within queries (although it does not yet handle `limit`, `offset`, `where` and `order_by`).
### HGE server changes
- The `Backend` type class adds a new type family `XNestedArrays b` to enable nested arrays on a per-backend basis (currently enabled only for the `DataConnector` backend.
- Within `RawColumnInfo` the column type is now represented by a new type `RawColumnType b` which mirrors the shape of the DC API `ColumnType`, but uses `XNestedObjects b` and `XNestedArrays b` type families to allow turning nested object and array supports on or off for a particular backend. In the `DataConnector` backend `API.CustomType` is converted into `RawColumnInfo 'DataConnector` while building the schema.
- In the next stage of schema building, the `RawColumnInfo` is converted into a `StructuredColumnInfo` which allows us to represent the three different types of columns: scalar, object and array. TODO: the `StructuredColumnInfo` looks very similar to the Logical Model types. The main difference is that it uses the `XNestedObjects` and `XNestedArrays` type families. We should be able to combine these two representations.
- The `StructuredColumnInfo` is then placed into a `FIColumn` `FieldInfo`. This involved some refactoring of `FieldInfo` as I had previously split out `FINestedObject` into a separate constructor. However it works out better to represent all "column" fields (i.e. scalar, object and array) using `FIColumn` as this make it easier to implement permission checking correctly. This is the reason the `StructuredColumnInfo` was needed.
- Next, the `FieldInfo` are used to generate `FieldParser`s. We add a new constructor to `AnnFieldG` for `AFNestedArray`. An `AFNestedArray` field parser can contain either a simple array selection or an array aggregate. Simple array `FieldParsers` are currently limited to subfield selection. We will add support for limit, offset, where and order_by in a future PR. We also don't yet generate array aggregate `FieldParsers.
- The new `AFNestedArray` field is handled by the `QueryPlan` module in the `DataConnector` backend. There we generate an `API.NestedArrayField` from the AFNestedArray. We also handle nested arrays when reshaping the response from the DC agent.
## Limitations
- Support for limit, offset, filter (where) and order_by is not yet fully implemented, although it should not be hard to add this
- Support for aggregations on nested arrays is not yet fully implemented
- Permissions involving nested arrays (and objects) not yet implemented
- This should be integrated with Logical Model types, but that will happen in a separate PR
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9149
GitOrigin-RevId: 0e7b71a994fc1d2ca1ef73bfe7b96e95b5328531
2023-05-24 11:00:59 +03:00
AnnNestedArraySelectG ( .. ) ,
AnnNestedArraySelect ,
2021-11-04 19:08:33 +03:00
AnnObjectSelect ,
AnnObjectSelectG ( .. ) ,
AnnSimpleSelect ,
AnnSimpleSelectG ,
2022-04-07 17:41:43 +03:00
AnnSimpleStreamSelect ,
AnnSimpleStreamSelectG ,
2021-11-04 19:08:33 +03:00
ArrayAggregateSelect ,
ArrayAggregateSelectG ,
ArrayConnectionSelect ,
ArrayRelationSelectG ,
ArraySelect ,
ArraySelectFieldsG ,
ArraySelectG ( .. ) ,
2023-05-23 17:46:27 +03:00
SelectionField ( .. ) ,
SelectionFields ,
2021-11-04 19:08:33 +03:00
ComputedFieldScalarSelect ( .. ) ,
ComputedFieldSelect ( .. ) ,
ConnectionField ( .. ) ,
ConnectionFields ,
ConnectionSelect ( .. ) ,
ConnectionSlice ( .. ) ,
ConnectionSplit ( .. ) ,
ConnectionSplitKind ( .. ) ,
EdgeField ( .. ) ,
EdgeFields ,
ObjectRelationSelect ,
ObjectRelationSelectG ,
PageInfoField ( .. ) ,
PageInfoFields ,
QueryDB ( .. ) ,
RemoteSourceSelect ( .. ) ,
2021-12-07 16:12:02 +03:00
RemoteRelationshipSelect ( .. ) ,
2021-11-04 19:08:33 +03:00
SourceRelationshipSelection ( .. ) ,
TableAggregateField ,
TableAggregateFieldG ( .. ) ,
TableAggregateFields ,
TableAggregateFieldsG ,
2023-06-19 08:04:54 +03:00
GroupByG ( .. ) ,
GroupByField ( .. ) ,
GroupKeyField ( .. ) ,
2022-01-18 17:53:44 +03:00
CountDistinct ( .. ) ,
2021-11-04 19:08:33 +03:00
insertFunctionArg ,
mkAnnColumnField ,
mkAnnColumnFieldAsText ,
2022-04-06 10:18:59 +03:00
traverseSourceRelationshipSelection ,
2023-04-17 18:19:37 +03:00
module Hasura.RQL.IR.Select.AnnSelectG ,
module Hasura.RQL.IR.Select.Args ,
module Hasura.RQL.IR.Select.From ,
module Hasura.RQL.IR.Select.OrderBy ,
module Hasura.RQL.IR.Select.TablePerm ,
module Hasura.RQL.IR.Select.RelationSelect ,
2021-11-04 19:08:33 +03:00
)
where
2018-12-12 15:58:39 +03:00
2022-03-08 11:22:20 +03:00
import Data.Bifoldable
2023-04-26 18:42:13 +03:00
import Data.HashMap.Strict qualified as HashMap
2021-09-24 01:56:37 +03:00
import Data.Kind ( Type )
import Data.List.NonEmpty qualified as NE
import Data.Sequence qualified as Seq
2023-04-03 13:18:54 +03:00
import Hasura.Function.Cache
2021-09-24 01:56:37 +03:00
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp
import Hasura.RQL.IR.OrderBy
2023-04-17 18:19:37 +03:00
import Hasura.RQL.IR.Select.AnnSelectG
import Hasura.RQL.IR.Select.Args
import Hasura.RQL.IR.Select.From
import Hasura.RQL.IR.Select.OrderBy
import Hasura.RQL.IR.Select.RelationSelect
import Hasura.RQL.IR.Select.TablePerm
2021-09-24 01:56:37 +03:00
import Hasura.RQL.Types.Backend
2023-04-24 21:35:48 +03:00
import Hasura.RQL.Types.BackendType
2021-09-24 01:56:37 +03:00
import Hasura.RQL.Types.Column
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.ComputedField
import Hasura.RQL.Types.Instances ( )
2021-12-22 02:14:56 +03:00
import Hasura.RQL.Types.Relationships.Remote
2023-04-24 18:17:15 +03:00
import Hasura.RQL.Types.Schema.Options ( StringifyNumbers )
2020-11-02 14:50:40 +03:00
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
-- Root selection
2019-04-17 12:48:41 +03:00
2021-12-07 16:12:02 +03:00
data QueryDB ( b :: BackendType ) ( r :: Type ) v
2021-09-24 01:56:37 +03:00
= QDBMultipleRows ( AnnSimpleSelectG b r v )
| QDBSingleRow ( AnnSimpleSelectG b r v )
| QDBAggregation ( AnnAggregateSelectG b r v )
| QDBConnection ( ConnectionSelect b r v )
2022-04-07 17:41:43 +03:00
| QDBStreamMultipleRows ( AnnSimpleStreamSelectG b r v )
2021-07-08 18:41:59 +03:00
deriving stock ( Generic , Functor , Foldable , Traversable )
2020-06-08 15:13:01 +03:00
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( QueryDB b ) where
2022-03-08 11:22:20 +03:00
bifoldMap f g = \ case
QDBMultipleRows annSel -> bifoldMapAnnSelectG f g annSel
QDBSingleRow annSel -> bifoldMapAnnSelectG f g annSel
QDBAggregation annSel -> bifoldMapAnnSelectG f g annSel
QDBConnection connSel -> bifoldMap f g connSel
2022-04-07 17:41:43 +03:00
QDBStreamMultipleRows annSel -> bifoldMapAnnSelectStreamG f g annSel
2022-03-08 11:22:20 +03:00
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
-- Select
2018-12-12 15:58:39 +03:00
2022-03-08 11:22:20 +03:00
type AnnSimpleSelectG b r v = AnnSelectG b ( AnnFieldG b r ) v
2021-09-22 13:43:05 +03:00
2022-03-08 11:22:20 +03:00
type AnnAggregateSelectG b r v = AnnSelectG b ( TableAggregateFieldG b r ) v
2020-06-25 06:33:37 +03:00
2022-04-07 17:41:43 +03:00
type AnnSimpleStreamSelectG b r v = AnnSelectStreamG b ( AnnFieldG b r ) v
2021-12-07 16:12:02 +03:00
type AnnSimpleSelect b = AnnSimpleSelectG b Void ( SQLExpression b )
2021-09-24 01:56:37 +03:00
2021-12-07 16:12:02 +03:00
type AnnAggregateSelect b = AnnAggregateSelectG b Void ( SQLExpression b )
2020-06-08 15:13:01 +03:00
2022-04-07 17:41:43 +03:00
type AnnSimpleStreamSelect b = AnnSimpleStreamSelectG b Void ( SQLExpression b )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
-- Relay select
2020-06-08 15:13:01 +03:00
2021-12-07 16:12:02 +03:00
data ConnectionSelect ( b :: BackendType ) ( r :: Type ) v = ConnectionSelect
2022-02-25 23:37:32 +03:00
{ _csXRelay :: XRelay b ,
_csPrimaryKeyColumns :: PrimaryKeyColumns b ,
_csSplit :: Maybe ( NE . NonEmpty ( ConnectionSplit b v ) ) ,
_csSlice :: Maybe ConnectionSlice ,
2022-03-08 11:22:20 +03:00
_csSelect :: ( AnnSelectG b ( ConnectionField b r ) v )
2021-09-24 01:56:37 +03:00
}
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
2021-05-21 05:46:58 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Eq ( AnnSelectG b ( ConnectionField b r ) v ) ,
Eq ( ConnectionSlice ) ,
Eq ( ConnectionSplit b v ) ,
Eq ( PrimaryKeyColumns b )
2021-09-24 01:56:37 +03:00
) =>
Eq ( ConnectionSelect b r v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Show ( AnnSelectG b ( ConnectionField b r ) v ) ,
Show ( ConnectionSlice ) ,
Show ( ConnectionSplit b v ) ,
Show ( PrimaryKeyColumns b )
2021-09-24 01:56:37 +03:00
) =>
Show ( ConnectionSelect b r v )
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( ConnectionSelect b ) where
2022-03-08 11:22:20 +03:00
bifoldMap f g ConnectionSelect { .. } =
foldMap ( foldMap $ foldMap g ) _csSplit
<> bifoldMapAnnSelectG f g _csSelect
2021-09-24 01:56:37 +03:00
data ConnectionSplit ( b :: BackendType ) v = ConnectionSplit
2022-02-23 23:17:58 +03:00
{ _csKind :: ConnectionSplitKind ,
_csValue :: v ,
_csOrderBy :: ( OrderByItemG b ( AnnotatedOrderByElement b v ) )
2021-09-24 01:56:37 +03:00
}
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Generic , Foldable , Traversable )
2021-09-22 13:43:05 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
Eq v ,
2022-08-11 19:31:34 +03:00
Eq ( OrderByItemG b ( AnnotatedOrderByElement b v ) )
2021-09-24 01:56:37 +03:00
) =>
Eq ( ConnectionSplit b v )
2021-09-22 13:43:05 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
Show v ,
2022-08-11 19:31:34 +03:00
Show ( OrderByItemG b ( AnnotatedOrderByElement b v ) )
2021-09-24 01:56:37 +03:00
) =>
Show ( ConnectionSplit b v )
2021-09-22 13:43:05 +03:00
instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Hashable v ,
Hashable ( OrderByItemG b ( AnnotatedOrderByElement b v ) )
2021-09-24 01:56:37 +03:00
) =>
Hashable ( ConnectionSplit b v )
2019-03-25 16:45:35 +03:00
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
data ConnectionSlice
2022-02-23 23:17:58 +03:00
= SliceFirst Int
| SliceLast Int
2021-12-13 19:48:10 +03:00
deriving stock ( Show , Eq , Generic )
deriving anyclass ( Hashable )
[Preview] Inherited roles for postgres read queries
fixes #3868
docker image - `hasura/graphql-engine:inherited-roles-preview-48b73a2de`
Note:
To be able to use the inherited roles feature, the graphql-engine should be started with the env variable `HASURA_GRAPHQL_EXPERIMENTAL_FEATURES` set to `inherited_roles`.
Introduction
------------
This PR implements the idea of multiple roles as presented in this [paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/FGALanguageICDE07.pdf). The multiple roles feature in this PR can be used via inherited roles. An inherited role is a role which can be created by combining multiple singular roles. For example, if there are two roles `author` and `editor` configured in the graphql-engine, then we can create a inherited role with the name of `combined_author_editor` role which will combine the select permissions of the `author` and `editor` roles and then make GraphQL queries using the `combined_author_editor`.
How are select permissions of different roles are combined?
------------------------------------------------------------
A select permission includes 5 things:
1. Columns accessible to the role
2. Row selection filter
3. Limit
4. Allow aggregation
5. Scalar computed fields accessible to the role
Suppose there are two roles, `role1` gives access to the `address` column with row filter `P1` and `role2` gives access to both the `address` and the `phone` column with row filter `P2` and we create a new role `combined_roles` which combines `role1` and `role2`.
Let's say the following GraphQL query is queried with the `combined_roles` role.
```graphql
query {
employees {
address
phone
}
}
```
This will translate to the following SQL query:
```sql
select
(case when (P1 or P2) then address else null end) as address,
(case when P2 then phone else null end) as phone
from employee
where (P1 or P2)
```
The other parameters of the select permission will be combined in the following manner:
1. Limit - Minimum of the limits will be the limit of the inherited role
2. Allow aggregations - If any of the role allows aggregation, then the inherited role will allow aggregation
3. Scalar computed fields - same as table column fields, as in the above example
APIs for inherited roles:
----------------------
1. `add_inherited_role`
`add_inherited_role` is the [metadata API](https://hasura.io/docs/1.0/graphql/core/api-reference/index.html#schema-metadata-api) to create a new inherited role. It accepts two arguments
`role_name`: the name of the inherited role to be added (String)
`role_set`: list of roles that need to be combined (Array of Strings)
Example:
```json
{
"type": "add_inherited_role",
"args": {
"role_name":"combined_user",
"role_set":[
"user",
"user1"
]
}
}
```
After adding the inherited role, the inherited role can be used like single roles like earlier
Note:
An inherited role can only be created with non-inherited/singular roles.
2. `drop_inherited_role`
The `drop_inherited_role` API accepts the name of the inherited role and drops it from the metadata. It accepts a single argument:
`role_name`: name of the inherited role to be dropped
Example:
```json
{
"type": "drop_inherited_role",
"args": {
"role_name":"combined_user"
}
}
```
Metadata
---------
The derived roles metadata will be included under the `experimental_features` key while exporting the metadata.
```json
{
"experimental_features": {
"derived_roles": [
{
"role_name": "manager_is_employee_too",
"role_set": [
"employee",
"manager"
]
}
]
}
}
```
Scope
------
Only postgres queries and subscriptions are supported in this PR.
Important points:
-----------------
1. All columns exposed to an inherited role will be marked as `nullable`, this is done so that cell value nullification can be done.
TODOs
-------
- [ ] Tests
- [ ] Test a GraphQL query running with a inherited role without enabling inherited roles in experimental features
- [] Tests for aggregate queries, limit, computed fields, functions, subscriptions (?)
- [ ] Introspection test with a inherited role (nullability changes in a inherited role)
- [ ] Docs
- [ ] Changelog
Co-authored-by: Vamshi Surabhi <6562944+0x777@users.noreply.github.com>
GitOrigin-RevId: 3b8ee1e11f5ceca80fe294f8c074d42fbccfec63
2021-03-08 14:14:13 +03:00
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
data ConnectionSplitKind
= CSKBefore
| CSKAfter
2021-12-13 19:48:10 +03:00
deriving stock ( Show , Eq , Generic )
deriving anyclass ( Hashable )
2020-10-22 23:42:27 +03:00
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
-- Fields
2021-12-07 16:12:02 +03:00
-- | captures a remote relationship's selection and the necessary context
data RemoteRelationshipSelect b r = RemoteRelationshipSelect
{ -- | The fields on the table that are required for the join condition
-- of the remote relationship
_rrsLHSJoinFields :: HashMap FieldName ( DBJoinField b ) ,
-- | The field that captures the relationship
-- r ~ (RemoteRelationshipField UnpreparedValue) when the AST is emitted by the parser.
-- r ~ Void when an execution tree is constructed so that a backend is
-- absolved of dealing with remote relationships.
_rrsRelationship :: r
}
deriving ( Eq , Show , Functor , Foldable , Traversable )
data AnnFieldG ( b :: BackendType ) ( r :: Type ) v
2022-02-23 23:17:58 +03:00
= AFColumn ( AnnColumnField b v )
| AFObjectRelation ( ObjectRelationSelectG b r v )
| AFArrayRelation ( ArraySelectG b r v )
Clean Relay's code, break schema cycles, introduce Node ID V2
## Motivation
This PR rewrites most of Relay to achieve the following:
- ~~fix a bug in which the same node id could refer to two different tables in the schema~~
- remove one of the few remaining uses of the source cache in the schema building code
In doing so, it also:
- simplifies the `BackendSchema` class by removing `node` from it,
- makes it much easier for other backends to support Relay,
- documents, re-organizes, and clarifies the code.
## Description
This PR introduces a new `NodeId` version ~~, and adapts the Postgres code to always generate this V2 version~~. This new id contains the source name, in addition to the table name, in order to disambiguate similar table names across different sources (which is now possible with source customization). In doing so, it now explicitly handles that case for V1 node ids, and returns an explicit error message instead of running the risk of _silently returning the wrong information_.
Furthermore, it adapts `nodeField` to support multiple backends; most of the code was trivial to generalize, and as a result it lowers the cost of entry for other backends, that now only need to support `AFNodeId` in their translation layer.
Finally, it removes one more cycle in the schema building code, by using the same trick we used for remote relationships instead of using the memoization trick of #4576.
## Remaining work
- ~~[ ]write a Changelog entry~~
- ~~[x] adapt all tests that were asserting on an old node id~~
## Future work
This PR was adapted from its original form to avoid a breaking change: while it introduces a Node ID V2, we keep generating V1 IDs and the parser rejects V2 IDs. It will be easy to make the switch at a later data in a subsequent PR.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4593
GitOrigin-RevId: 88e5cb91e8b0646900547fa8c7c0e1463de267a1
2022-06-07 16:35:26 +03:00
| AFComputedField ( XComputedField b ) ComputedFieldName ( ComputedFieldSelect b r v )
2021-12-07 16:12:02 +03:00
| -- | A remote relationship field
2022-02-23 23:17:58 +03:00
AFRemote ( RemoteRelationshipSelect b r )
Clean Relay's code, break schema cycles, introduce Node ID V2
## Motivation
This PR rewrites most of Relay to achieve the following:
- ~~fix a bug in which the same node id could refer to two different tables in the schema~~
- remove one of the few remaining uses of the source cache in the schema building code
In doing so, it also:
- simplifies the `BackendSchema` class by removing `node` from it,
- makes it much easier for other backends to support Relay,
- documents, re-organizes, and clarifies the code.
## Description
This PR introduces a new `NodeId` version ~~, and adapts the Postgres code to always generate this V2 version~~. This new id contains the source name, in addition to the table name, in order to disambiguate similar table names across different sources (which is now possible with source customization). In doing so, it now explicitly handles that case for V1 node ids, and returns an explicit error message instead of running the risk of _silently returning the wrong information_.
Furthermore, it adapts `nodeField` to support multiple backends; most of the code was trivial to generalize, and as a result it lowers the cost of entry for other backends, that now only need to support `AFNodeId` in their translation layer.
Finally, it removes one more cycle in the schema building code, by using the same trick we used for remote relationships instead of using the memoization trick of #4576.
## Remaining work
- ~~[ ]write a Changelog entry~~
- ~~[x] adapt all tests that were asserting on an old node id~~
## Future work
This PR was adapted from its original form to avoid a breaking change: while it introduces a Node ID V2, we keep generating V1 IDs and the parser rejects V2 IDs. It will be easy to make the switch at a later data in a subsequent PR.
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4593
GitOrigin-RevId: 88e5cb91e8b0646900547fa8c7c0e1463de267a1
2022-06-07 16:35:26 +03:00
| AFNodeId ( XRelay b ) SourceName ( TableName b ) ( PrimaryKeyColumns b )
2022-02-23 23:17:58 +03:00
| AFExpression Text
2023-04-11 04:29:05 +03:00
| -- | Nested object.
Nested array support for Data Connectors Backend and MongoDB
## Description
This change adds support for querying into nested arrays in Data Connector agents that support such a concept (currently MongoDB).
### DC API changes
- New API type `ColumnType` which allows representing the type of a "column" as either a scalar type, an object reference or an array of `ColumnType`s. This recursive definition allows arbitrary nesting of arrays of types.
- The `type` fields in the API types `ColumnInfo` and `ColumnInsertSchema` now take a `ColumnType` instead of a `ScalarType`.
- To ensure backwards compatibility, a `ColumnType` representing a scalar serialises and deserialises to the same representation as `ScalarType`.
- In queries, the `Field` type now has a new constructor `NestedArrayField`. This contains a nested `Field` along with optional `limit`, `offset`, `where` and `order_by` arguments. (These optional arguments are not yet used by either HGE or the MongoDB agent.)
### MongoDB Haskell agent changes
- The `/schema` endpoint will now recognise arrays within the JSON validation schema and generate corresponding arrays in the DC schema.
- The `/query` endpoint will now handle `NestedArrayField`s within queries (although it does not yet handle `limit`, `offset`, `where` and `order_by`).
### HGE server changes
- The `Backend` type class adds a new type family `XNestedArrays b` to enable nested arrays on a per-backend basis (currently enabled only for the `DataConnector` backend.
- Within `RawColumnInfo` the column type is now represented by a new type `RawColumnType b` which mirrors the shape of the DC API `ColumnType`, but uses `XNestedObjects b` and `XNestedArrays b` type families to allow turning nested object and array supports on or off for a particular backend. In the `DataConnector` backend `API.CustomType` is converted into `RawColumnInfo 'DataConnector` while building the schema.
- In the next stage of schema building, the `RawColumnInfo` is converted into a `StructuredColumnInfo` which allows us to represent the three different types of columns: scalar, object and array. TODO: the `StructuredColumnInfo` looks very similar to the Logical Model types. The main difference is that it uses the `XNestedObjects` and `XNestedArrays` type families. We should be able to combine these two representations.
- The `StructuredColumnInfo` is then placed into a `FIColumn` `FieldInfo`. This involved some refactoring of `FieldInfo` as I had previously split out `FINestedObject` into a separate constructor. However it works out better to represent all "column" fields (i.e. scalar, object and array) using `FIColumn` as this make it easier to implement permission checking correctly. This is the reason the `StructuredColumnInfo` was needed.
- Next, the `FieldInfo` are used to generate `FieldParser`s. We add a new constructor to `AnnFieldG` for `AFNestedArray`. An `AFNestedArray` field parser can contain either a simple array selection or an array aggregate. Simple array `FieldParsers` are currently limited to subfield selection. We will add support for limit, offset, where and order_by in a future PR. We also don't yet generate array aggregate `FieldParsers.
- The new `AFNestedArray` field is handled by the `QueryPlan` module in the `DataConnector` backend. There we generate an `API.NestedArrayField` from the AFNestedArray. We also handle nested arrays when reshaping the response from the DC agent.
## Limitations
- Support for limit, offset, filter (where) and order_by is not yet fully implemented, although it should not be hard to add this
- Support for aggregations on nested arrays is not yet fully implemented
- Permissions involving nested arrays (and objects) not yet implemented
- This should be integrated with Logical Model types, but that will happen in a separate PR
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9149
GitOrigin-RevId: 0e7b71a994fc1d2ca1ef73bfe7b96e95b5328531
2023-05-24 11:00:59 +03:00
AFNestedObject ( AnnNestedObjectSelectG b r v ) -- TODO(dmoverton): move XNestedObject to a field in AFNestedObject constructor for consistency with AFNestedArray
| -- | Nested array
2023-05-30 17:04:16 +03:00
AFNestedArray ( XNestedObjects b ) ( AnnNestedArraySelectG b r v )
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Eq ( AnnColumnField b v ) ,
Eq ( ArraySelectG b r v ) ,
Eq ( ComputedFieldSelect b r v ) ,
Eq ( ObjectRelationSelectG b r v ) ,
2023-04-11 04:29:05 +03:00
Eq ( RemoteRelationshipSelect b r ) ,
Nested array support for Data Connectors Backend and MongoDB
## Description
This change adds support for querying into nested arrays in Data Connector agents that support such a concept (currently MongoDB).
### DC API changes
- New API type `ColumnType` which allows representing the type of a "column" as either a scalar type, an object reference or an array of `ColumnType`s. This recursive definition allows arbitrary nesting of arrays of types.
- The `type` fields in the API types `ColumnInfo` and `ColumnInsertSchema` now take a `ColumnType` instead of a `ScalarType`.
- To ensure backwards compatibility, a `ColumnType` representing a scalar serialises and deserialises to the same representation as `ScalarType`.
- In queries, the `Field` type now has a new constructor `NestedArrayField`. This contains a nested `Field` along with optional `limit`, `offset`, `where` and `order_by` arguments. (These optional arguments are not yet used by either HGE or the MongoDB agent.)
### MongoDB Haskell agent changes
- The `/schema` endpoint will now recognise arrays within the JSON validation schema and generate corresponding arrays in the DC schema.
- The `/query` endpoint will now handle `NestedArrayField`s within queries (although it does not yet handle `limit`, `offset`, `where` and `order_by`).
### HGE server changes
- The `Backend` type class adds a new type family `XNestedArrays b` to enable nested arrays on a per-backend basis (currently enabled only for the `DataConnector` backend.
- Within `RawColumnInfo` the column type is now represented by a new type `RawColumnType b` which mirrors the shape of the DC API `ColumnType`, but uses `XNestedObjects b` and `XNestedArrays b` type families to allow turning nested object and array supports on or off for a particular backend. In the `DataConnector` backend `API.CustomType` is converted into `RawColumnInfo 'DataConnector` while building the schema.
- In the next stage of schema building, the `RawColumnInfo` is converted into a `StructuredColumnInfo` which allows us to represent the three different types of columns: scalar, object and array. TODO: the `StructuredColumnInfo` looks very similar to the Logical Model types. The main difference is that it uses the `XNestedObjects` and `XNestedArrays` type families. We should be able to combine these two representations.
- The `StructuredColumnInfo` is then placed into a `FIColumn` `FieldInfo`. This involved some refactoring of `FieldInfo` as I had previously split out `FINestedObject` into a separate constructor. However it works out better to represent all "column" fields (i.e. scalar, object and array) using `FIColumn` as this make it easier to implement permission checking correctly. This is the reason the `StructuredColumnInfo` was needed.
- Next, the `FieldInfo` are used to generate `FieldParser`s. We add a new constructor to `AnnFieldG` for `AFNestedArray`. An `AFNestedArray` field parser can contain either a simple array selection or an array aggregate. Simple array `FieldParsers` are currently limited to subfield selection. We will add support for limit, offset, where and order_by in a future PR. We also don't yet generate array aggregate `FieldParsers.
- The new `AFNestedArray` field is handled by the `QueryPlan` module in the `DataConnector` backend. There we generate an `API.NestedArrayField` from the AFNestedArray. We also handle nested arrays when reshaping the response from the DC agent.
## Limitations
- Support for limit, offset, filter (where) and order_by is not yet fully implemented, although it should not be hard to add this
- Support for aggregations on nested arrays is not yet fully implemented
- Permissions involving nested arrays (and objects) not yet implemented
- This should be integrated with Logical Model types, but that will happen in a separate PR
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9149
GitOrigin-RevId: 0e7b71a994fc1d2ca1ef73bfe7b96e95b5328531
2023-05-24 11:00:59 +03:00
Eq ( AnnNestedObjectSelectG b r v ) ,
Eq ( AnnNestedArraySelectG b r v )
2021-09-24 01:56:37 +03:00
) =>
Eq ( AnnFieldG b r v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Show ( AnnColumnField b v ) ,
Show ( ArraySelectG b r v ) ,
Show ( ComputedFieldSelect b r v ) ,
Show ( ObjectRelationSelectG b r v ) ,
2023-04-11 04:29:05 +03:00
Show ( RemoteRelationshipSelect b r ) ,
Nested array support for Data Connectors Backend and MongoDB
## Description
This change adds support for querying into nested arrays in Data Connector agents that support such a concept (currently MongoDB).
### DC API changes
- New API type `ColumnType` which allows representing the type of a "column" as either a scalar type, an object reference or an array of `ColumnType`s. This recursive definition allows arbitrary nesting of arrays of types.
- The `type` fields in the API types `ColumnInfo` and `ColumnInsertSchema` now take a `ColumnType` instead of a `ScalarType`.
- To ensure backwards compatibility, a `ColumnType` representing a scalar serialises and deserialises to the same representation as `ScalarType`.
- In queries, the `Field` type now has a new constructor `NestedArrayField`. This contains a nested `Field` along with optional `limit`, `offset`, `where` and `order_by` arguments. (These optional arguments are not yet used by either HGE or the MongoDB agent.)
### MongoDB Haskell agent changes
- The `/schema` endpoint will now recognise arrays within the JSON validation schema and generate corresponding arrays in the DC schema.
- The `/query` endpoint will now handle `NestedArrayField`s within queries (although it does not yet handle `limit`, `offset`, `where` and `order_by`).
### HGE server changes
- The `Backend` type class adds a new type family `XNestedArrays b` to enable nested arrays on a per-backend basis (currently enabled only for the `DataConnector` backend.
- Within `RawColumnInfo` the column type is now represented by a new type `RawColumnType b` which mirrors the shape of the DC API `ColumnType`, but uses `XNestedObjects b` and `XNestedArrays b` type families to allow turning nested object and array supports on or off for a particular backend. In the `DataConnector` backend `API.CustomType` is converted into `RawColumnInfo 'DataConnector` while building the schema.
- In the next stage of schema building, the `RawColumnInfo` is converted into a `StructuredColumnInfo` which allows us to represent the three different types of columns: scalar, object and array. TODO: the `StructuredColumnInfo` looks very similar to the Logical Model types. The main difference is that it uses the `XNestedObjects` and `XNestedArrays` type families. We should be able to combine these two representations.
- The `StructuredColumnInfo` is then placed into a `FIColumn` `FieldInfo`. This involved some refactoring of `FieldInfo` as I had previously split out `FINestedObject` into a separate constructor. However it works out better to represent all "column" fields (i.e. scalar, object and array) using `FIColumn` as this make it easier to implement permission checking correctly. This is the reason the `StructuredColumnInfo` was needed.
- Next, the `FieldInfo` are used to generate `FieldParser`s. We add a new constructor to `AnnFieldG` for `AFNestedArray`. An `AFNestedArray` field parser can contain either a simple array selection or an array aggregate. Simple array `FieldParsers` are currently limited to subfield selection. We will add support for limit, offset, where and order_by in a future PR. We also don't yet generate array aggregate `FieldParsers.
- The new `AFNestedArray` field is handled by the `QueryPlan` module in the `DataConnector` backend. There we generate an `API.NestedArrayField` from the AFNestedArray. We also handle nested arrays when reshaping the response from the DC agent.
## Limitations
- Support for limit, offset, filter (where) and order_by is not yet fully implemented, although it should not be hard to add this
- Support for aggregations on nested arrays is not yet fully implemented
- Permissions involving nested arrays (and objects) not yet implemented
- This should be integrated with Logical Model types, but that will happen in a separate PR
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9149
GitOrigin-RevId: 0e7b71a994fc1d2ca1ef73bfe7b96e95b5328531
2023-05-24 11:00:59 +03:00
Show ( AnnNestedObjectSelectG b r v ) ,
Show ( AnnNestedArraySelectG b r v )
2021-09-24 01:56:37 +03:00
) =>
Show ( AnnFieldG b r v )
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( AnnFieldG b ) where
2022-03-08 11:22:20 +03:00
bifoldMap f g = \ case
AFColumn col -> foldMap g col
AFObjectRelation objRel -> foldMap ( bifoldMap f g ) objRel
AFArrayRelation arrRel -> bifoldMap f g arrRel
AFComputedField _ _ cf -> bifoldMap f g cf
AFRemote r -> foldMap f r
AFNodeId { } -> mempty
AFExpression { } -> mempty
2023-04-11 04:29:05 +03:00
AFNestedObject no -> bifoldMap f g no
Nested array support for Data Connectors Backend and MongoDB
## Description
This change adds support for querying into nested arrays in Data Connector agents that support such a concept (currently MongoDB).
### DC API changes
- New API type `ColumnType` which allows representing the type of a "column" as either a scalar type, an object reference or an array of `ColumnType`s. This recursive definition allows arbitrary nesting of arrays of types.
- The `type` fields in the API types `ColumnInfo` and `ColumnInsertSchema` now take a `ColumnType` instead of a `ScalarType`.
- To ensure backwards compatibility, a `ColumnType` representing a scalar serialises and deserialises to the same representation as `ScalarType`.
- In queries, the `Field` type now has a new constructor `NestedArrayField`. This contains a nested `Field` along with optional `limit`, `offset`, `where` and `order_by` arguments. (These optional arguments are not yet used by either HGE or the MongoDB agent.)
### MongoDB Haskell agent changes
- The `/schema` endpoint will now recognise arrays within the JSON validation schema and generate corresponding arrays in the DC schema.
- The `/query` endpoint will now handle `NestedArrayField`s within queries (although it does not yet handle `limit`, `offset`, `where` and `order_by`).
### HGE server changes
- The `Backend` type class adds a new type family `XNestedArrays b` to enable nested arrays on a per-backend basis (currently enabled only for the `DataConnector` backend.
- Within `RawColumnInfo` the column type is now represented by a new type `RawColumnType b` which mirrors the shape of the DC API `ColumnType`, but uses `XNestedObjects b` and `XNestedArrays b` type families to allow turning nested object and array supports on or off for a particular backend. In the `DataConnector` backend `API.CustomType` is converted into `RawColumnInfo 'DataConnector` while building the schema.
- In the next stage of schema building, the `RawColumnInfo` is converted into a `StructuredColumnInfo` which allows us to represent the three different types of columns: scalar, object and array. TODO: the `StructuredColumnInfo` looks very similar to the Logical Model types. The main difference is that it uses the `XNestedObjects` and `XNestedArrays` type families. We should be able to combine these two representations.
- The `StructuredColumnInfo` is then placed into a `FIColumn` `FieldInfo`. This involved some refactoring of `FieldInfo` as I had previously split out `FINestedObject` into a separate constructor. However it works out better to represent all "column" fields (i.e. scalar, object and array) using `FIColumn` as this make it easier to implement permission checking correctly. This is the reason the `StructuredColumnInfo` was needed.
- Next, the `FieldInfo` are used to generate `FieldParser`s. We add a new constructor to `AnnFieldG` for `AFNestedArray`. An `AFNestedArray` field parser can contain either a simple array selection or an array aggregate. Simple array `FieldParsers` are currently limited to subfield selection. We will add support for limit, offset, where and order_by in a future PR. We also don't yet generate array aggregate `FieldParsers.
- The new `AFNestedArray` field is handled by the `QueryPlan` module in the `DataConnector` backend. There we generate an `API.NestedArrayField` from the AFNestedArray. We also handle nested arrays when reshaping the response from the DC agent.
## Limitations
- Support for limit, offset, filter (where) and order_by is not yet fully implemented, although it should not be hard to add this
- Support for aggregations on nested arrays is not yet fully implemented
- Permissions involving nested arrays (and objects) not yet implemented
- This should be integrated with Logical Model types, but that will happen in a separate PR
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9149
GitOrigin-RevId: 0e7b71a994fc1d2ca1ef73bfe7b96e95b5328531
2023-05-24 11:00:59 +03:00
AFNestedArray _ na -> bifoldMap f g na
2022-03-08 11:22:20 +03:00
2021-12-07 16:12:02 +03:00
type AnnField b = AnnFieldG b Void ( SQLExpression b )
2021-09-22 13:43:05 +03:00
2021-12-07 16:12:02 +03:00
type AnnFields b = AnnFieldsG b Void ( SQLExpression b )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-09-24 01:56:37 +03:00
mkAnnColumnField ::
Column backend ->
ColumnType backend ->
Maybe ( AnnColumnCaseBoolExp backend v ) ->
2022-05-03 11:58:56 +03:00
Maybe ( ScalarSelectionArguments backend ) ->
2021-09-24 01:56:37 +03:00
AnnFieldG backend r v
2021-09-22 13:43:05 +03:00
mkAnnColumnField col typ caseBoolExp colOpM =
AFColumn ( AnnColumnField col typ False colOpM caseBoolExp )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-09-24 01:56:37 +03:00
mkAnnColumnFieldAsText ::
ColumnInfo backend ->
AnnFieldG backend r v
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
mkAnnColumnFieldAsText ci =
2022-01-19 11:37:50 +03:00
AFColumn ( AnnColumnField ( ciColumn ci ) ( ciType ci ) True Nothing Nothing )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2022-04-06 10:18:59 +03:00
traverseSourceRelationshipSelection ::
( Applicative f , Backend backend ) =>
( vf backend -> f ( vg backend ) ) ->
SourceRelationshipSelection backend r vf ->
f ( SourceRelationshipSelection backend r vg )
traverseSourceRelationshipSelection f = \ case
SourceRelationshipObject s ->
SourceRelationshipObject <$> traverse f s
SourceRelationshipArray s ->
SourceRelationshipArray <$> traverse f s
SourceRelationshipArrayAggregate s ->
SourceRelationshipArrayAggregate <$> traverse f s
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
-- Aggregation fields
2018-12-12 15:58:39 +03:00
2021-12-07 16:12:02 +03:00
data TableAggregateFieldG ( b :: BackendType ) ( r :: Type ) v
2023-05-23 17:46:27 +03:00
= TAFAgg ( AggregateFields b v )
2022-02-23 23:17:58 +03:00
| TAFNodes ( XNodesAgg b ) ( AnnFieldsG b r v )
2023-06-19 08:04:54 +03:00
| TAFGroupBy ( XGroupBy b ) ( GroupByG b r v )
2022-02-23 23:17:58 +03:00
| TAFExp Text
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
2018-12-12 15:58:39 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2023-05-23 17:46:27 +03:00
Eq ( AggregateFields b v ) ,
2023-06-19 08:04:54 +03:00
Eq ( AnnFieldsG b r v ) ,
Eq ( GroupByG b r v )
2021-09-24 01:56:37 +03:00
) =>
Eq ( TableAggregateFieldG b r v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2023-05-23 17:46:27 +03:00
Show ( AggregateFields b v ) ,
2023-06-19 08:04:54 +03:00
Show ( AnnFieldsG b r v ) ,
Show ( GroupByG b r v )
2021-09-24 01:56:37 +03:00
) =>
Show ( TableAggregateFieldG b r v )
2021-09-22 13:43:05 +03:00
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( TableAggregateFieldG b ) where
2023-06-19 08:04:54 +03:00
bifoldMap :: ( Monoid m ) => ( r -> m ) -> ( v -> m ) -> TableAggregateFieldG b r v -> m
bifoldMap mapR mapV = \ case
TAFAgg aggFields -> foldMap ( foldMap $ foldMap mapV ) aggFields
TAFNodes _ fields -> foldMap ( foldMap $ bifoldMap mapR mapV ) fields
TAFGroupBy _ groupByFields -> bifoldMap mapR mapV groupByFields
2022-03-08 11:22:20 +03:00
TAFExp { } -> mempty
2023-05-23 17:46:27 +03:00
data AggregateField ( b :: BackendType ) v
2023-07-17 07:27:11 +03:00
= AFCount ( CountType b v )
2023-05-23 17:46:27 +03:00
| AFOp ( AggregateOp b v )
2022-02-23 23:17:58 +03:00
| AFExp Text
2023-07-17 07:27:11 +03:00
deriving stock instance ( Backend b ) => Functor ( AggregateField b )
deriving stock instance ( Backend b ) => Foldable ( AggregateField b )
deriving stock instance ( Backend b ) => Traversable ( AggregateField b )
2021-09-24 01:56:37 +03:00
2023-05-23 17:46:27 +03:00
deriving stock instance
2023-07-17 07:27:11 +03:00
( Backend b , Eq ( CountType b v ) , Eq ( AggregateOp b v ) , Eq v ) =>
2023-05-23 17:46:27 +03:00
Eq ( AggregateField b v )
2021-09-24 01:56:37 +03:00
2023-05-23 17:46:27 +03:00
deriving stock instance
2023-07-17 07:27:11 +03:00
( Backend b , Show ( CountType b v ) , Show ( AggregateOp b v ) , Show v ) =>
2023-05-23 17:46:27 +03:00
Show ( AggregateField b v )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2023-05-23 17:46:27 +03:00
data AggregateOp ( b :: BackendType ) v = AggregateOp
2022-02-23 23:17:58 +03:00
{ _aoOp :: Text ,
2023-05-23 17:46:27 +03:00
_aoFields :: SelectionFields b v
2021-09-24 01:56:37 +03:00
}
2023-05-23 17:46:27 +03:00
deriving ( Functor , Foldable , Traversable )
deriving stock instance
2023-07-17 07:27:11 +03:00
( Backend b , Eq ( SelectionFields b v ) , Eq v ) =>
2023-05-23 17:46:27 +03:00
Eq ( AggregateOp b v )
deriving stock instance
2023-07-17 07:27:11 +03:00
( Backend b , Show ( SelectionFields b v ) , Show v ) =>
2023-05-23 17:46:27 +03:00
Show ( AggregateOp b v )
2023-06-19 08:04:54 +03:00
data GroupByG ( b :: BackendType ) r v = GroupByG
{ _gbgKeys :: [ GroupKeyField b ] ,
_gbgFields :: Fields ( GroupByField b r v )
}
deriving ( Functor , Foldable , Traversable )
deriving stock instance ( Backend b , Eq ( GroupByField b r v ) , Eq ( GroupKeyField b ) ) => Eq ( GroupByG b r v )
deriving stock instance ( Backend b , Show ( GroupByField b r v ) , Show ( GroupKeyField b ) ) => Show ( GroupByG b r v )
instance ( Backend b ) => Bifoldable ( GroupByG b ) where
bifoldMap :: ( Monoid m ) => ( r -> m ) -> ( v -> m ) -> GroupByG b r v -> m
bifoldMap mapR mapV GroupByG { .. } =
foldMap ( foldMap $ bifoldMap mapR mapV ) _gbgFields
data GroupByField ( b :: BackendType ) r v
= GBFGroupKey ( Fields ( GroupKeyField b ) )
| GBFAggregate ( AggregateFields b v )
| GBFNodes ( AnnFieldsG b r v )
| GBFExp Text
deriving ( Functor , Foldable , Traversable )
deriving stock instance ( Backend b , Eq ( GroupKeyField b ) , Eq ( AggregateField b v ) , Eq ( AnnFieldG b r v ) ) => Eq ( GroupByField b r v )
deriving stock instance ( Backend b , Show ( GroupKeyField b ) , Show ( AggregateField b v ) , Show ( AnnFieldG b r v ) ) => Show ( GroupByField b r v )
instance ( Backend b ) => Bifoldable ( GroupByField b ) where
bifoldMap :: ( Monoid m ) => ( r -> m ) -> ( v -> m ) -> GroupByField b r v -> m
bifoldMap mapR mapV = \ case
GBFGroupKey _groupKeyFields -> mempty
GBFAggregate aggFields -> foldMap ( foldMap $ foldMap mapV ) aggFields
GBFNodes fields -> foldMap ( foldMap $ bifoldMap mapR mapV ) fields
GBFExp _text -> mempty
data GroupKeyField ( b :: BackendType )
= GKFColumn ( Column b )
| GKFExp Text
deriving stock instance ( Backend b ) => Eq ( GroupKeyField b )
deriving stock instance ( Backend b ) => Show ( GroupKeyField b )
2023-05-23 17:46:27 +03:00
-- | Types of fields that can be selected in a user query.
data SelectionField ( b :: BackendType ) v
2023-07-17 07:27:11 +03:00
= SFCol
( Column b )
( ColumnType b )
-- | This type is used to determine whether the column
-- should be nullified. When the value is `Nothing`, the column value
-- will be outputted as computed and when the value is `Just c`, the
-- column will be outputted when `c` evaluates to `true` and `null`
-- when `c` evaluates to `false`.
( Maybe ( AnnColumnCaseBoolExp b v ) )
2023-05-23 17:46:27 +03:00
| SFComputedField ComputedFieldName ( ComputedFieldScalarSelect b v )
| SFExp Text
deriving ( Functor , Foldable , Traversable )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2023-05-23 17:46:27 +03:00
deriving stock instance
2023-07-17 07:27:11 +03:00
( Backend b , Eq ( FunctionArgumentExp b v ) , Eq ( AnnColumnCaseBoolExp b v ) , Eq v ) =>
2023-05-23 17:46:27 +03:00
Eq ( SelectionField b v )
deriving stock instance
2023-07-17 07:27:11 +03:00
( Backend b , Show ( FunctionArgumentExp b v ) , Show ( AnnColumnCaseBoolExp b v ) , Show v ) =>
2023-05-23 17:46:27 +03:00
Show ( SelectionField b v )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-12-07 16:12:02 +03:00
type TableAggregateField b = TableAggregateFieldG b Void ( SQLExpression b )
2021-09-24 01:56:37 +03:00
2021-12-07 16:12:02 +03:00
type TableAggregateFields b = TableAggregateFieldsG b Void ( SQLExpression b )
2021-09-24 01:56:37 +03:00
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
type TableAggregateFieldsG b r v = Fields ( TableAggregateFieldG b r v )
2023-05-23 17:46:27 +03:00
type SelectionFields b v = Fields ( SelectionField b v )
2021-09-24 01:56:37 +03:00
2023-05-23 17:46:27 +03:00
type AggregateFields b v = Fields ( AggregateField b v )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-09-24 01:56:37 +03:00
type AnnFieldsG b r v = Fields ( AnnFieldG b r v )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
-- Relay fields
2021-12-07 16:12:02 +03:00
data ConnectionField ( b :: BackendType ) ( r :: Type ) v
2022-02-23 23:17:58 +03:00
= ConnectionTypename Text
| ConnectionPageInfo PageInfoFields
| ConnectionEdges ( EdgeFields b r v )
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2022-08-11 19:31:34 +03:00
( Eq ( EdgeFields b r v )
2021-09-24 01:56:37 +03:00
) =>
Eq ( ConnectionField b r v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2022-08-11 19:31:34 +03:00
( Show ( EdgeFields b r v )
2021-09-24 01:56:37 +03:00
) =>
Show ( ConnectionField b r v )
2021-09-22 13:43:05 +03:00
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( ConnectionField b ) where
2022-03-08 11:22:20 +03:00
bifoldMap f g = \ case
ConnectionTypename { } -> mempty
ConnectionPageInfo { } -> mempty
ConnectionEdges edgeFields -> foldMap ( foldMap $ bifoldMap f g ) edgeFields
2020-06-08 15:13:01 +03:00
data PageInfoField
2022-02-23 23:17:58 +03:00
= PageInfoTypename Text
2020-06-08 15:13:01 +03:00
| PageInfoHasNextPage
| PageInfoHasPreviousPage
| PageInfoStartCursor
| PageInfoEndCursor
2021-12-13 19:48:10 +03:00
deriving stock ( Show , Eq )
2021-04-22 00:44:37 +03:00
2021-12-07 16:12:02 +03:00
data EdgeField ( b :: BackendType ) ( r :: Type ) v
2022-02-23 23:17:58 +03:00
= EdgeTypename Text
2020-06-08 15:13:01 +03:00
| EdgeCursor
2022-02-23 23:17:58 +03:00
| EdgeNode ( AnnFieldsG b r v )
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
2020-06-08 15:13:01 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2022-08-11 19:31:34 +03:00
( Eq ( AnnFieldsG b r v )
2021-09-24 01:56:37 +03:00
) =>
Eq ( EdgeField b r v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2022-08-11 19:31:34 +03:00
( Show ( AnnFieldsG b r v )
2021-09-24 01:56:37 +03:00
) =>
Show ( EdgeField b r v )
2021-09-22 13:43:05 +03:00
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( EdgeField b ) where
2022-03-08 11:22:20 +03:00
bifoldMap f g = \ case
EdgeTypename { } -> mempty
EdgeCursor -> mempty
EdgeNode annFields -> foldMap ( foldMap $ bifoldMap f g ) annFields
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
type ConnectionFields b r v = Fields ( ConnectionField b r v )
2021-04-22 00:44:37 +03:00
2021-09-24 01:56:37 +03:00
type PageInfoFields = Fields PageInfoField
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
type EdgeFields b r v = Fields ( EdgeField b r v )
2020-06-08 15:13:01 +03:00
2021-09-24 01:56:37 +03:00
data AnnColumnField ( b :: BackendType ) v = AnnColumnField
2022-02-25 23:37:32 +03:00
{ _acfColumn :: Column b ,
_acfType :: ColumnType b ,
2022-05-03 11:58:56 +03:00
-- | If this field is 'True', columns are explicitly casted to @text@ when
-- fetched, which avoids an issue that occurs because we don’ t currently
-- have proper support for array types. See
2021-09-24 01:56:37 +03:00
-- https://github.com/hasura/graphql-engine/pull/3198 for more details.
2022-02-23 23:17:58 +03:00
_acfAsText :: Bool ,
2022-05-03 11:58:56 +03:00
-- | Arguments of this column's selection. See 'ScalarSelectionArguments'
_acfArguments :: Maybe ( ScalarSelectionArguments b ) ,
2022-02-25 23:37:32 +03:00
-- | This type is used to determine whether the column
2021-09-24 01:56:37 +03:00
-- should be nullified. When the value is `Nothing`, the column value
-- will be outputted as computed and when the value is `Just c`, the
-- column will be outputted when `c` evaluates to `true` and `null`
-- when `c` evaluates to `false`.
2022-02-23 23:17:58 +03:00
_acfCaseBoolExpression :: ( Maybe ( AnnColumnCaseBoolExp b v ) )
2021-09-24 01:56:37 +03:00
}
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
2021-05-21 05:46:58 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-10-06 12:07:14 +03:00
Eq ( AnnColumnCaseBoolExp b v )
2021-09-24 01:56:37 +03:00
) =>
Eq ( AnnColumnField b v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-10-06 12:07:14 +03:00
Show ( AnnColumnCaseBoolExp b v )
2021-09-24 01:56:37 +03:00
) =>
Show ( AnnColumnField b v )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
-- Computed field
2019-04-17 12:48:41 +03:00
2021-09-24 01:56:37 +03:00
data ComputedFieldScalarSelect ( b :: BackendType ) v = ComputedFieldScalarSelect
2022-02-25 23:37:32 +03:00
{ _cfssFunction :: FunctionName b ,
2022-05-25 13:24:41 +03:00
_cfssArguments :: FunctionArgsExp b v ,
2022-02-25 23:37:32 +03:00
_cfssType :: ScalarType b ,
2023-07-17 07:27:11 +03:00
_cfssScalarArguments :: ( Maybe ( ScalarSelectionArguments b ) ) ,
-- | This type is used to determine if whether the scalar
-- computed field should be nullified. When the value is `Nothing`,
-- the scalar computed value will be outputted as computed and when the
-- value is `Just c`, the scalar computed field will be outputted when
-- `c` evaluates to `true` and `null` when `c` evaluates to `false`
_cfssCaseBoolExpression :: Maybe ( AnnColumnCaseBoolExp b v )
2021-09-24 01:56:37 +03:00
}
2023-07-17 07:27:11 +03:00
deriving stock ( Functor , Foldable , Traversable )
2021-09-24 01:56:37 +03:00
2023-07-17 07:27:11 +03:00
deriving stock instance
( Backend b ,
Show v ,
Show ( FunctionArgumentExp b v ) ,
Show ( AnnColumnCaseBoolExp b v )
) =>
Show ( ComputedFieldScalarSelect b v )
2022-05-25 13:24:41 +03:00
2023-07-17 07:27:11 +03:00
deriving stock instance
( Backend b ,
Eq v ,
Eq ( FunctionArgumentExp b v ) ,
Eq ( AnnColumnCaseBoolExp b v )
) =>
Eq ( ComputedFieldScalarSelect b v )
2018-12-12 15:58:39 +03:00
2021-12-07 16:12:02 +03:00
data ComputedFieldSelect ( b :: BackendType ) ( r :: Type ) v
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
= CFSScalar
2023-05-24 16:51:56 +03:00
-- | Type containing info about the computed field
2022-02-23 23:17:58 +03:00
( ComputedFieldScalarSelect b v )
2022-08-01 12:32:04 +03:00
| CFSTable JsonAggSelect ( AnnSimpleSelectG b r v )
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
2019-04-17 12:48:41 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Eq ( AnnSimpleSelectG b r v ) ,
Eq ( ComputedFieldScalarSelect b v )
2021-09-24 01:56:37 +03:00
) =>
Eq ( ComputedFieldSelect b r v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Show ( AnnSimpleSelectG b r v ) ,
Show ( ComputedFieldScalarSelect b v )
2021-09-24 01:56:37 +03:00
) =>
Show ( ComputedFieldSelect b r v )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( ComputedFieldSelect b ) where
2022-03-08 11:22:20 +03:00
bifoldMap f g = \ case
2023-07-17 07:27:11 +03:00
CFSScalar cfsSelect -> foldMap g cfsSelect
2022-03-08 11:22:20 +03:00
CFSTable _ simpleSelect -> bifoldMapAnnSelectG f g simpleSelect
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
-- Local relationship
2021-09-24 01:56:37 +03:00
type ArrayRelationSelectG b r v = AnnRelationSelectG b ( AnnSimpleSelectG b r v )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
type ArrayAggregateSelectG b r v = AnnRelationSelectG b ( AnnAggregateSelectG b r v )
2021-09-24 01:56:37 +03:00
type ArrayConnectionSelect b r v = AnnRelationSelectG b ( ConnectionSelect b r v )
2021-12-07 16:12:02 +03:00
type ArrayAggregateSelect b = ArrayAggregateSelectG b Void ( SQLExpression b )
2021-09-24 01:56:37 +03:00
2021-12-07 16:12:02 +03:00
data AnnObjectSelectG ( b :: BackendType ) ( r :: Type ) v = AnnObjectSelectG
2022-02-25 23:37:32 +03:00
{ _aosFields :: AnnFieldsG b r v ,
2023-05-10 18:13:56 +03:00
_aosTarget :: SelectFromG b v ,
_aosTargetFilter :: ( AnnBoolExp b v )
2021-09-24 01:56:37 +03:00
}
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2023-05-10 18:13:56 +03:00
Eq ( SelectFromG b v ) ,
2022-08-11 19:31:34 +03:00
Eq ( AnnBoolExp b v ) ,
Eq ( AnnFieldsG b r v )
2021-09-24 01:56:37 +03:00
) =>
Eq ( AnnObjectSelectG b r v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2023-05-10 18:13:56 +03:00
Show ( SelectFromG b v ) ,
2022-08-11 19:31:34 +03:00
Show ( AnnBoolExp b v ) ,
Show ( AnnFieldsG b r v )
2021-09-24 01:56:37 +03:00
) =>
Show ( AnnObjectSelectG b r v )
2021-09-22 13:43:05 +03:00
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( AnnObjectSelectG b ) where
2022-03-08 11:22:20 +03:00
bifoldMap f g AnnObjectSelectG { .. } =
2023-05-10 18:13:56 +03:00
foldMap ( foldMap $ bifoldMap f g ) _aosFields <> foldMap ( foldMap g ) _aosTargetFilter
2022-03-08 11:22:20 +03:00
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
type AnnObjectSelect b r = AnnObjectSelectG b r ( SQLExpression b )
type ObjectRelationSelectG b r v = AnnRelationSelectG b ( AnnObjectSelectG b r v )
2021-12-07 16:12:02 +03:00
type ObjectRelationSelect b = ObjectRelationSelectG b Void ( SQLExpression b )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-12-07 16:12:02 +03:00
data ArraySelectG ( b :: BackendType ) ( r :: Type ) v
2022-02-23 23:17:58 +03:00
= ASSimple ( ArrayRelationSelectG b r v )
| ASAggregate ( ArrayAggregateSelectG b r v )
| ASConnection ( ArrayConnectionSelect b r v )
2021-12-13 19:48:10 +03:00
deriving stock ( Functor , Foldable , Traversable )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2022-08-11 19:31:34 +03:00
( Eq ( ArrayRelationSelectG b r v ) ,
Eq ( ArrayAggregateSelectG b r v ) ,
Eq ( ArrayConnectionSelect b r v )
2021-09-24 01:56:37 +03:00
) =>
Eq ( ArraySelectG b r v )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2022-08-11 19:31:34 +03:00
( Show ( ArrayRelationSelectG b r v ) ,
Show ( ArrayAggregateSelectG b r v ) ,
Show ( ArrayConnectionSelect b r v )
2021-09-24 01:56:37 +03:00
) =>
Show ( ArraySelectG b r v )
2021-09-22 13:43:05 +03:00
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( ArraySelectG b ) where
2022-03-08 11:22:20 +03:00
bifoldMap f g = \ case
ASSimple arrayRelationSelect -> foldMap ( bifoldMapAnnSelectG f g ) arrayRelationSelect
ASAggregate arrayAggregateSelect -> foldMap ( bifoldMapAnnSelectG f g ) arrayAggregateSelect
ASConnection arrayConnectionSelect -> foldMap ( bifoldMap f g ) arrayConnectionSelect
2021-12-07 16:12:02 +03:00
type ArraySelect b = ArraySelectG b Void ( SQLExpression b )
server: IR for DB-DB joins
### Description
This PR adds the required IR for DB to DB joins, based on @paf31 and @0x777 's `feature/db-to-db` branch.
To do so, it also refactors the IR to introduce a new type parameter, `r`, which is used to recursively constructs the `v` parameter of remote QueryDBs. When collecting remote joins, we replace `r` with `Const Void`, indicating at the type level that there cannot be any leftover remote join.
Furthermore, this PR refactors IR.Select for readability, moves some code from IR.Root to IR.Select to avoid having to deal with circular dependencies, and makes it compile by adding `error` in all new cases in the execution pipeline.
The diff doesn't make it clear, but most of Select.hs is actually unchanged. Declarations have just been reordered by topic, in the following order:
- type declarations
- instance declarations
- type aliases
- constructor functions
- traverse functions
https://github.com/hasura/graphql-engine-mono/pull/1580
Co-authored-by: Phil Freeman <630306+paf31@users.noreply.github.com>
GitOrigin-RevId: bbdcb4119cec8bb3fc32f1294f91b8dea0728721
2021-06-18 02:12:11 +03:00
2021-09-24 01:56:37 +03:00
type ArraySelectFieldsG b r v = Fields ( ArraySelectG b r v )
2019-04-17 12:48:41 +03:00
2021-07-26 16:03:51 +03:00
-- | Captures the selection set of a remote source relationship.
2021-09-24 01:56:37 +03:00
data
SourceRelationshipSelection
2021-07-26 16:03:51 +03:00
( b :: BackendType )
2021-12-07 16:12:02 +03:00
( r :: Type )
2021-07-26 16:03:51 +03:00
( vf :: BackendType -> Type )
2022-02-23 23:17:58 +03:00
= SourceRelationshipObject ( AnnObjectSelectG b r ( vf b ) )
| SourceRelationshipArray ( AnnSimpleSelectG b r ( vf b ) )
| SourceRelationshipArrayAggregate ( AnnAggregateSelectG b r ( vf b ) )
2021-07-26 16:03:51 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Eq ( AnnAggregateSelectG b r ( vf b ) ) ,
Eq ( AnnObjectSelectG b r ( vf b ) ) ,
Eq ( AnnSimpleSelectG b r ( vf b ) )
2021-09-24 01:56:37 +03:00
) =>
2022-08-11 19:31:34 +03:00
Eq ( SourceRelationshipSelection b r vf )
2021-09-22 13:43:05 +03:00
2021-12-13 19:48:10 +03:00
deriving stock instance
2021-09-24 01:56:37 +03:00
( Backend b ,
2022-08-11 19:31:34 +03:00
Show ( AnnAggregateSelectG b r ( vf b ) ) ,
Show ( AnnObjectSelectG b r ( vf b ) ) ,
Show ( AnnSimpleSelectG b r ( vf b ) )
2021-09-24 01:56:37 +03:00
) =>
2022-08-11 19:31:34 +03:00
Show ( SourceRelationshipSelection b r vf )
2021-09-22 13:43:05 +03:00
2021-07-26 16:03:51 +03:00
-- | A relationship to a remote source. 'vf' (could use a better name) is
-- analogous to 'v' in other IR types such as 'AnnFieldG'. vf's kind is
-- (BackendType -> Type) instead of v's 'Type' so that 'v' of 'AnnFieldG' can
-- be specific to the backend that it captures ('b' of an AnnFieldG changes as
-- we walk down the IR branches which capture relationships to other databases)
2021-09-24 01:56:37 +03:00
data
RemoteSourceSelect
2021-12-07 16:12:02 +03:00
( r :: Type )
2021-07-26 16:03:51 +03:00
( vf :: BackendType -> Type )
2021-09-24 01:56:37 +03:00
( tgt :: BackendType ) = RemoteSourceSelect
2022-02-23 23:17:58 +03:00
{ _rssName :: SourceName ,
2022-02-25 23:37:32 +03:00
_rssConfig :: SourceConfig tgt ,
_rssSelection :: SourceRelationshipSelection tgt r vf ,
2021-09-24 01:56:37 +03:00
-- | Additional information about the source's join columns:
2021-07-26 16:03:51 +03:00
-- (ScalarType tgt) so that the remote can interpret the join values coming
-- from src
-- (Column tgt) so that an appropriate join condition / IN clause can be built
-- by the remote
2023-04-26 18:42:13 +03:00
_rssJoinMapping :: ( HashMap . HashMap FieldName ( ScalarType tgt , Column tgt ) ) ,
2022-12-19 17:03:13 +03:00
_rssStringifyNums :: StringifyNumbers
2021-09-24 01:56:37 +03:00
}
2021-07-26 16:03:51 +03:00
2022-05-26 17:05:13 +03:00
deriving stock instance
( Backend tgt ,
2022-08-11 19:31:34 +03:00
Eq ( SourceRelationshipSelection tgt r vf )
2022-05-26 17:05:13 +03:00
) =>
Eq ( RemoteSourceSelect r vf tgt )
2023-01-04 11:28:19 +03:00
deriving stock instance
( Backend tgt ,
Show ( SourceRelationshipSelection tgt r vf ) ,
Show ( SourceConfig tgt )
) =>
Show ( RemoteSourceSelect r vf tgt )
2023-04-11 04:29:05 +03:00
-- Nested objects
data AnnNestedObjectSelectG ( b :: BackendType ) ( r :: Type ) v = AnnNestedObjectSelectG
{ _anosSupportsNestedObjects :: XNestedObjects b ,
_anosColumn :: Column b ,
_anosFields :: AnnFieldsG b r v
}
deriving stock ( Functor , Foldable , Traversable )
deriving stock instance
( Backend b ,
Eq ( AnnFieldsG b r v )
) =>
Eq ( AnnNestedObjectSelectG b r v )
deriving stock instance
( Backend b ,
Show ( AnnFieldsG b r v )
) =>
Show ( AnnNestedObjectSelectG b r v )
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( AnnNestedObjectSelectG b ) where
2023-04-11 04:29:05 +03:00
bifoldMap f g AnnNestedObjectSelectG { .. } =
foldMap ( foldMap $ bifoldMap f g ) _anosFields
type AnnNestedObjectSelect b r = AnnNestedObjectSelectG b r ( SQLExpression b )
Nested array support for Data Connectors Backend and MongoDB
## Description
This change adds support for querying into nested arrays in Data Connector agents that support such a concept (currently MongoDB).
### DC API changes
- New API type `ColumnType` which allows representing the type of a "column" as either a scalar type, an object reference or an array of `ColumnType`s. This recursive definition allows arbitrary nesting of arrays of types.
- The `type` fields in the API types `ColumnInfo` and `ColumnInsertSchema` now take a `ColumnType` instead of a `ScalarType`.
- To ensure backwards compatibility, a `ColumnType` representing a scalar serialises and deserialises to the same representation as `ScalarType`.
- In queries, the `Field` type now has a new constructor `NestedArrayField`. This contains a nested `Field` along with optional `limit`, `offset`, `where` and `order_by` arguments. (These optional arguments are not yet used by either HGE or the MongoDB agent.)
### MongoDB Haskell agent changes
- The `/schema` endpoint will now recognise arrays within the JSON validation schema and generate corresponding arrays in the DC schema.
- The `/query` endpoint will now handle `NestedArrayField`s within queries (although it does not yet handle `limit`, `offset`, `where` and `order_by`).
### HGE server changes
- The `Backend` type class adds a new type family `XNestedArrays b` to enable nested arrays on a per-backend basis (currently enabled only for the `DataConnector` backend.
- Within `RawColumnInfo` the column type is now represented by a new type `RawColumnType b` which mirrors the shape of the DC API `ColumnType`, but uses `XNestedObjects b` and `XNestedArrays b` type families to allow turning nested object and array supports on or off for a particular backend. In the `DataConnector` backend `API.CustomType` is converted into `RawColumnInfo 'DataConnector` while building the schema.
- In the next stage of schema building, the `RawColumnInfo` is converted into a `StructuredColumnInfo` which allows us to represent the three different types of columns: scalar, object and array. TODO: the `StructuredColumnInfo` looks very similar to the Logical Model types. The main difference is that it uses the `XNestedObjects` and `XNestedArrays` type families. We should be able to combine these two representations.
- The `StructuredColumnInfo` is then placed into a `FIColumn` `FieldInfo`. This involved some refactoring of `FieldInfo` as I had previously split out `FINestedObject` into a separate constructor. However it works out better to represent all "column" fields (i.e. scalar, object and array) using `FIColumn` as this make it easier to implement permission checking correctly. This is the reason the `StructuredColumnInfo` was needed.
- Next, the `FieldInfo` are used to generate `FieldParser`s. We add a new constructor to `AnnFieldG` for `AFNestedArray`. An `AFNestedArray` field parser can contain either a simple array selection or an array aggregate. Simple array `FieldParsers` are currently limited to subfield selection. We will add support for limit, offset, where and order_by in a future PR. We also don't yet generate array aggregate `FieldParsers.
- The new `AFNestedArray` field is handled by the `QueryPlan` module in the `DataConnector` backend. There we generate an `API.NestedArrayField` from the AFNestedArray. We also handle nested arrays when reshaping the response from the DC agent.
## Limitations
- Support for limit, offset, filter (where) and order_by is not yet fully implemented, although it should not be hard to add this
- Support for aggregations on nested arrays is not yet fully implemented
- Permissions involving nested arrays (and objects) not yet implemented
- This should be integrated with Logical Model types, but that will happen in a separate PR
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9149
GitOrigin-RevId: 0e7b71a994fc1d2ca1ef73bfe7b96e95b5328531
2023-05-24 11:00:59 +03:00
-- Nested arrays
data AnnNestedArraySelectG ( b :: BackendType ) ( r :: Type ) v
= ANASSimple ( AnnFieldG b r v )
| ANASAggregate ( AnnAggregateSelectG b r v )
deriving stock ( Functor , Foldable , Traversable )
deriving stock instance
( Backend b , Eq ( AnnFieldG b r v ) , Eq ( AnnAggregateSelectG b r v ) ) => Eq ( AnnNestedArraySelectG b r v )
deriving stock instance
( Backend b , Show ( AnnFieldG b r v ) , Show ( AnnAggregateSelectG b r v ) ) => Show ( AnnNestedArraySelectG b r v )
2023-05-24 16:51:56 +03:00
instance ( Backend b ) => Bifoldable ( AnnNestedArraySelectG b ) where
Nested array support for Data Connectors Backend and MongoDB
## Description
This change adds support for querying into nested arrays in Data Connector agents that support such a concept (currently MongoDB).
### DC API changes
- New API type `ColumnType` which allows representing the type of a "column" as either a scalar type, an object reference or an array of `ColumnType`s. This recursive definition allows arbitrary nesting of arrays of types.
- The `type` fields in the API types `ColumnInfo` and `ColumnInsertSchema` now take a `ColumnType` instead of a `ScalarType`.
- To ensure backwards compatibility, a `ColumnType` representing a scalar serialises and deserialises to the same representation as `ScalarType`.
- In queries, the `Field` type now has a new constructor `NestedArrayField`. This contains a nested `Field` along with optional `limit`, `offset`, `where` and `order_by` arguments. (These optional arguments are not yet used by either HGE or the MongoDB agent.)
### MongoDB Haskell agent changes
- The `/schema` endpoint will now recognise arrays within the JSON validation schema and generate corresponding arrays in the DC schema.
- The `/query` endpoint will now handle `NestedArrayField`s within queries (although it does not yet handle `limit`, `offset`, `where` and `order_by`).
### HGE server changes
- The `Backend` type class adds a new type family `XNestedArrays b` to enable nested arrays on a per-backend basis (currently enabled only for the `DataConnector` backend.
- Within `RawColumnInfo` the column type is now represented by a new type `RawColumnType b` which mirrors the shape of the DC API `ColumnType`, but uses `XNestedObjects b` and `XNestedArrays b` type families to allow turning nested object and array supports on or off for a particular backend. In the `DataConnector` backend `API.CustomType` is converted into `RawColumnInfo 'DataConnector` while building the schema.
- In the next stage of schema building, the `RawColumnInfo` is converted into a `StructuredColumnInfo` which allows us to represent the three different types of columns: scalar, object and array. TODO: the `StructuredColumnInfo` looks very similar to the Logical Model types. The main difference is that it uses the `XNestedObjects` and `XNestedArrays` type families. We should be able to combine these two representations.
- The `StructuredColumnInfo` is then placed into a `FIColumn` `FieldInfo`. This involved some refactoring of `FieldInfo` as I had previously split out `FINestedObject` into a separate constructor. However it works out better to represent all "column" fields (i.e. scalar, object and array) using `FIColumn` as this make it easier to implement permission checking correctly. This is the reason the `StructuredColumnInfo` was needed.
- Next, the `FieldInfo` are used to generate `FieldParser`s. We add a new constructor to `AnnFieldG` for `AFNestedArray`. An `AFNestedArray` field parser can contain either a simple array selection or an array aggregate. Simple array `FieldParsers` are currently limited to subfield selection. We will add support for limit, offset, where and order_by in a future PR. We also don't yet generate array aggregate `FieldParsers.
- The new `AFNestedArray` field is handled by the `QueryPlan` module in the `DataConnector` backend. There we generate an `API.NestedArrayField` from the AFNestedArray. We also handle nested arrays when reshaping the response from the DC agent.
## Limitations
- Support for limit, offset, filter (where) and order_by is not yet fully implemented, although it should not be hard to add this
- Support for aggregations on nested arrays is not yet fully implemented
- Permissions involving nested arrays (and objects) not yet implemented
- This should be integrated with Logical Model types, but that will happen in a separate PR
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9149
GitOrigin-RevId: 0e7b71a994fc1d2ca1ef73bfe7b96e95b5328531
2023-05-24 11:00:59 +03:00
bifoldMap f g = \ case
ANASSimple field -> bifoldMap f g field
ANASAggregate agg -> bifoldMapAnnSelectG f g agg
type AnnNestedArraySelect b r = AnnNestedArraySelectG b r ( SQLExpression b )
2020-06-08 15:13:01 +03:00
-- | If argument positional index is less than or equal to length of
-- 'positional' arguments then insert the value in 'positional' arguments else
-- insert the value with argument name in 'named' arguments
2021-09-24 01:56:37 +03:00
insertFunctionArg ::
FunctionArgName ->
Int ->
a ->
FunctionArgsExpG a ->
FunctionArgsExpG a
2020-05-27 18:02:58 +03:00
insertFunctionArg argName idx value ( FunctionArgsExp positional named ) =
2021-09-24 01:56:37 +03:00
if ( idx + 1 ) <= length positional
then FunctionArgsExp ( insertAt idx value positional ) named
else
2023-05-24 16:51:56 +03:00
FunctionArgsExp positional
$ HashMap . insert ( getFuncArgNameTxt argName ) value named
2019-10-18 11:29:47 +03:00
where
insertAt i a = toList . Seq . insertAt i a . Seq . fromList
2022-01-18 17:53:44 +03:00
-- | The "distinct" input field inside "count" aggregate field
--
-- count (
-- distinct: Boolean
2022-02-23 23:17:58 +03:00
-- ): Int
2022-01-18 17:53:44 +03:00
data CountDistinct
= SelectCountDistinct
| SelectCountNonDistinct