]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/GraphQL/User.hs
[graphql] some user work
[gargantext.git] / src / Gargantext / API / GraphQL / User.hs
1 {-# LANGUAGE DeriveAnyClass #-}
2
3 module Gargantext.API.GraphQL.User where
4
5 import Data.Either (Either(..))
6 import Data.Maybe (fromMaybe)
7 import Data.Morpheus.Types
8 ( GQLType
9 , ResolverQ
10 , liftEither
11 )
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
19
20
21 -- | Arguments to the "user" query.
22 data UserArgs
23 = UserArgs
24 { user_id :: Int
25 , includeHyperdata :: Maybe Bool
26 } deriving (Generic, GQLType)
27
28
29 -- | Function to resolve user from a query.
30 resolveUsers
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
37 -- case user of
38 -- --Left err -> failure $ msg err
39 -- Left err -> error "fail"
40 -- Right u -> pure u
41
42 -- | Inner function to fetch the user from DB.
43 dbUsers :: Int -> Cmd err (Either Prelude.String [UserLight])
44 dbUsers user_id = do
45 users <- getUsersWithId user_id
46 pure $ Right users