[graphql] context endpoint implementation

parent a6ec0726
Pipeline #3590 failed with stage
in 0 seconds
......@@ -74,6 +74,7 @@ queryGql session name q = do
type Schema
= { imt_schools :: {} ==> Array GQLIMT.School
, contexts :: { context_id :: Int, node_id :: Int } ==> Array GQLCTX.NodeContext
, contexts_for_ngrams :: { corpus_id :: Int, ngrams_ids :: Array Int } ==> Array GQLCTX.Context
, nodes :: { node_id :: Int } ==> Array Node
, node_parent :: { node_id :: Int, parent_type :: String } ==> Array Node -- TODO: parent_type :: NodeType
, user_infos :: { user_id :: Int } ==> Array UserInfo
......
module Gargantext.Components.GraphQL.Context
( NodeContext
( Context_
, Context
, Hyperdata_
, Hyperdata
, NodeContext
, NodeContext_
, nodeContextQuery
, NodeContextCategoryM
, contextsForNgramsQuery
) where
import Gargantext.Prelude
......@@ -16,6 +21,40 @@ import Type.Proxy (Proxy(..))
import Data.Array as A
type Context_
= ( c_id :: Int
, c_name :: String
, c_typename :: Int
, c_hash_id :: String
, c_user_id :: Int
, c_parent_id :: Int
, c_hyperdata :: Maybe Hyperdata )
type Context = Record Context_
type Hyperdata_
= ( hrd_abstract :: String
, hrd_authors :: String
, hrd_bdd :: String
, hrd_doi :: String
, hrd_institutes :: String
, hrd_language_iso2 :: String
, hrd_page :: Int
, hrd_publication_date :: String
, hrd_publication_day :: Int
, hrd_publication_hour :: Int
, hrd_publication_minute :: Int
, hrd_publication_month :: Int
, hrd_publication_second :: Int
, hrd_publication_year :: Int
, hrd_source :: String
, hrd_title :: String
, hrd_url :: String
, hrd_uniqId :: String
, hrd_uniqIdBdd :: String )
type Hyperdata = Record Hyperdata_
type NodeContext_
= ( nc_id :: Maybe Int
, nc_node_id :: Int
......@@ -44,6 +83,46 @@ nodeContextQuery
GGQL.getFieldsStandard (Proxy :: _ NodeContext)
}
type ContextsForNgramsQuery
= { contexts_for_ngrams :: Args
{ corpus_id :: Var "corpus_id" Int
, ngrams_ids :: Var "ngrams_ids" (Array Int)}
{ c_id :: Unit
, c_name :: Unit
, c_typename :: Unit
, c_hash_id :: Unit
, c_user_id :: Unit
, c_parent_id :: Unit
, c_hyperdata ::
{ hrd_abstract :: Unit
, hrd_authors :: Unit
, hrd_bdd :: Unit
, hrd_doi :: Unit
, hrd_institutes :: Unit
, hrd_language_iso2 :: Unit
, hrd_page :: Unit
, hrd_publication_date :: Unit
, hrd_publication_day :: Unit
, hrd_publication_hour :: Unit
, hrd_publication_minute :: Unit
, hrd_publication_month :: Unit
, hrd_publication_second :: Unit
, hrd_publication_year :: Unit
, hrd_source :: Unit
, hrd_title :: Unit
, hrd_url :: Unit
, hrd_uniqId :: Unit
, hrd_uniqIdBdd :: Unit }
}
}
contextsForNgramsQuery :: ContextsForNgramsQuery
contextsForNgramsQuery
= { contexts_for_ngrams:
{ corpus_id: Var :: _ "corpus_id" Int
, ngrams_ids: Var :: _ "ngrams_ids" (Array Int) } =>>
GGQL.getFieldsStandard (Proxy :: _ Context)
}
------------------------------------------------------------------------
type NodeContextCategoryM
......
......@@ -101,12 +101,19 @@ deleteTeamMembership session sharedFolderId teamNodeId = do
getNodeContext :: Session -> Int -> Int -> AffRESTError GQLCTX.NodeContext
getNodeContext session context_id node_id = do
{ contexts } <- queryGql session "get node context" $ GQLCTX.nodeContextQuery `withVars` { context_id, node_id }
{ contexts } <- queryGql session "get node context" $
GQLCTX.nodeContextQuery `withVars` { context_id, node_id }
--liftEffect $ here.log2 "[getNodeContext] node context" contexts
case A.head contexts of
Nothing -> pure $ Left $ CustomError "no node context found"
Just context -> pure $ Right context -- TODO: error handling
getContextsForNgrams :: Session -> Int -> Array Int -> AffRESTError (Array GQLCTX.Context)
getContextsForNgrams session corpus_id ngrams_ids = do
{ contexts_for_ngrams } <- queryGql session "get contexts for ngrams" $
GQLCTX.contextsForNgramsQuery `withVars` { corpus_id, ngrams_ids }
pure $ Right contexts_for_ngrams
updateNodeContextCategory :: Session -> Int -> Int -> Int -> AffRESTError Int
updateNodeContextCategory session context_id node_id category = do
client <- liftEffect $ getClient session
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment