1 {-# LANGUAGE DeriveAnyClass #-}
3 module Gargantext.API.GraphQL.User where
5 import Data.Either (Either(..))
6 import Data.Maybe (fromMaybe)
7 import Data.Morpheus.Types
12 import Gargantext.API.Prelude (GargM, GargError)
13 import Gargantext.Database.Prelude (Cmd, HasConnectionPool, HasConfig)
14 import Gargantext.Database.Query.Table.User (getUsersWithId)
15 import Gargantext.Database.Schema.User (UserLight)
16 import Gargantext.Prelude
17 import GHC.Generics (Generic)
18 import qualified Prelude as Prelude
21 -- | Arguments to the "user" query.
25 , includeHyperdata :: Maybe Bool
26 } deriving (Generic, GQLType)
29 -- | Function to resolve user from a query.
31 :: (HasConnectionPool env, HasConfig env)
32 => UserArgs -> ResolverQ e (GargM env GargError) [UserLight]
33 resolveUsers UserArgs { user_id, includeHyperdata } = do
34 let _hyp = fromMaybe False includeHyperdata
35 liftEither $ dbUsers user_id
36 -- user <- lift $ dbUser user_id
38 -- --Left err -> failure $ msg err
39 -- Left err -> error "fail"
42 -- | Inner function to fetch the user from DB.
43 dbUsers :: Int -> Cmd err (Either Prelude.String [UserLight])
45 users <- getUsersWithId user_id