1
Fork 0
mirror of https://github.com/Airsequel/AirGQL.git synced 2025-08-13 10:16:57 +03:00

Do not allow views to be mutated

This commit is contained in:
prescientmoon 2024-11-08 13:09:47 +01:00
commit c161fbd288
2 changed files with 25 additions and 10 deletions

View file

@ -109,7 +109,8 @@ import AirGQL.Lib (
AccessMode (ReadAndWrite, ReadOnly, WriteOnly),
ColumnEntry (column_name, datatype, datatype_gql),
GqlTypeName (root),
TableEntry (columns, name),
ObjectType (Table),
TableEntry (columns, name, object_type),
column_name_gql,
getColumns,
)
@ -124,6 +125,7 @@ import AirGQL.Types.SchemaConf (
import AirGQL.Types.Utils (encodeToText)
import AirGQL.Utils (colToFileUrl, collectErrorList, quoteKeyword, quoteText)
import Data.Either.Extra qualified as Either
import Data.List qualified as List
typeNameToScalarType :: Maybe GqlTypeName -> ScalarType
@ -618,7 +620,7 @@ queryType connection accessMode dbId tables = do
getResolvers = do
let
-- Exceptions must be converted to ResolverExceptions
-- to be picked up by GQL query executor
-- to be picked up by the GQL query executor
wrapResolver :: Out.Resolve IO -> Out.Resolve IO
wrapResolver resolver =
catchAll
@ -1615,10 +1617,16 @@ mutationType connection maxRowsPerTable accessMode dbId tables = do
getTableTuples :: IO [(Text, Resolver IO)]
getTableTuples =
sequence $
(tables <&> getInsertTableTuple)
<> (tables <&> getUpdateTableTuple)
<> (tables <&> getDeleteTableTuple)
let
tablesWithoutViews =
List.filter
(\table -> table.object_type == Table)
tables
in
sequence $
(tablesWithoutViews <&> getInsertTableTuple)
<> (tablesWithoutViews <&> getUpdateTableTuple)
<> (tablesWithoutViews <&> getDeleteTableTuple)
getTableTuples <&> HashMap.fromList

View file

@ -17,6 +17,7 @@ import Protolude (
($),
(&),
(<&>),
(==),
)
import Protolude qualified as P
@ -34,7 +35,8 @@ import AirGQL.Lib (
AccessMode,
ColumnEntry (isRowid, primary_key),
GqlTypeName (full),
TableEntry (columns, name),
ObjectType (Table),
TableEntry (columns, name, object_type),
canRead,
canWrite,
column_name_gql,
@ -354,13 +356,18 @@ getSchema accessMode tables = do
]
else []
tablesWithoutViews =
List.filter
(\table -> table.object_type == Table)
tables
mutationType =
if canWrite accessMode
then
P.fold
[ tables <&> tableInsertField accessMode
, tables <&> tableUpdateField accessMode
, tables <&> tableDeleteField accessMode
[ tablesWithoutViews <&> tableInsertField accessMode
, tablesWithoutViews <&> tableUpdateField accessMode
, tablesWithoutViews <&> tableDeleteField accessMode
]
else []