Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
199
Issues
199
List
Board
Labels
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
2dc0600b
Commit
2dc0600b
authored
Oct 07, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[graphql] (does not compile) attempt to lift to GargServer
parent
d0f938b1
Pipeline
#1942
failed with stage
in 10 minutes and 52 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
24 deletions
+47
-24
package.yaml
package.yaml
+2
-0
GraphQL.hs
src/Gargantext/API/GraphQL.hs
+36
-21
Server.hs
src/Gargantext/API/Server.hs
+5
-1
User.hs
src/Gargantext/Database/Schema/User.hs
+4
-2
No files found.
package.yaml
View file @
2dc0600b
...
@@ -171,6 +171,8 @@ library:
...
@@ -171,6 +171,8 @@ library:
-
monad-control
-
monad-control
-
monad-logger
-
monad-logger
-
morpheus-graphql
-
morpheus-graphql
-
morpheus-graphql-app
-
morpheus-graphql-core
-
morpheus-graphql-subscriptions
-
morpheus-graphql-subscriptions
-
mtl
-
mtl
-
natural-transformation
-
natural-transformation
...
...
src/Gargantext/API/GraphQL.hs
View file @
2dc0600b
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DuplicateRecordFields #-}
-- permit duplications for field names in multiple constructors
{-# LANGUAGE DuplicateRecordFields #-}
-- permit duplications for field names in multiple constructors
{-# LANGUAGE KindSignatures #-}
-- for use of Endpoint (name :: Symbol)
{-# LANGUAGE KindSignatures #-}
-- for use of Endpoint (name :: Symbol)
{-# LANGUAGE PartialTypeSignatures #-}
-- to automatically use suggested type hole signatures during compilation
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module
Gargantext.API.GraphQL
where
module
Gargantext.API.GraphQL
where
import
Control.Monad.Base
(
liftBase
)
import
Control.Monad.IO.Class
(
liftIO
)
import
Control.Monad.IO.Class
(
liftIO
)
import
Data.ByteString.Lazy.Char8
import
Data.ByteString.Lazy.Char8
(
ByteString
(
ByteString
...
@@ -15,6 +17,8 @@ import Data.List.NonEmpty (NonEmpty ((:|)))
...
@@ -15,6 +17,8 @@ import Data.List.NonEmpty (NonEmpty ((:|)))
import
Data.Morpheus
import
Data.Morpheus
(
App
(
App
,
deriveApp
)
,
deriveApp
)
import
Data.Morpheus.App.Internal.Resolving
(
failure
)
import
Data.Morpheus.Server
import
Data.Morpheus.Server
(
httpPlayground
(
httpPlayground
)
)
...
@@ -32,15 +36,22 @@ import Data.Morpheus.Types
...
@@ -32,15 +36,22 @@ import Data.Morpheus.Types
,
GQLType
,
GQLType
,
ResolverQ
,
ResolverQ
,
RootResolver
(
..
)
,
RootResolver
(
..
)
,
Undefined
,
Undefined
(
..
)
,
lift
,
liftEither
,
liftEither
,
publish
,
publish
,
render
,
render
)
)
import
Data.Morpheus.Types.Internal.AST
(
msg
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
qualified
Data.Text.Lazy
as
LT
import
qualified
Data.Text.Lazy
as
LT
import
Data.Text.Lazy.Encoding
(
decodeUtf8
)
import
Data.Text.Lazy.Encoding
(
decodeUtf8
)
import
Data.Typeable
(
Typeable
)
import
Data.Typeable
(
Typeable
)
import
Gargantext.API.Prelude
(
GargServer
)
import
Gargantext.Database.Prelude
(
Cmd
)
import
Gargantext.Database.Query.Table.User
(
getUsersWithId
)
import
Gargantext.Database.Schema.User
(
UserPoly
(
..
),
UserLight
)
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
GHC.TypeLits
import
GHC.TypeLits
import
Network.HTTP.Media
((
//
),
(
/:
))
import
Network.HTTP.Media
((
//
),
(
/:
))
...
@@ -60,25 +71,17 @@ import Servant
...
@@ -60,25 +71,17 @@ import Servant
Server
,
Server
,
)
)
import
Prelude
import
Prelude
import
Gargantext.Database.Prelude
(
Cmd
)
-- | Our simple datatype.
data
User
=
User
{
name
::
Text
,
user_id
::
Int
}
deriving
(
Generic
,
GQLType
)
-- | Represents possible GraphQL queries.
-- | Represents possible GraphQL queries.
data
Query
m
data
Query
m
=
Query
=
Query
{
user
::
UserArgs
->
m
User
{
user
::
UserArgs
->
m
User
Light
}
deriving
(
Generic
,
GQLType
)
}
deriving
(
Generic
,
GQLType
)
-- | Arguments to the "user" query.
-- | Arguments to the "user" query.
data
UserArgs
data
UserArgs
=
UserArgs
=
UserArgs
{
name
::
Tex
t
{
user_id
::
In
t
}
deriving
(
Generic
,
GQLType
)
}
deriving
(
Generic
,
GQLType
)
-- | Possible GraphQL Events, i.e. here we describe how we will
-- | Possible GraphQL Events, i.e. here we describe how we will
...
@@ -93,12 +96,12 @@ data Channel
...
@@ -93,12 +96,12 @@ data Channel
-- | This type describes what data we will operate on.
-- | This type describes what data we will operate on.
data
Contet
data
Contet
=
UserContet
User
=
UserContet
User
Light
-- | The main GraphQL resolver: how queries, mutations and
-- | The main GraphQL resolver: how queries, mutations and
-- subscriptions are handled.
-- subscriptions are handled.
rootResolver
::
RootResolver
IO
EVENT
Query
Undefined
Undefined
rootResolver
::
RootResolver
_
EVENT
Query
Undefined
Undefined
rootResolver
=
rootResolver
=
RootResolver
RootResolver
{
queryResolver
=
Query
{
user
=
resolveUser
}
{
queryResolver
=
Query
{
user
=
resolveUser
}
...
@@ -106,15 +109,25 @@ rootResolver =
...
@@ -106,15 +109,25 @@ rootResolver =
,
subscriptionResolver
=
Undefined
}
,
subscriptionResolver
=
Undefined
}
-- | Function to resolve user from a query.
-- | Function to resolve user from a query.
resolveUser
::
UserArgs
->
ResolverQ
e
IO
User
resolveUser
::
UserArgs
->
ResolverQ
e
_
UserLight
resolveUser
UserArgs
{
name
}
=
liftEither
$
dbUser
name
resolveUser
UserArgs
{
user_id
}
=
do
liftEither
$
dbUser
user_id
-- user <- lift $ dbUser user_id
-- case user of
-- --Left err -> failure $ msg err
-- Left err -> error "fail"
-- Right u -> pure u
-- | Inner function to fetch the user from DB.
-- | Inner function to fetch the user from DB.
dbUser
::
Text
->
IO
(
Either
String
User
)
dbUser
::
Int
->
Cmd
err
(
Either
String
UserLight
)
dbUser
name
=
pure
$
Right
$
User
{
name
,
user_id
=
1
}
dbUser
user_id
=
do
users
<-
getUsersWithId
user_id
case
users
of
[]
->
pure
$
Left
"User not found"
(
user
:
_
)
->
pure
$
Right
user
-- | Main GraphQL "app".
-- | Main GraphQL "app".
app
::
App
EVENT
IO
app
::
App
EVENT
_
app
=
deriveApp
rootResolver
app
=
deriveApp
rootResolver
----------------------------------------------
----------------------------------------------
...
@@ -127,7 +140,7 @@ data HTML deriving (Typeable)
...
@@ -127,7 +140,7 @@ data HTML deriving (Typeable)
instance
Accept
HTML
where
instance
Accept
HTML
where
contentTypes
_
=
"text"
//
"html"
/:
(
"charset"
,
"utf-8"
)
:|
[
"text"
//
"html"
]
contentTypes
_
=
"text"
//
"html"
/:
(
"charset"
,
"utf-8"
)
:|
[
"text"
//
"html"
]
instance
MimeRender
HTML
ByteString
where
instance
MimeRender
HTML
ByteString
where
mimeRender
_
=
id
mimeRender
_
=
Prelude
.
id
-- | Servant route for the app we defined above.
-- | Servant route for the app we defined above.
type
GQAPI
=
ReqBody
'[
J
SON
]
GQLRequest
:>
Post
'[
J
SON
]
GQLResponse
type
GQAPI
=
ReqBody
'[
J
SON
]
GQLRequest
:>
Post
'[
J
SON
]
GQLResponse
...
@@ -151,7 +164,9 @@ type API = "gql" :> (GQAPI :<|> Playground)
...
@@ -151,7 +164,9 @@ type API = "gql" :> (GQAPI :<|> Playground)
-- withSchema = pure . LT.toStrict . decodeUtf8 . render
-- withSchema = pure . LT.toStrict . decodeUtf8 . render
-- | Implementation of our API.
-- | Implementation of our API.
api
::
Server
API
--api :: Server API
api
::
GargServer
API
api
=
do
api
=
do
--(wsApp, publish') <- liftIO $ webSocketsApp app
--(wsApp, publish') <- liftIO $ webSocketsApp app
(
liftIO
.
httpPubApp
[]
app
)
:<|>
pure
httpPlayground
--(liftIO . httpPubApp [] app) :<|> pure httpPlayground
(
liftBase
.
httpPubApp
[]
app
)
:<|>
pure
httpPlayground
src/Gargantext/API/Server.hs
View file @
2dc0600b
...
@@ -62,7 +62,11 @@ server env = do
...
@@ -62,7 +62,11 @@ server env = do
(
Proxy
::
Proxy
AuthContext
)
(
Proxy
::
Proxy
AuthContext
)
transform
transform
(
serverGargAPI
(
env
^.
hasConfig
.
gc_url_backend_api
))
(
serverGargAPI
(
env
^.
hasConfig
.
gc_url_backend_api
))
:<|>
GraphQL
.
api
:<|>
hoistServerWithContext
(
Proxy
::
Proxy
GraphQL
.
API
)
(
Proxy
::
Proxy
AuthContext
)
transform
GraphQL
.
api
:<|>
frontEndServer
:<|>
frontEndServer
where
where
transform
::
forall
a
.
GargM
env
GargError
a
->
Handler
a
transform
::
forall
a
.
GargM
env
GargError
a
->
Handler
a
...
...
src/Gargantext/Database/Schema/User.hs
View file @
2dc0600b
...
@@ -13,12 +13,14 @@ Functions to deal with users, database side.
...
@@ -13,12 +13,14 @@ Functions to deal with users, database side.
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TemplateHaskell
#-}
module
Gargantext.Database.Schema.User
where
module
Gargantext.Database.Schema.User
where
import
Data.Morpheus.Types
(
GQLType
)
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
import
Data.Time
(
UTCTime
)
import
Data.Time
(
UTCTime
)
import
Gargantext.Prelude
import
Gargantext.Prelude
...
@@ -41,7 +43,7 @@ data UserLight = UserLight { userLight_id :: !Int
...
@@ -41,7 +43,7 @@ data UserLight = UserLight { userLight_id :: !Int
,
userLight_username
::
!
Text
,
userLight_username
::
!
Text
,
userLight_email
::
!
Text
,
userLight_email
::
!
Text
,
userLight_password
::
!
Text
,
userLight_password
::
!
Text
}
deriving
(
Show
,
Generic
)
}
deriving
(
Show
,
Generic
,
GQLType
)
toUserLight
::
UserDB
->
UserLight
toUserLight
::
UserDB
->
UserLight
toUserLight
(
UserDB
id
p
_
_
u
_
_
e
_
_
_
)
=
UserLight
id
u
e
p
toUserLight
(
UserDB
id
p
_
_
u
_
_
e
_
_
_
)
=
UserLight
id
u
e
p
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment