Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest support #3

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions dataseed/MassaliaSchema/Industry/Plant.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
import Protolude
import Data.UUID (UUID, nil)
import Massalia.HasqlExec (dynamicallyParameterizedStatement, use)
import Massalia.SelectionTree (fromMorpheusContext)
import Massalia.SelectionTree (fromMorpheusContextM)
import Massalia.MorpheusTypes
(
GQLType,
Expand All @@ -40,7 +40,6 @@ import Massalia.SQLSelectStruct (
import MassaliaSchema.Industry.PlantInput (queryTest)
import MassaliaSchema.Industry.Truck (Truck)
import MassaliaSchema.Industry.PlantFilter (PlantFilter)
import Data.Morpheus.Types (unsafeInternalContext)
import Massalia.Utils (LocalTime, Day, uuidV4)
import Massalia.UtilsGQL (Paginated, defaultPaginated)
import qualified Massalia.UtilsGQL as Paginated
Expand Down Expand Up @@ -81,14 +80,14 @@ defaultPlant = Plant {
createdAt=Default.timestamptz
}

plantListQuery :: _ => _ -> _ -> _ _ _ IO (Vector Plant)
plantListQuery :: _ => Maybe _ -> Paginated PlantFilter -> m (Vector Plant)
plantListQuery maybePool queryArgs = do
massaliaTree <- fromMorpheusContext <$> unsafeInternalContext
massaliaTree <- fromMorpheusContextM
case maybePool of
Nothing -> pure mempty
Just pool -> lift (exec pool massaliaTree)
Just pool -> liftIO (exec pool massaliaTree)
where
exec :: _ => _ -> _ -> _ (Vector Plant)
exec :: _ => _ -> _ -> IO (Vector Plant)
exec pool validSel = do
let (snippet, result) = queryAndDecoderToQueryFormatAndResultVect $ toSelectQuery validSel queryArgs
let fullSnippet = binaryQueryResult snippet
Expand All @@ -100,8 +99,8 @@ plantListQuery maybePool queryArgs = do
-- statement validSel = queryAndDecoderToSession $ initialSnippet validSel
-- arg = defaultPaginated{Paginated.globalFilter = pure plantFilterTest}

plantListQueryGen :: _ => Paginated PlantFilter -> _ _ _ IO (Vector Plant)
plantListQueryGen :: _ => Paginated PlantFilter -> m (Vector Plant)
plantListQueryGen queryArgs = do
massaliaTree <- fromMorpheusContext <$> unsafeInternalContext
massaliaTree <- fromMorpheusContextM
let (snippet, _) = queryAndDecoderToQueryFormatAndResultVect $ toSelectQuery @_ @Plant massaliaTree queryArgs
pure $ pure defaultPlant{name=snippet} -- a Hack for only generating the query
4 changes: 2 additions & 2 deletions dataseed/MassaliaSchema/Industry/PlantFilter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module MassaliaSchema.Industry.PlantFilter
where

import qualified Data.Aeson as JSON
import Data.Morpheus.Types (GQLType (description))
import Data.Morpheus.Types (GQLType(..), directives, typeDirective, Describe (Describe))
import Massalia.Filter
( GQLFilterDay,
GQLFilterText,
Expand Down Expand Up @@ -62,7 +62,7 @@ data PlantFilter = PlantFilter
)

instance GQLType PlantFilter where
description = const $ Just ("A set of filters for the Plant type" :: Text)
directives _ = typeDirective (Describe "A set of filters for the Plant type")

instance SQLDecoder (Paginated PlantFilter) [Truck] where
sqlExpr = basicDecodeListSubquery contextSwitch joinFn
Expand Down
5 changes: 2 additions & 3 deletions dataseed/MassaliaSchema/Industry/TruckFilter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import Massalia.SQLClass (
SQLFilter,
SQLFilterField(filterStruct)
)
import Data.Morpheus.Types (GQLType(description), KIND)
import Data.Morpheus.Kind (INPUT)
import Data.Morpheus.Types (GQLType(..), directives, typeDirective, Describe (Describe), KIND)
import Protolude

data TruckFilter
Expand All @@ -67,7 +66,7 @@ testInstance =
}

instance GQLType TruckFilter where
description = const $ Just ("A set of filters for the Truck type" :: Text)
directives _ = typeDirective (Describe "A set of filters for the Truck type")

instance MassaliaContext TruckFilter where
getDecodeOption = const mempty
Expand Down
15 changes: 9 additions & 6 deletions dataseed/MassaliaSchema/TestAPI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}

module MassaliaSchema.TestAPI where

Expand All @@ -16,6 +18,9 @@ import Data.Morpheus.Types
RootResolver (..),
GQLType,
Undefined (..),
defaultRootResolver,
Resolver,
QUERY
)
import MassaliaSchema.Industry.Plant (Plant, plantListQuery, plantListQueryGen)
import MassaliaSchema.Industry.PlantFilter (PlantFilter)
Expand All @@ -28,12 +33,10 @@ api dbConnectionPool = interpreter $ rootResolver (Just dbConnectionPool)
apiWithoutDB :: GQLRequest -> IO GQLResponse
apiWithoutDB = interpreter $ rootResolver Nothing

rootResolver :: Maybe Pool -> RootResolver IO () Query Undefined Undefined
rootResolver :: _ => Maybe Pool -> RootResolver m () Query Undefined Undefined
rootResolver dbConnectionPool =
RootResolver
{ queryResolver = rootQuery dbConnectionPool,
mutationResolver = Undefined,
subscriptionResolver = Undefined
defaultRootResolver
{ queryResolver = rootQuery dbConnectionPool
}

-- data Mutation m
Expand All @@ -49,7 +52,7 @@ data Query m
}
deriving (Generic, GQLType)

rootQuery :: (Maybe Pool) -> Query (_ _ () IO)
rootQuery :: _ => (Maybe Pool) -> Query m
rootQuery dbConnectionPool =
Query
{ plantListPaginated = plantListQuery dbConnectionPool,
Expand Down
35 changes: 23 additions & 12 deletions massalia.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.33.0.
-- This file has been generated from package.yaml by hpack version 0.35.1.
--
-- see: https://github.com/sol/hpack
--
-- hash: 5dfd5e0742455ad37a16aaee97c35e8222b5a2982e42407851cc89cfd777ce6e
-- hash: 2ab94fbd39fc1fb8c1db68ea1da00ebc7d8a2155991a5cf4f055836d4fb26504

name: massalia
version: 0.1.0.0
Expand Down Expand Up @@ -41,6 +41,7 @@ library
Massalia.MorpheusTypes
Massalia.MRange
Massalia.QueryFormat
Massalia.RESTSchema
Massalia.SelectionTree
Massalia.SQLClass
Massalia.SQLSelectStruct
Expand Down Expand Up @@ -71,13 +72,15 @@ library
, hasql-url
, inflections
, jwt
, morpheus-graphql >=0.16
, morpheus-graphql-core >=0.16
, morpheus-graphql >=0.27
, morpheus-graphql-core >=0.27
, morpheus-graphql-server >=0.27
, mtl
, postgresql-binary
, pretty-simple
, protolude
, range
, scientific
, tasty
, tasty-hunit
, text
Expand Down Expand Up @@ -115,13 +118,15 @@ test-suite doctest
, inflections
, jwt
, massalia
, morpheus-graphql >=0.16
, morpheus-graphql-core >=0.16
, morpheus-graphql >=0.27
, morpheus-graphql-core >=0.27
, morpheus-graphql-server >=0.27
, mtl
, postgresql-binary
, pretty-simple
, protolude
, range
, scientific
, tasty
, tasty-hunit
, text
Expand Down Expand Up @@ -172,13 +177,15 @@ test-suite massalia-integration-test
, jwt
, massalia
, massalia-migration
, morpheus-graphql >=0.16
, morpheus-graphql-core >=0.16
, morpheus-graphql >=0.27
, morpheus-graphql-core >=0.27
, morpheus-graphql-server >=0.27
, mtl
, postgresql-binary
, pretty-simple
, protolude
, range
, scientific
, tasty
, tasty-hunit
, text
Expand Down Expand Up @@ -228,13 +235,15 @@ test-suite massalia-unit-test
, inflections
, jwt
, massalia
, morpheus-graphql >=0.16
, morpheus-graphql-core >=0.16
, morpheus-graphql >=0.27
, morpheus-graphql-core >=0.27
, morpheus-graphql-server >=0.27
, mtl
, postgresql-binary
, pretty-simple
, protolude
, range
, scientific
, tasty
, tasty-hunit
, text
Expand Down Expand Up @@ -281,13 +290,15 @@ benchmark massalia-bench
, inflections
, jwt
, massalia
, morpheus-graphql >=0.16
, morpheus-graphql-core >=0.16
, morpheus-graphql >=0.27
, morpheus-graphql-core >=0.27
, morpheus-graphql-server >=0.27
, mtl
, postgresql-binary
, pretty-simple
, protolude
, range
, scientific
, tasty
, tasty-hunit
, text
Expand Down
5 changes: 4 additions & 1 deletion massalia.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
{
"path": "../morpheus-graphql"
}
]
],
"settings": {
"esbonio.server.enabled": true
}
}
6 changes: 4 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ dependencies:
- filepattern
- filepath
- time
- morpheus-graphql >= 0.16
- morpheus-graphql-core >= 0.16
- morpheus-graphql >= 0.27
- morpheus-graphql-core >= 0.27
- morpheus-graphql-server >= 0.27
- scientific
- these

library:
Expand Down
5 changes: 3 additions & 2 deletions src/Massalia/Auth.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PartialTypeSignatures #-}

-- |
-- Module : Massalia.Auth
Expand Down Expand Up @@ -62,7 +63,7 @@ defaultCheckOptions =
-- | A simple alias to 'checkJWT' with default options.
-- See 'checkJWT'.
defaultCheckJWT ::
Signer ->
_ ->
JWTEncodedString ->
ExceptT JWTError IO JWTClaimsSet
defaultCheckJWT = checkJWT Nothing
Expand All @@ -76,7 +77,7 @@ defaultCheckJWT = checkJWT Nothing
-- It uses @getPOSIXTime@ for the accessing the current time.
checkJWT ::
Maybe CheckOptions ->
Signer ->
VerifySigner ->
JWTEncodedString ->
ExceptT JWTError IO JWTClaimsSet
checkJWT maybeOpt secret (JWTEncodedString inputJWT) = do
Expand Down
7 changes: 3 additions & 4 deletions src/Massalia/HasqlExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import Hasql.Session
import Hasql.Statement
import qualified Hasql.Connection as Connection (Settings)
import Massalia.HasqlConnection (settingsFromURL, URLError)
import Data.Time (NominalDiffTime)

poolFromURLString :: Int -> NominalDiffTime -> String -> IO (Either URLError Pool)
poolFromURLString :: Int -> Maybe Int -> String -> IO (Either URLError Pool)
poolFromURLString poolSize timeout url = eitherURLToPool poolSize timeout $ settingsFromURL url

eitherURLToPool :: Int -> NominalDiffTime -> Either URLError Connection.Settings -> IO (Either URLError Pool)
eitherURLToPool :: Int -> Maybe Int -> Either URLError Connection.Settings -> IO (Either URLError Pool)
eitherURLToPool poolSize timeout input = case input of
Left err -> pure $ Left err
Right settings -> Right <$> acquire (poolSize, timeout, settings)
Right settings -> Right <$> acquire poolSize timeout settings
4 changes: 2 additions & 2 deletions src/Massalia/MorpheusTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where

import qualified Data.Aeson as JSON
import Data.Morpheus.Types.GQLScalar ( EncodeScalar(encodeScalar), DecodeScalar(decodeScalar) )
import Data.Morpheus.Types (GQLType(description), KIND)
import Data.Morpheus.Types (GQLType(..), directives, typeDirective, Describe (Describe), KIND)
import Data.Morpheus.Kind (SCALAR)
import qualified Data.Morpheus.Types as GQLT
import Massalia.Utils (UTCTime,
Expand Down Expand Up @@ -114,7 +114,7 @@ instance GQLType Void where
type KIND Void = SCALAR

instance (Typeable a, GQLType a) => GQLType (SimpleRange a) where
description = const $ Just ("A simple range structure for filtering in postgres, it's ultimately translated as a PostgresRange" :: Text)
directives _ = typeDirective (Describe "A simple range structure for filtering in postgres, it's ultimately translated as a PostgresRange")

instance EncodeScalar Inclusivity where
encodeScalar x = case x of
Expand Down
Loading