Skip to content

Commit

Permalink
test array within array
Browse files Browse the repository at this point in the history
  • Loading branch information
hallettj committed Jul 11, 2024
1 parent e1a58eb commit bdb8f2a
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/integration-tests/src/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,27 @@ async fn filters_by_date() -> anyhow::Result<()> {
);
Ok(())
}

#[tokio::test]
async fn selects_array_within_array() -> anyhow::Result<()> {
assert_yaml_snapshot!(
graphql_query(
r#"
query {
artistsWithAlbumsAndTracks(limit: 1, order_by: {id: Asc}) {
name
albums {
title
tracks {
name
}
}
}
}
"#
)
.run()
.await?
);
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: crates/integration-tests/src/tests/basic.rs
expression: "graphql_query(r#\"\n query {\n artistsWithAlbumsAndTracks(limit: 1, order_by: {id: Asc}) {\n name\n albums {\n title\n tracks {\n name\n }\n }\n }\n }\n \"#).run().await?"
---
data:
artistsWithAlbumsAndTracks:
- name: AC/DC
albums:
- title: For Those About To Rock We Salute You
tracks:
- name: "Let's Get It Up"
- name: Inject The Venom
- name: Evil Walks
- name: Snowballed
- name: Breaking The Rules
- name: Spellbound
- name: Night Of The Long Knives
- name: Put The Finger On You
- name: For Those About To Rock (We Salute You)
- name: C.O.D.
- title: Let There Be Rock
tracks:
- name: Go Down
- name: Bad Boy Boogie
- name: Problem Child
- name: Dog Eat Dog
- name: Let There Be Rock
- name: Overdose
- name: "Hell Ain't A Bad Place To Be"
- name: Whole Lotta Rosie
errors: ~
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "artists_with_albums_and_tracks",
"representation": "collection",
"inputCollection": "Artist",
"description": "combines artist, albums, and tracks into a single document per artist",
"resultDocumentType": "ArtistWithAlbumsAndTracks",
"objectTypes": {
"ArtistWithAlbumsAndTracks": {
"fields": {
"_id": { "type": { "scalar": "objectId" } },
"Name": { "type": { "scalar": "string" } },
"Albums": { "type": { "arrayOf": { "object": "AlbumWithTracks" } } }
}
},
"AlbumWithTracks": {
"fields": {
"_id": { "type": { "scalar": "objectId" } },
"Title": { "type": { "scalar": "string" } },
"Tracks": { "type": { "arrayOf": { "object": "Track" } } }
}
}
},
"pipeline": [
{
"$lookup": {
"from": "Album",
"localField": "ArtistId",
"foreignField": "ArtistId",
"as": "Albums",
"pipeline": [
{
"$lookup": {
"from": "Track",
"localField": "AlbumId",
"foreignField": "AlbumId",
"as": "Tracks"
}
},
{
"$replaceWith": {
"_id": "$_id",
"Title": "$Title",
"Tracks": "$Tracks"
}
}
]
}
},
{
"$replaceWith": {
"_id": "$_id",
"Name": "$Name",
"Albums": "$Albums"
}
}
]
}


145 changes: 145 additions & 0 deletions fixtures/hasura/chinook/metadata/ArtistsWithAlbumsAndTracks.hml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
kind: ObjectType
version: v1
definition:
name: AlbumWithTracks
fields:
- name: id
type: Chinook_ObjectId!
- name: title
type: String!
- name: tracks
type: "[Track!]!"
graphql:
typeName: Chinook_AlbumWithTracks
inputTypeName: Chinook_AlbumWithTracksInput
dataConnectorTypeMapping:
- dataConnectorName: chinook
dataConnectorObjectType: AlbumWithTracks
fieldMapping:
id:
column:
name: _id
title:
column:
name: Title
tracks:
column:
name: Tracks

---
kind: TypePermissions
version: v1
definition:
typeName: AlbumWithTracks
permissions:
- role: admin
output:
allowedFields:
- id
- title
- tracks

---
kind: ObjectType
version: v1
definition:
name: ArtistWithAlbumsAndTracks
fields:
- name: id
type: Chinook_ObjectId!
- name: albums
type: "[AlbumWithTracks!]!"
- name: name
type: String!
graphql:
typeName: Chinook_ArtistWithAlbumsAndTracks
inputTypeName: Chinook_ArtistWithAlbumsAndTracksInput
dataConnectorTypeMapping:
- dataConnectorName: chinook
dataConnectorObjectType: ArtistWithAlbumsAndTracks
fieldMapping:
id:
column:
name: _id
albums:
column:
name: Albums
name:
column:
name: Name

---
kind: TypePermissions
version: v1
definition:
typeName: ArtistWithAlbumsAndTracks
permissions:
- role: admin
output:
allowedFields:
- id
- albums
- name

---
kind: ObjectBooleanExpressionType
version: v1
definition:
name: ArtistWithAlbumsAndTracksBoolExp
objectType: ArtistWithAlbumsAndTracks
dataConnectorName: chinook
dataConnectorObjectType: ArtistWithAlbumsAndTracks
comparableFields:
- fieldName: id
operators:
enableAll: true
- fieldName: albums
operators:
enableAll: true
- fieldName: name
operators:
enableAll: true
graphql:
typeName: Chinook_ArtistWithAlbumsAndTracksBoolExp

---
kind: Model
version: v1
definition:
name: ArtistsWithAlbumsAndTracks
objectType: ArtistWithAlbumsAndTracks
source:
dataConnectorName: chinook
collection: artists_with_albums_and_tracks
filterExpressionType: ArtistWithAlbumsAndTracksBoolExp
orderableFields:
- fieldName: id
orderByDirections:
enableAll: true
- fieldName: albums
orderByDirections:
enableAll: true
- fieldName: name
orderByDirections:
enableAll: true
graphql:
selectMany:
queryRootField: artistsWithAlbumsAndTracks
selectUniques:
- queryRootField: artistsWithAlbumsAndTracksById
uniqueIdentifier:
- id
orderByExpressionType: Chinook_ArtistsWithAlbumsAndTracksOrderBy
description: combines artist, albums, and tracks into a single document per artist

---
kind: ModelPermissions
version: v1
definition:
modelName: ArtistsWithAlbumsAndTracks
permissions:
- role: admin
select:
filter: null

41 changes: 41 additions & 0 deletions fixtures/hasura/chinook/metadata/chinook.hml
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,22 @@ definition:
type:
type: named
name: String
AlbumWithTracks:
fields:
_id:
type:
type: named
name: ObjectId
Title:
type:
type: named
name: String
Tracks:
type:
type: array
element_type:
type: named
name: Track
Artist:
description: Object type for collection Artist
fields:
Expand All @@ -553,6 +569,22 @@ definition:
underlying_type:
type: named
name: String
ArtistWithAlbumsAndTracks:
fields:
_id:
type:
type: named
name: ObjectId
Albums:
type:
type: array
element_type:
type: named
name: AlbumWithTracks
Name:
type:
type: named
name: String
Customer:
description: Object type for collection Customer
fields:
Expand Down Expand Up @@ -1017,6 +1049,15 @@ definition:
unique_columns:
- _id
foreign_keys: {}
- name: artists_with_albums_and_tracks
description: combines artist, albums, and tracks into a single document per artist
arguments: {}
type: ArtistWithAlbumsAndTracks
uniqueness_constraints:
artists_with_albums_and_tracks_id:
unique_columns:
- _id
foreign_keys: {}
functions: []
procedures:
- name: insertArtist
Expand Down

0 comments on commit bdb8f2a

Please sign in to comment.