mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-11 10:46:25 +03:00
Rename DataConnector cross_table capability to subquery
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5980 GitOrigin-RevId: c289b2a7afb4d07214aac2b4d89c9b87a75e98aa
This commit is contained in:
parent
7365838f76
commit
3365a18516
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hasura/dc-api-types",
|
||||
"version": "0.6.0",
|
||||
"version": "0.7.0",
|
||||
"description": "Hasura GraphQL Engine Data Connector Agent API types",
|
||||
"author": "Hasura (https://github.com/hasura/graphql-engine)",
|
||||
"license": "Apache-2.0",
|
||||
|
@ -294,7 +294,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"RelationshipCapabilities": {},
|
||||
"CrossTableComparisonCapabilities": {
|
||||
"SubqueryComparisonCapabilities": {
|
||||
"nullable": true,
|
||||
"properties": {
|
||||
"supports_relations": {
|
||||
@ -309,8 +309,8 @@
|
||||
},
|
||||
"ComparisonCapabilities": {
|
||||
"properties": {
|
||||
"cross_table": {
|
||||
"$ref": "#/components/schemas/CrossTableComparisonCapabilities"
|
||||
"subquery": {
|
||||
"$ref": "#/components/schemas/SubqueryComparisonCapabilities"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
|
@ -21,7 +21,6 @@ export type { ComparisonColumn } from './models/ComparisonColumn';
|
||||
export type { ComparisonValue } from './models/ComparisonValue';
|
||||
export type { ConfigSchemaResponse } from './models/ConfigSchemaResponse';
|
||||
export type { Constraint } from './models/Constraint';
|
||||
export type { CrossTableComparisonCapabilities } from './models/CrossTableComparisonCapabilities';
|
||||
export type { ExistsExpression } from './models/ExistsExpression';
|
||||
export type { ExistsInTable } from './models/ExistsInTable';
|
||||
export type { ExplainCapabilities } from './models/ExplainCapabilities';
|
||||
@ -65,6 +64,7 @@ export type { SchemaResponse } from './models/SchemaResponse';
|
||||
export type { SingleColumnAggregate } from './models/SingleColumnAggregate';
|
||||
export type { SingleColumnAggregateFunction } from './models/SingleColumnAggregateFunction';
|
||||
export type { StarCountAggregate } from './models/StarCountAggregate';
|
||||
export type { SubqueryComparisonCapabilities } from './models/SubqueryComparisonCapabilities';
|
||||
export type { SubscriptionCapabilities } from './models/SubscriptionCapabilities';
|
||||
export type { TableInfo } from './models/TableInfo';
|
||||
export type { TableName } from './models/TableName';
|
||||
|
@ -2,9 +2,9 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
import type { CrossTableComparisonCapabilities } from './CrossTableComparisonCapabilities';
|
||||
import type { SubqueryComparisonCapabilities } from './SubqueryComparisonCapabilities';
|
||||
|
||||
export type ComparisonCapabilities = {
|
||||
cross_table?: CrossTableComparisonCapabilities;
|
||||
subquery?: SubqueryComparisonCapabilities;
|
||||
};
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export type CrossTableComparisonCapabilities = {
|
||||
export type SubqueryComparisonCapabilities = {
|
||||
/**
|
||||
* Does the agent support comparisons that involve related tables (ie. joins)?
|
||||
*/
|
10
dc-agents/package-lock.json
generated
10
dc-agents/package-lock.json
generated
@ -24,7 +24,7 @@
|
||||
},
|
||||
"dc-api-types": {
|
||||
"name": "@hasura/dc-api-types",
|
||||
"version": "0.6.0",
|
||||
"version": "0.7.0",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@tsconfig/node16": "^1.0.3",
|
||||
@ -631,7 +631,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^7.0.0",
|
||||
"@hasura/dc-api-types": "0.6.0",
|
||||
"@hasura/dc-api-types": "0.7.0",
|
||||
"fastify": "^3.29.0",
|
||||
"mathjs": "^11.0.0",
|
||||
"pino-pretty": "^8.0.0",
|
||||
@ -1389,7 +1389,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^8.1.0",
|
||||
"@hasura/dc-api-types": "0.6.0",
|
||||
"@hasura/dc-api-types": "0.7.0",
|
||||
"fastify": "^4.4.0",
|
||||
"fastify-metrics": "^9.2.1",
|
||||
"nanoid": "^3.3.4",
|
||||
@ -3127,7 +3127,7 @@
|
||||
"version": "file:reference",
|
||||
"requires": {
|
||||
"@fastify/cors": "^7.0.0",
|
||||
"@hasura/dc-api-types": "0.6.0",
|
||||
"@hasura/dc-api-types": "0.7.0",
|
||||
"@tsconfig/node16": "^1.0.3",
|
||||
"@types/node": "^16.11.49",
|
||||
"@types/xml2js": "^0.4.11",
|
||||
@ -3618,7 +3618,7 @@
|
||||
"version": "file:sqlite",
|
||||
"requires": {
|
||||
"@fastify/cors": "^8.1.0",
|
||||
"@hasura/dc-api-types": "0.6.0",
|
||||
"@hasura/dc-api-types": "0.7.0",
|
||||
"@tsconfig/node16": "^1.0.3",
|
||||
"@types/node": "^16.11.49",
|
||||
"@types/sqlite3": "^3.1.8",
|
||||
|
4
dc-agents/reference/package-lock.json
generated
4
dc-agents/reference/package-lock.json
generated
@ -10,7 +10,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^7.0.0",
|
||||
"@hasura/dc-api-types": "0.6.0",
|
||||
"@hasura/dc-api-types": "0.7.0",
|
||||
"fastify": "^3.29.0",
|
||||
"mathjs": "^11.0.0",
|
||||
"pino-pretty": "^8.0.0",
|
||||
@ -44,7 +44,7 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@hasura/dc-api-types": {
|
||||
"version": "0.6.0",
|
||||
"version": "0.7.0",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@tsconfig/node16": "^1.0.3",
|
||||
|
@ -22,7 +22,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^7.0.0",
|
||||
"@hasura/dc-api-types": "0.6.0",
|
||||
"@hasura/dc-api-types": "0.7.0",
|
||||
"fastify": "^3.29.0",
|
||||
"mathjs": "^11.0.0",
|
||||
"pino-pretty": "^8.0.0",
|
||||
|
@ -20,7 +20,7 @@ const scalarTypes: ScalarTypesCapabilities = {
|
||||
const capabilities: Capabilities = {
|
||||
relationships: {},
|
||||
comparisons: {
|
||||
cross_table: {
|
||||
subquery: {
|
||||
supports_relations: true
|
||||
}
|
||||
},
|
||||
|
4
dc-agents/sqlite/package-lock.json
generated
4
dc-agents/sqlite/package-lock.json
generated
@ -10,7 +10,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^8.1.0",
|
||||
"@hasura/dc-api-types": "0.6.0",
|
||||
"@hasura/dc-api-types": "0.7.0",
|
||||
"fastify": "^4.4.0",
|
||||
"fastify-metrics": "^9.2.1",
|
||||
"nanoid": "^3.3.4",
|
||||
@ -55,7 +55,7 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@hasura/dc-api-types": {
|
||||
"version": "0.6.0",
|
||||
"version": "0.7.0",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@tsconfig/node16": "^1.0.3",
|
||||
|
@ -22,7 +22,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^8.1.0",
|
||||
"@hasura/dc-api-types": "0.6.0",
|
||||
"@hasura/dc-api-types": "0.7.0",
|
||||
"fastify-metrics": "^9.2.1",
|
||||
"fastify": "^4.4.0",
|
||||
"nanoid": "^3.3.4",
|
||||
|
@ -10,7 +10,7 @@ export const capabilitiesResponse: CapabilitiesResponse = {
|
||||
},
|
||||
relationships: {},
|
||||
comparisons: {
|
||||
cross_table: {
|
||||
subquery: {
|
||||
supports_relations: true
|
||||
}
|
||||
},
|
||||
|
@ -14,7 +14,7 @@ module Hasura.Backends.DataConnector.API.V0.Capabilities
|
||||
GraphQLTypeDefinitions,
|
||||
RelationshipCapabilities (..),
|
||||
ComparisonCapabilities (..),
|
||||
CrossTableComparisonCapabilities (..),
|
||||
SubqueryComparisonCapabilities (..),
|
||||
MetricsCapabilities (..),
|
||||
ExplainCapabilities (..),
|
||||
CapabilitiesResponse (..),
|
||||
@ -224,7 +224,7 @@ instance HasCodec GraphQLTypeDefinitions where
|
||||
. _gtdTypeDefinitions
|
||||
|
||||
data ComparisonCapabilities = ComparisonCapabilities
|
||||
{_ccCrossTableComparisonCapabilities :: Maybe CrossTableComparisonCapabilities}
|
||||
{_ccSubqueryComparisonCapabilities :: Maybe SubqueryComparisonCapabilities}
|
||||
deriving stock (Eq, Ord, Show, Generic, Data)
|
||||
deriving anyclass (NFData, Hashable)
|
||||
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec ComparisonCapabilities
|
||||
@ -233,18 +233,18 @@ instance HasCodec ComparisonCapabilities where
|
||||
codec =
|
||||
object "ComparisonCapabilities" $
|
||||
ComparisonCapabilities
|
||||
<$> optionalFieldOrNull "cross_table" "The agent supports comparisons that involve tables other than the one being queried" .= _ccCrossTableComparisonCapabilities
|
||||
<$> optionalFieldOrNull "subquery" "The agent supports comparisons that involve tables other than the one being queried" .= _ccSubqueryComparisonCapabilities
|
||||
|
||||
data CrossTableComparisonCapabilities = CrossTableComparisonCapabilities
|
||||
data SubqueryComparisonCapabilities = SubqueryComparisonCapabilities
|
||||
{_ctccSupportsRelations :: Bool}
|
||||
deriving stock (Eq, Ord, Show, Generic, Data)
|
||||
deriving anyclass (NFData, Hashable)
|
||||
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec CrossTableComparisonCapabilities
|
||||
deriving (FromJSON, ToJSON, ToSchema) via Autodocodec SubqueryComparisonCapabilities
|
||||
|
||||
instance HasCodec CrossTableComparisonCapabilities where
|
||||
instance HasCodec SubqueryComparisonCapabilities where
|
||||
codec =
|
||||
object "CrossTableComparisonCapabilities" $
|
||||
CrossTableComparisonCapabilities
|
||||
object "SubqueryComparisonCapabilities" $
|
||||
SubqueryComparisonCapabilities
|
||||
<$> requiredField "supports_relations" "Does the agent support comparisons that involve related tables (ie. joins)?" .= _ctccSupportsRelations
|
||||
|
||||
data MetricsCapabilities = MetricsCapabilities {}
|
||||
|
@ -120,11 +120,11 @@ genRelationshipCapabilities = pure RelationshipCapabilities {}
|
||||
genComparisonCapabilities :: MonadGen m => m ComparisonCapabilities
|
||||
genComparisonCapabilities =
|
||||
ComparisonCapabilities
|
||||
<$> Gen.maybe genCrossTableComparisonCapabilities
|
||||
<$> Gen.maybe genSubqueryComparisonCapabilities
|
||||
|
||||
genCrossTableComparisonCapabilities :: MonadGen m => m CrossTableComparisonCapabilities
|
||||
genCrossTableComparisonCapabilities =
|
||||
CrossTableComparisonCapabilities
|
||||
genSubqueryComparisonCapabilities :: MonadGen m => m SubqueryComparisonCapabilities
|
||||
genSubqueryComparisonCapabilities =
|
||||
SubqueryComparisonCapabilities
|
||||
<$> Gen.bool
|
||||
|
||||
genMetricsCapabilities :: MonadGen m => m MetricsCapabilities
|
||||
|
@ -2,7 +2,7 @@ module Test.QuerySpec (spec) where
|
||||
|
||||
import Control.Monad (when)
|
||||
import Data.Maybe (isJust)
|
||||
import Hasura.Backends.DataConnector.API (Capabilities (..), ComparisonCapabilities (_ccCrossTableComparisonCapabilities), Config, Routes (..), SourceName)
|
||||
import Hasura.Backends.DataConnector.API (Capabilities (..), ComparisonCapabilities (..), Config, Routes (..), SourceName)
|
||||
import Servant.API (NamedRoutes)
|
||||
import Servant.Client (Client)
|
||||
import Test.Hspec
|
||||
@ -20,5 +20,5 @@ spec api sourceName config capabilities@Capabilities {..} = do
|
||||
Test.QuerySpec.FilteringSpec.spec api sourceName config _cComparisons
|
||||
Test.QuerySpec.OrderBySpec.spec api sourceName config capabilities
|
||||
when (isJust _cRelationships) $
|
||||
Test.QuerySpec.RelationshipsSpec.spec api sourceName config (_cComparisons >>= _ccCrossTableComparisonCapabilities)
|
||||
Test.QuerySpec.RelationshipsSpec.spec api sourceName config (_cComparisons >>= _ccSubqueryComparisonCapabilities)
|
||||
Test.QuerySpec.AggregatesSpec.spec api sourceName config _cRelationships
|
||||
|
@ -163,7 +163,7 @@ spec api sourceName config comparisonCapabilities = describe "Filtering in Queri
|
||||
Data.responseRows receivedAlbums `rowsShouldBe` expectedAlbums
|
||||
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
||||
|
||||
when (isJust $ comparisonCapabilities >>= _ccCrossTableComparisonCapabilities) $
|
||||
when (isJust $ comparisonCapabilities >>= _ccSubqueryComparisonCapabilities) $
|
||||
describe "Comparisons in unrelated tables" $ do
|
||||
describe "can filter with a condition that requires that matching rows exist in another unrelated table" $ do
|
||||
describe "compare against a single column" $ do
|
||||
@ -218,92 +218,92 @@ spec api sourceName config comparisonCapabilities = describe "Filtering in Queri
|
||||
Data.responseRows receivedAlbums `rowsShouldBe` []
|
||||
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
||||
|
||||
when ((comparisonCapabilities >>= _ccCrossTableComparisonCapabilities <&> _ctccSupportsRelations) == Just True) $
|
||||
describe "Comparisons in related tables" $ do
|
||||
it "can filter by comparing against rows in a related table" $ do
|
||||
let where' =
|
||||
Exists (RelatedTable Data.artistRelationshipName) $
|
||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Name") (ScalarValue (String "AC/DC"))
|
||||
let query =
|
||||
albumsQueryRequest
|
||||
& qrTableRelationships .~ [Data.onlyKeepRelationships [Data.artistRelationshipName] Data.albumsTableRelationships]
|
||||
& qrQuery . qWhere ?~ where'
|
||||
receivedAlbums <- Data.sortResponseRowsBy "AlbumId" <$> (api // _query) sourceName config query
|
||||
when ((comparisonCapabilities >>= _ccSubqueryComparisonCapabilities <&> _ctccSupportsRelations) == Just True) $
|
||||
describe "Comparisons in related tables" $ do
|
||||
it "can filter by comparing against rows in a related table" $ do
|
||||
let where' =
|
||||
Exists (RelatedTable Data.artistRelationshipName) $
|
||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Name") (ScalarValue (String "AC/DC"))
|
||||
let query =
|
||||
albumsQueryRequest
|
||||
& qrTableRelationships .~ [Data.onlyKeepRelationships [Data.artistRelationshipName] Data.albumsTableRelationships]
|
||||
& qrQuery . qWhere ?~ where'
|
||||
receivedAlbums <- Data.sortResponseRowsBy "AlbumId" <$> (api // _query) sourceName config query
|
||||
|
||||
let artistId =
|
||||
Data.artistsRows
|
||||
& find (\artist -> (artist ^? Data.field "Name" . Data._ColumnFieldString) == Just "AC/DC")
|
||||
>>= (^? Data.field "ArtistId" . Data._ColumnFieldNumber)
|
||||
let artistId =
|
||||
Data.artistsRows
|
||||
& find (\artist -> (artist ^? Data.field "Name" . Data._ColumnFieldString) == Just "AC/DC")
|
||||
>>= (^? Data.field "ArtistId" . Data._ColumnFieldNumber)
|
||||
|
||||
let albums =
|
||||
Data.albumsRows
|
||||
& filter (\album -> (album ^? Data.field "ArtistId" . Data._ColumnFieldNumber) == artistId)
|
||||
& sortOn (^? Data.field "AlbumId")
|
||||
let albums =
|
||||
Data.albumsRows
|
||||
& filter (\album -> (album ^? Data.field "ArtistId" . Data._ColumnFieldNumber) == artistId)
|
||||
& sortOn (^? Data.field "AlbumId")
|
||||
|
||||
Data.responseRows receivedAlbums `rowsShouldBe` albums
|
||||
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
||||
Data.responseRows receivedAlbums `rowsShouldBe` albums
|
||||
_qrAggregates receivedAlbums `jsonShouldBe` Nothing
|
||||
|
||||
it "can filter by comparing against rows in a deeply related table" $ do
|
||||
let where' =
|
||||
Exists (RelatedTable Data.albumsRelationshipName) . Exists (RelatedTable Data.tracksRelationshipName) . Exists (RelatedTable Data.genreRelationshipName) $
|
||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Name") (ScalarValue (String "Metal"))
|
||||
let query =
|
||||
artistsQueryRequest
|
||||
& qrTableRelationships
|
||||
.~ [ Data.onlyKeepRelationships [Data.albumsRelationshipName] Data.artistsTableRelationships,
|
||||
Data.onlyKeepRelationships [Data.tracksRelationshipName] Data.albumsTableRelationships,
|
||||
Data.onlyKeepRelationships [Data.genreRelationshipName] Data.tracksTableRelationships
|
||||
]
|
||||
& qrQuery . qWhere ?~ where'
|
||||
receivedArtists <- Data.sortResponseRowsBy "ArtistId" <$> (api // _query) sourceName config query
|
||||
it "can filter by comparing against rows in a deeply related table" $ do
|
||||
let where' =
|
||||
Exists (RelatedTable Data.albumsRelationshipName) . Exists (RelatedTable Data.tracksRelationshipName) . Exists (RelatedTable Data.genreRelationshipName) $
|
||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Name") (ScalarValue (String "Metal"))
|
||||
let query =
|
||||
artistsQueryRequest
|
||||
& qrTableRelationships
|
||||
.~ [ Data.onlyKeepRelationships [Data.albumsRelationshipName] Data.artistsTableRelationships,
|
||||
Data.onlyKeepRelationships [Data.tracksRelationshipName] Data.albumsTableRelationships,
|
||||
Data.onlyKeepRelationships [Data.genreRelationshipName] Data.tracksTableRelationships
|
||||
]
|
||||
& qrQuery . qWhere ?~ where'
|
||||
receivedArtists <- Data.sortResponseRowsBy "ArtistId" <$> (api // _query) sourceName config query
|
||||
|
||||
let genreId =
|
||||
Data.genresRows
|
||||
& find (\genre -> (genre ^? Data.field "Name" . Data._ColumnFieldString) == Just "Metal")
|
||||
>>= (^? Data.field "GenreId" . Data._ColumnFieldNumber)
|
||||
let genreId =
|
||||
Data.genresRows
|
||||
& find (\genre -> (genre ^? Data.field "Name" . Data._ColumnFieldString) == Just "Metal")
|
||||
>>= (^? Data.field "GenreId" . Data._ColumnFieldNumber)
|
||||
|
||||
let albumIds =
|
||||
Data.tracksRows
|
||||
& filter (\track -> (track ^? Data.field "GenreId" . Data._ColumnFieldNumber) == genreId)
|
||||
& map (\track -> (track ^? Data.field "AlbumId" . Data._ColumnFieldNumber))
|
||||
& HashSet.fromList
|
||||
let albumIds =
|
||||
Data.tracksRows
|
||||
& filter (\track -> (track ^? Data.field "GenreId" . Data._ColumnFieldNumber) == genreId)
|
||||
& map (\track -> (track ^? Data.field "AlbumId" . Data._ColumnFieldNumber))
|
||||
& HashSet.fromList
|
||||
|
||||
let artists =
|
||||
Data.albumsRows
|
||||
& filter (\album -> HashSet.member (album ^? Data.field "AlbumId" . Data._ColumnFieldNumber) albumIds)
|
||||
& mapMaybe (\album -> album ^? Data.field "ArtistId" . Data._ColumnFieldNumber)
|
||||
& HashSet.fromList
|
||||
& HashSet.toList
|
||||
& mapMaybe (\artistId -> HashMap.lookup artistId Data.artistsRowsById)
|
||||
& sortOn (^? Data.field "ArtistId")
|
||||
let artists =
|
||||
Data.albumsRows
|
||||
& filter (\album -> HashSet.member (album ^? Data.field "AlbumId" . Data._ColumnFieldNumber) albumIds)
|
||||
& mapMaybe (\album -> album ^? Data.field "ArtistId" . Data._ColumnFieldNumber)
|
||||
& HashSet.fromList
|
||||
& HashSet.toList
|
||||
& mapMaybe (\artistId -> HashMap.lookup artistId Data.artistsRowsById)
|
||||
& sortOn (^? Data.field "ArtistId")
|
||||
|
||||
Data.responseRows receivedArtists `rowsShouldBe` artists
|
||||
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
||||
Data.responseRows receivedArtists `rowsShouldBe` artists
|
||||
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
||||
|
||||
it "can filter by comparing against multiple columns in a related table" $ do
|
||||
let where' =
|
||||
Exists (RelatedTable Data.albumsRelationshipName) $
|
||||
And
|
||||
[ ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "AlbumId") (ScalarValue (Number 1)),
|
||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Title") (ScalarValue (String "Let There Be Rock"))
|
||||
]
|
||||
let query =
|
||||
artistsQueryRequest
|
||||
& qrTableRelationships .~ [Data.onlyKeepRelationships [Data.albumsRelationshipName] Data.artistsTableRelationships]
|
||||
& qrQuery . qWhere ?~ where'
|
||||
receivedArtists <- Data.sortResponseRowsBy "ArtistId" <$> (api // _query) sourceName config query
|
||||
it "can filter by comparing against multiple columns in a related table" $ do
|
||||
let where' =
|
||||
Exists (RelatedTable Data.albumsRelationshipName) $
|
||||
And
|
||||
[ ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "AlbumId") (ScalarValue (Number 1)),
|
||||
ApplyBinaryComparisonOperator Equal (Data.currentComparisonColumn "Title") (ScalarValue (String "Let There Be Rock"))
|
||||
]
|
||||
let query =
|
||||
artistsQueryRequest
|
||||
& qrTableRelationships .~ [Data.onlyKeepRelationships [Data.albumsRelationshipName] Data.artistsTableRelationships]
|
||||
& qrQuery . qWhere ?~ where'
|
||||
receivedArtists <- Data.sortResponseRowsBy "ArtistId" <$> (api // _query) sourceName config query
|
||||
|
||||
let albums =
|
||||
Data.albumsRows
|
||||
& filter (\album -> (album ^? Data.field "AlbumId" . Data._ColumnFieldNumber) == Just 1 && (album ^? Data.field "Title" . Data._ColumnFieldString) == Just "Let There Be Rock")
|
||||
let albums =
|
||||
Data.albumsRows
|
||||
& filter (\album -> (album ^? Data.field "AlbumId" . Data._ColumnFieldNumber) == Just 1 && (album ^? Data.field "Title" . Data._ColumnFieldString) == Just "Let There Be Rock")
|
||||
|
||||
let artists =
|
||||
Data.artistsRows
|
||||
& filter (\artist -> isJust $ find (\album -> (album ^? Data.field "ArtistId" . Data._ColumnFieldNumber) == (artist ^? Data.field "ArtistId" . Data._ColumnFieldNumber)) albums)
|
||||
& sortOn (^? Data.field "ArtistId")
|
||||
let artists =
|
||||
Data.artistsRows
|
||||
& filter (\artist -> isJust $ find (\album -> (album ^? Data.field "ArtistId" . Data._ColumnFieldNumber) == (artist ^? Data.field "ArtistId" . Data._ColumnFieldNumber)) albums)
|
||||
& sortOn (^? Data.field "ArtistId")
|
||||
|
||||
Data.responseRows receivedArtists `rowsShouldBe` artists
|
||||
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
||||
Data.responseRows receivedArtists `rowsShouldBe` artists
|
||||
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
||||
|
||||
artistsQueryRequest :: QueryRequest
|
||||
artistsQueryRequest =
|
||||
|
@ -16,8 +16,8 @@ import Test.Expectations (jsonShouldBe, rowsShouldBe)
|
||||
import Test.Hspec (Spec, describe, it)
|
||||
import Prelude
|
||||
|
||||
spec :: Client IO (NamedRoutes Routes) -> SourceName -> Config -> Maybe CrossTableComparisonCapabilities -> Spec
|
||||
spec api sourceName config crossTableComparisonCapabilities = describe "Relationship Queries" $ do
|
||||
spec :: Client IO (NamedRoutes Routes) -> SourceName -> Config -> Maybe SubqueryComparisonCapabilities -> Spec
|
||||
spec api sourceName config subqueryComparisonCapabilities = describe "Relationship Queries" $ do
|
||||
it "perform an object relationship query by joining artist to albums" $ do
|
||||
let query = albumsWithArtistQuery id
|
||||
receivedAlbums <- Data.sortResponseRowsBy "AlbumId" <$> (api // _query) sourceName config query
|
||||
@ -64,7 +64,7 @@ spec api sourceName config crossTableComparisonCapabilities = describe "Relation
|
||||
Data.responseRows receivedArtists `rowsShouldBe` expectedAlbums
|
||||
_qrAggregates receivedArtists `jsonShouldBe` Nothing
|
||||
|
||||
when ((_ctccSupportsRelations <$> crossTableComparisonCapabilities) == Just True) $
|
||||
when ((_ctccSupportsRelations <$> subqueryComparisonCapabilities) == Just True) $
|
||||
describe "Cross related table comparisons" $ do
|
||||
it "perform an object relationship query by joining employee to customers and filter comparing columns across the object relationship" $ do
|
||||
-- Join Employee to Customers via SupportRep, and only get those customers that have a rep
|
||||
|
@ -42,7 +42,7 @@ capabilities =
|
||||
API._cComparisons =
|
||||
Just
|
||||
API.ComparisonCapabilities
|
||||
{ API._ccCrossTableComparisonCapabilities = Just API.CrossTableComparisonCapabilities {API._ctccSupportsRelations = True}
|
||||
{ API._ccSubqueryComparisonCapabilities = Just API.SubqueryComparisonCapabilities {API._ctccSupportsRelations = True}
|
||||
},
|
||||
API._cMetrics = Just API.MetricsCapabilities {},
|
||||
API._cExplain = Just API.ExplainCapabilities {}
|
||||
|
@ -53,7 +53,7 @@ defaultBackendCapabilities = \case
|
||||
[yaml|
|
||||
relationships: {}
|
||||
comparisons:
|
||||
cross_table:
|
||||
subquery:
|
||||
supports_relations: true
|
||||
explain: {}
|
||||
metrics: {}
|
||||
@ -71,7 +71,7 @@ defaultBackendCapabilities = \case
|
||||
}
|
||||
relationships: {}
|
||||
comparisons:
|
||||
cross_table:
|
||||
subquery:
|
||||
supports_relations: true
|
||||
scalar_types:
|
||||
DateTime:
|
||||
|
Loading…
Reference in New Issue
Block a user