1
Fork 0
mirror of https://github.com/Airsequel/AirGQL.git synced 2025-09-22 20:14:31 +02:00

Add insertonly endpoint to airgql server

I removed the `readonlyGqlPostHandler` thingy from airgql,
as it seemed to be a slightly worse version of the existing more
general gql post handler. The one difference is that it was trying
to use the readonly db directory, although the token already protected
the queries to reading only, so this didn't matter. Moreover, the
writeonly endpoint was also using the readonly directory, which seemed
like a mistake (I removed that handler as well in favour of passing the
`writeonly` access mode to the existing handler).

I also fixed a TODO, making it so the readonly airsequel-cli handler
takes the edition into account.
This commit is contained in:
prescientmoon 2024-12-07 16:47:39 +01:00
commit 58e3f0bb7b
3 changed files with 15 additions and 42 deletions
source
AirGQL
Server

View file

@ -10,6 +10,7 @@ module AirGQL.Lib (
mkAccessMode, mkAccessMode,
readOnly, readOnly,
writeOnly, writeOnly,
insertOnly,
readAndWrite, readAndWrite,
ColumnEntry (..), ColumnEntry (..),
GqlTypeName (..), GqlTypeName (..),
@ -144,6 +145,10 @@ writeOnly :: AccessMode
writeOnly = mkAccessMode False True True writeOnly = mkAccessMode False True True
insertOnly :: AccessMode
insertOnly = mkAccessMode False True False
readAndWrite :: AccessMode readAndWrite :: AccessMode
readAndWrite = mkAccessMode True True True readAndWrite = mkAccessMode True True True

View file

@ -2,8 +2,6 @@ module AirGQL.Servant.GraphQL (
gqlQueryGetHandler, gqlQueryGetHandler,
gqlQueryPostHandler, gqlQueryPostHandler,
playgroundDefaultQueryHandler, playgroundDefaultQueryHandler,
readOnlyGqlPostHandler,
writeOnlyGqlPostHandler,
) where ) where
import Protolude ( import Protolude (
@ -29,16 +27,13 @@ import AirGQL.Lib (
column_name, column_name,
getColumns, getColumns,
getTableNames, getTableNames,
readOnly,
writeOnly,
) )
import AirGQL.ServerUtils (executeQuery) import AirGQL.ServerUtils (executeQuery)
import AirGQL.Types.SchemaConf (SchemaConf (accessMode), defaultSchemaConf) import AirGQL.Types.SchemaConf (SchemaConf)
import AirGQL.Types.Types (GQLPost (operationName, query, variables)) import AirGQL.Types.Types (GQLPost (operationName, query, variables))
import AirGQL.Utils ( import AirGQL.Utils (
getDbDir, getDbDir,
getMainDbPath, getMainDbPath,
getReadOnlyFilePath,
throwErr400WithMsg, throwErr400WithMsg,
throwErr404WithMsg, throwErr404WithMsg,
withRetryConn, withRetryConn,
@ -93,34 +88,6 @@ gqlQueryPostHandler schemaConf dbIdOrPath gqlPost = do
handleNoDbError handleNoDbError
readOnlyGqlPostHandler :: Text -> GQLPost -> Servant.Handler Object
readOnlyGqlPostHandler dbIdOrPath gqlPost =
liftIO $ do
reqDir <- makeAbsolute $ getReadOnlyFilePath dbIdOrPath
executeQuery
defaultSchemaConf{accessMode = readOnly}
dbIdOrPath
reqDir
gqlPost.query
(gqlPost.variables & P.fromMaybe mempty)
gqlPost.operationName
writeOnlyGqlPostHandler :: Text -> GQLPost -> Servant.Handler Object
writeOnlyGqlPostHandler dbPath gqlPost =
liftIO $ do
reqDir <- makeAbsolute $ getReadOnlyFilePath dbPath
executeQuery
defaultSchemaConf{accessMode = writeOnly}
dbPath
reqDir
gqlPost.query
(gqlPost.variables & P.fromMaybe mempty)
gqlPost.operationName
playgroundDefaultQueryHandler playgroundDefaultQueryHandler
:: Text :: Text
-> Servant.Handler Text -> Servant.Handler Text

View file

@ -56,7 +56,7 @@ import Text.Blaze.Internal (MarkupM)
import AirGQL.Config (Config (maxDbSize), defaultConfig) import AirGQL.Config (Config (maxDbSize), defaultConfig)
import AirGQL.ExternalAppContext (ExternalAppContext) import AirGQL.ExternalAppContext (ExternalAppContext)
import AirGQL.Lib (SQLPost) import AirGQL.Lib (SQLPost, insertOnly, readOnly, writeOnly)
import AirGQL.Servant.Database ( import AirGQL.Servant.Database (
apiDatabaseSchemaGetHandler, apiDatabaseSchemaGetHandler,
apiDatabaseVacuumPostHandler, apiDatabaseVacuumPostHandler,
@ -65,11 +65,9 @@ import AirGQL.Servant.GraphQL (
gqlQueryGetHandler, gqlQueryGetHandler,
gqlQueryPostHandler, gqlQueryPostHandler,
playgroundDefaultQueryHandler, playgroundDefaultQueryHandler,
readOnlyGqlPostHandler,
writeOnlyGqlPostHandler,
) )
import AirGQL.Servant.SqlQuery (sqlQueryPostHandler) import AirGQL.Servant.SqlQuery (sqlQueryPostHandler)
import AirGQL.Types.SchemaConf (SchemaConf (pragmaConf), defaultSchemaConf) import AirGQL.Types.SchemaConf (SchemaConf (accessMode, pragmaConf), defaultSchemaConf)
import AirGQL.Types.SqlQueryPostResult (SqlQueryPostResult) import AirGQL.Types.SqlQueryPostResult (SqlQueryPostResult)
import AirGQL.Types.Types (GQLPost) import AirGQL.Types.Types (GQLPost)
@ -86,16 +84,18 @@ type PlatformAPI =
:> ReqBody '[JSON] GQLPost :> ReqBody '[JSON] GQLPost
:> Post '[JSON] Object :> Post '[JSON] Object
-- writeOnlyGqlPostHandler
:<|> "readonly" :> "graphql" :<|> "readonly" :> "graphql"
:> ReqBody '[JSON] GQLPost :> ReqBody '[JSON] GQLPost
:> Post '[JSON] Object :> Post '[JSON] Object
-- writeOnlyGqlPostHandler
:<|> "writeonly" :> "graphql" :<|> "writeonly" :> "graphql"
:> ReqBody '[JSON] GQLPost :> ReqBody '[JSON] GQLPost
:> Post '[JSON] Object :> Post '[JSON] Object
:<|> "insertonly" :> "graphql"
:> ReqBody '[JSON] GQLPost
:> Post '[JSON] Object
-- playgroundDefaultQueryHandler -- playgroundDefaultQueryHandler
:<|> "playground" :> "default-query" :<|> "playground" :> "default-query"
:> Get '[PlainText] Text :> Get '[PlainText] Text
@ -164,8 +164,9 @@ platformServer ctx filePath = do
let dbPath = T.pack filePath let dbPath = T.pack filePath
gqlQueryGetHandler dbPath gqlQueryGetHandler dbPath
:<|> gqlQueryPostHandler defaultSchemaConf dbPath :<|> gqlQueryPostHandler defaultSchemaConf dbPath
:<|> readOnlyGqlPostHandler dbPath :<|> gqlQueryPostHandler defaultSchemaConf{accessMode = readOnly} dbPath
:<|> writeOnlyGqlPostHandler dbPath :<|> gqlQueryPostHandler defaultSchemaConf{accessMode = writeOnly} dbPath
:<|> gqlQueryPostHandler defaultSchemaConf{accessMode = insertOnly} dbPath
:<|> playgroundDefaultQueryHandler dbPath :<|> playgroundDefaultQueryHandler dbPath
:<|> apiDatabaseSchemaGetHandler ctx dbPath :<|> apiDatabaseSchemaGetHandler ctx dbPath
:<|> apiDatabaseVacuumPostHandler dbPath :<|> apiDatabaseVacuumPostHandler dbPath