module PGIP.GraphQL.Resolver.Serialization (resolve) where import PGIP.GraphQL.Resolver.ToResult import PGIP.GraphQL.Result as GraphQLResult import PGIP.Shared import Driver.Options import Persistence.Database import Persistence.Schema as DatabaseSchema import Database.Esqueleto import Control.Monad.IO.Class (MonadIO (..)) resolve :: HetcatsOpts -> Cache -> String -> IO (Maybe GraphQLResult.Result) resolve :: HetcatsOpts -> Cache -> String -> IO (Maybe Result) resolve opts :: HetcatsOpts opts _ idVar :: String idVar = DBConfig -> DBMonad (NoLoggingT IO) (Maybe Result) -> IO (Maybe Result) forall (m :: * -> *) a. (MonadIO m, MonadBaseControl IO m, MonadUnliftIO m, MonadFail m) => DBConfig -> DBMonad (NoLoggingT m) a -> m a onDatabase (HetcatsOpts -> DBConfig databaseConfig HetcatsOpts opts) (DBMonad (NoLoggingT IO) (Maybe Result) -> IO (Maybe Result)) -> DBMonad (NoLoggingT IO) (Maybe Result) -> IO (Maybe Result) forall a b. (a -> b) -> a -> b $ String -> DBMonad (NoLoggingT IO) (Maybe Result) forall (m :: * -> *). MonadIO m => String -> DBMonad m (Maybe Result) resolveDB String idVar resolveDB :: MonadIO m => String -> DBMonad m (Maybe GraphQLResult.Result) resolveDB :: String -> DBMonad m (Maybe Result) resolveDB idVar :: String idVar = do [(Entity Serialization, Entity Language)] serializationL <- SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language)) -> ReaderT SqlBackend m [(Entity Serialization, Entity Language)] forall a r (m :: * -> *). (SqlSelect a r, MonadIO m) => SqlQuery a -> SqlReadT m [r] select (SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language)) -> ReaderT SqlBackend m [(Entity Serialization, Entity Language)]) -> SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language)) -> ReaderT SqlBackend m [(Entity Serialization, Entity Language)] forall a b. (a -> b) -> a -> b $ (InnerJoin (SqlExpr (Entity Serialization)) (SqlExpr (Entity Language)) -> SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language))) -> SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language)) forall a b. From a => (a -> SqlQuery b) -> SqlQuery b from ((InnerJoin (SqlExpr (Entity Serialization)) (SqlExpr (Entity Language)) -> SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language))) -> SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language))) -> (InnerJoin (SqlExpr (Entity Serialization)) (SqlExpr (Entity Language)) -> SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language))) -> SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language)) forall a b. (a -> b) -> a -> b $ \(serializations :: SqlExpr (Entity Serialization) serializations `InnerJoin` languages :: SqlExpr (Entity Language) languages) -> do SqlExpr (Value Bool) -> SqlQuery () on (SqlExpr (Entity Serialization) serializations SqlExpr (Entity Serialization) -> EntityField Serialization (Key Language) -> SqlExpr (Value (Key Language)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField Serialization (Key Language) forall typ. (typ ~ Key Language) => EntityField Serialization typ SerializationLanguageId SqlExpr (Value (Key Language)) -> SqlExpr (Value (Key Language)) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. SqlExpr (Entity Language) languages SqlExpr (Entity Language) -> EntityField Language (Key Language) -> SqlExpr (Value (Key Language)) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField Language (Key Language) forall typ. (typ ~ Key Language) => EntityField Language typ LanguageId) SqlExpr (Value Bool) -> SqlQuery () where_ (SqlExpr (Entity Serialization) serializations SqlExpr (Entity Serialization) -> EntityField Serialization String -> SqlExpr (Value String) forall typ val. (PersistEntity val, PersistField typ) => SqlExpr (Entity val) -> EntityField val typ -> SqlExpr (Value typ) ^. EntityField Serialization String forall typ. (typ ~ String) => EntityField Serialization typ SerializationSlug SqlExpr (Value String) -> SqlExpr (Value String) -> SqlExpr (Value Bool) forall typ. PersistField typ => SqlExpr (Value typ) -> SqlExpr (Value typ) -> SqlExpr (Value Bool) ==. String -> SqlExpr (Value String) forall typ. PersistField typ => typ -> SqlExpr (Value typ) val String idVar) (SqlExpr (Entity Serialization), SqlExpr (Entity Language)) -> SqlQuery (SqlExpr (Entity Serialization), SqlExpr (Entity Language)) forall (m :: * -> *) a. Monad m => a -> m a return (SqlExpr (Entity Serialization) serializations, SqlExpr (Entity Language) languages) case [(Entity Serialization, Entity Language)] serializationL of [] -> Maybe Result -> DBMonad m (Maybe Result) forall (m :: * -> *) a. Monad m => a -> m a return Maybe Result forall a. Maybe a Nothing (serializationEntity :: Entity Serialization serializationEntity, languageEntity :: Entity Language languageEntity) : _ -> Maybe Result -> DBMonad m (Maybe Result) forall (m :: * -> *) a. Monad m => a -> m a return (Maybe Result -> DBMonad m (Maybe Result)) -> Maybe Result -> DBMonad m (Maybe Result) forall a b. (a -> b) -> a -> b $ Result -> Maybe Result forall a. a -> Maybe a Just (Result -> Maybe Result) -> Result -> Maybe Result forall a b. (a -> b) -> a -> b $ Serialization -> Result GraphQLResult.SerializationResult (Serialization -> Result) -> Serialization -> Result forall a b. (a -> b) -> a -> b $ Entity Serialization -> Entity Language -> Serialization serializationToResult Entity Serialization serializationEntity Entity Language languageEntity