mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
b4f89569c8
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4467 GitOrigin-RevId: 5e81d8581197c90ad2de9106e724c63d7592ae72
90 lines
3.4 KiB
Haskell
90 lines
3.4 KiB
Haskell
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
module Hasura.Backends.DataConnector.Agent.Data
|
|
( Row (..),
|
|
StaticData (..),
|
|
schema,
|
|
staticData,
|
|
)
|
|
where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Data.Aeson (FromJSON)
|
|
import Data.Aeson qualified as J
|
|
import Data.ByteString.Lazy qualified as BL
|
|
import Data.FileEmbed (embedFile, makeRelativeToProject)
|
|
import Data.HashMap.Strict (HashMap)
|
|
import Data.HashMap.Strict qualified as Map
|
|
import Data.Maybe (fromJust)
|
|
import Hasura.Backends.DataConnector.API qualified as API
|
|
import Prelude
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
newtype Row = Row {unRow :: HashMap API.ColumnName API.Value}
|
|
deriving stock (Show)
|
|
deriving newtype (FromJSON)
|
|
|
|
newtype StaticData = StaticData (HashMap API.TableName [Row])
|
|
deriving stock (Show)
|
|
deriving newtype (FromJSON)
|
|
|
|
staticData :: StaticData
|
|
staticData = fromJust $ do
|
|
albums <- J.decode $ BL.fromStrict $(makeRelativeToProject "src-dc-api/Hasura/Backends/DataConnector/Agent/Albums.json" >>= embedFile)
|
|
artists <- J.decode $ BL.fromStrict $(makeRelativeToProject "src-dc-api/Hasura/Backends/DataConnector/Agent/Artists.json" >>= embedFile)
|
|
pure $ StaticData $ Map.fromList [(API.TableName "albums", albums), (API.TableName "artists", artists)]
|
|
|
|
schema :: API.SchemaResponse
|
|
schema =
|
|
API.SchemaResponse
|
|
{ API.srCapabilities = API.Capabilities {API.dcRelationships = True},
|
|
API.srTables =
|
|
[ API.TableInfo
|
|
{ API.dtiName = API.TableName "artists",
|
|
API.dtiColumns =
|
|
[ API.ColumnInfo
|
|
{ API.dciName = API.ColumnName "id",
|
|
API.dciType = API.NumberTy,
|
|
API.dciNullable = False,
|
|
API.dciDescription = Just "Artist primary key identifier"
|
|
},
|
|
API.ColumnInfo
|
|
{ API.dciName = API.ColumnName "name",
|
|
API.dciType = API.StringTy,
|
|
API.dciNullable = False,
|
|
API.dciDescription = Just "The name of the artist"
|
|
}
|
|
],
|
|
API.dtiPrimaryKey = Just "id",
|
|
API.dtiDescription = Just "Collection of artists of music"
|
|
},
|
|
API.TableInfo
|
|
{ API.dtiName = API.TableName "albums",
|
|
API.dtiColumns =
|
|
[ API.ColumnInfo
|
|
{ API.dciName = API.ColumnName "id",
|
|
API.dciType = API.NumberTy,
|
|
API.dciNullable = False,
|
|
API.dciDescription = Just "Album primary key identifier"
|
|
},
|
|
API.ColumnInfo
|
|
{ API.dciName = API.ColumnName "title",
|
|
API.dciType = API.StringTy,
|
|
API.dciNullable = False,
|
|
API.dciDescription = Just "The title of the album"
|
|
},
|
|
API.ColumnInfo
|
|
{ API.dciName = API.ColumnName "artist_id",
|
|
API.dciType = API.NumberTy,
|
|
API.dciNullable = False,
|
|
API.dciDescription = Just "The ID of the artist that created the album"
|
|
}
|
|
],
|
|
API.dtiPrimaryKey = Just "id",
|
|
API.dtiDescription = Just "Collection of music albums created by artists"
|
|
}
|
|
]
|
|
}
|