Skip to content

Commit

Permalink
test array within array instead of array within object within array
Browse files Browse the repository at this point in the history
  • Loading branch information
hallettj committed Jul 11, 2024
1 parent bdb8f2a commit 2775c08
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
"name": "artists_with_albums_and_tracks",
"representation": "collection",
"inputCollection": "Artist",
"description": "combines artist, albums, and tracks into a single document per artist",
"description": "combines artist, albums, and tracks into a single document per artist - demonstrates array within array",
"resultDocumentType": "ArtistWithAlbumsAndTracks",
"objectTypes": {
"ArtistWithAlbumsAndTracks": {
"fields": {
"_id": { "type": { "scalar": "objectId" } },
"Name": { "type": { "scalar": "string" } },
"Albums": { "type": { "arrayOf": { "object": "AlbumWithTracks" } } }
"name": { "type": { "scalar": "string" } },
"albums": { "type": { "arrayOf": { "arrayOf": { "object": "TrackWithAlbumTitle" } } } }
}
},
"AlbumWithTracks": {
"TrackWithAlbumTitle": {
"fields": {
"_id": { "type": { "scalar": "objectId" } },
"Title": { "type": { "scalar": "string" } },
"Tracks": { "type": { "arrayOf": { "object": "Track" } } }
"track": { "type": { "scalar": "string" } },
"album": { "type": { "scalar": "string" } }
}
}
},
Expand All @@ -26,21 +25,25 @@
"from": "Album",
"localField": "ArtistId",
"foreignField": "ArtistId",
"as": "Albums",
"as": "albums",
"pipeline": [
{
"$lookup": {
"from": "Track",
"localField": "AlbumId",
"foreignField": "AlbumId",
"as": "Tracks"
}
},
{
"$replaceWith": {
"_id": "$_id",
"Title": "$Title",
"Tracks": "$Tracks"
"let": {
"albumTitle": "$Title"
},
"as": "tracks",
"pipeline": [
{
"$replaceWith": {
"track": "$Name",
"album": "$$albumTitle"
}
}
]
}
}
]
Expand All @@ -49,8 +52,8 @@
{
"$replaceWith": {
"_id": "$_id",
"Name": "$Name",
"Albums": "$Albums"
"name": "$Name",
"albums": { "$map": { "input": "$albums", "in": "$$this.tracks" } }
}
}
]
Expand Down
77 changes: 32 additions & 45 deletions fixtures/hasura/chinook/metadata/ArtistsWithAlbumsAndTracks.hml
Original file line number Diff line number Diff line change
@@ -1,45 +1,3 @@
---
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
Expand All @@ -49,7 +7,7 @@ definition:
- name: id
type: Chinook_ObjectId!
- name: albums
type: "[AlbumWithTracks!]!"
type: "[[TrackWithAlbumTitle!]!]!"
- name: name
type: String!
graphql:
Expand All @@ -64,10 +22,10 @@ definition:
name: _id
albums:
column:
name: Albums
name: albums
name:
column:
name: Name
name: name

---
kind: TypePermissions
Expand Down Expand Up @@ -143,3 +101,32 @@ definition:
select:
filter: null

---
kind: ObjectType
version: v1
definition:
name: TrackWithAlbumTitle
fields:
- name: album
type: String!
- name: track
type: String!
graphql:
typeName: Chinook_TrackWithAlbumTitle
inputTypeName: Chinook_TrackWithAlbumTitleInput
dataConnectorTypeMapping:
- dataConnectorName: chinook
dataConnectorObjectType: TrackWithAlbumTitle

---
kind: TypePermissions
version: v1
definition:
typeName: TrackWithAlbumTitle
permissions:
- role: admin
output:
allowedFields:
- album
- track

38 changes: 17 additions & 21 deletions fixtures/hasura/chinook/metadata/chinook.hml
Original file line number Diff line number Diff line change
Expand Up @@ -536,22 +536,6 @@ 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 @@ -575,13 +559,15 @@ definition:
type:
type: named
name: ObjectId
Albums:
albums:
type:
type: array
element_type:
type: named
name: AlbumWithTracks
Name:
type: array
element_type:
type: named
name: TrackWithAlbumTitle
name:
type:
type: named
name: String
Expand Down Expand Up @@ -960,6 +946,16 @@ definition:
type:
type: named
name: Decimal
TrackWithAlbumTitle:
fields:
album:
type:
type: named
name: String
track:
type:
type: named
name: String
collections:
- name: Album
arguments: {}
Expand Down Expand Up @@ -1050,7 +1046,7 @@ definition:
- _id
foreign_keys: {}
- name: artists_with_albums_and_tracks
description: combines artist, albums, and tracks into a single document per artist
description: combines artist, albums, and tracks into a single document per artist - demonstrates array within array
arguments: {}
type: ArtistWithAlbumsAndTracks
uniqueness_constraints:
Expand Down

0 comments on commit 2775c08

Please sign in to comment.