1 {-# LANGUAGE DeriveAnyClass #-}
3 module Gargantext.API.GraphQL.User where
5 import Data.Maybe (listToMaybe)
6 import Data.Morpheus.Types
11 import Data.Text (Text)
12 import Gargantext.API.Prelude (GargM, GargError)
13 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataUser(..))
14 import Gargantext.Database.Prelude (CmdCommon)
15 import Gargantext.Database.Query.Table.User (getUsersWithId, getUserHyperdata)
16 import Gargantext.Database.Schema.User (UserLight(..))
17 import Gargantext.Prelude
18 import GHC.Generics (Generic)
22 , u_hyperdata :: m (Maybe HyperdataUser)
24 , u_username :: Text }
25 deriving (Generic, GQLType)
27 -- | Arguments to the "user" query.
31 } deriving (Generic, GQLType)
33 type GqlM e env = Resolver QUERY e (GargM env GargError)
35 -- | Function to resolve user from a query.
38 => UserArgs -> GqlM e env [User (GqlM e env)]
39 resolveUsers UserArgs { user_id } = dbUsers user_id
41 -- | Inner function to fetch the user from DB.
44 => Int -> GqlM e env [User (GqlM e env)]
45 dbUsers user_id = lift (map toUser <$> getUsersWithId user_id)
49 => UserLight -> User (GqlM e env)
50 toUser (UserLight { .. }) = User { u_email = userLight_email
51 , u_hyperdata = resolveHyperdata userLight_id
53 , u_username = userLight_username }
57 => Int -> GqlM e env (Maybe HyperdataUser)
58 resolveHyperdata userid = lift (listToMaybe <$> getUserHyperdata userid)