1
Fork 0
mirror of https://github.com/Airsequel/AirGQL.git synced 2025-08-14 02:36:57 +03:00

Update schema to be closer to the Hasura one

This commit is contained in:
prescientmoon 2025-04-17 13:03:44 +02:00
commit 71210de300
6 changed files with 49 additions and 3014 deletions
source/AirGQL

View file

@ -992,7 +992,7 @@ mutationType connection maxRowsPerTable accessMode dbId tables = do
let Arguments args = context.arguments
liftIO $ do
filterObj <- getArg "where" ["filter"] args
pairsToSet <- getArg "set" [] args
pairsToSet <- getArg "_set" ["set"] args
(numOfChanges, updatedRows) <- case HashMap.toList filterObj of
[] -> P.throwIO $ userError "Error: Filter must not be empty"
filterElements ->
@ -1020,6 +1020,7 @@ mutationType connection maxRowsPerTable accessMode dbId tables = do
(encodeOutsidePKNames table "_set")
[encodeOutsidePKNames table "set"]
args
(numOfChanges, updatedRows) <-
executeUpdateMutation
connection

View file

@ -372,14 +372,14 @@ tableUpdateField accessMode table = do
& Type.withArguments
( Type.inputValue
"set"
(Type.nonNull $ tableSetInput table)
(tableSetInput table)
& Type.inputValueWithDescription "Fields to be updated"
& Type.renameInputValue "_set" "Unify naming with Hasura"
)
& Type.withArguments
( Type.inputValue
"filter"
(Type.nonNull $ filterType table)
(filterType table)
& Type.inputValueWithDescription "Filter to select rows to be updated"
& Type.renameInputValue "where" "Unify naming with Hasura"
)
@ -393,14 +393,6 @@ tableUpdateFieldByPk
tableUpdateFieldByPk accessMode tables table = do
pkArguments <- tablePKArguments table
let arguments =
[ Type.inputValue
(encodeOutsidePKNames table "set")
(Type.nonNull $ tableSetInput table)
& Type.inputValueWithDescription "Fields to be updated"
]
<> pkArguments
pure $
Type.field
( "update_"
@ -413,7 +405,16 @@ tableUpdateFieldByPk accessMode tables table = do
(Type.nonNull $ mutationByPkResponseType accessMode table)
& Type.fieldWithDescription
("Update row in table \"" <> table.name <> "\" by PK")
& Type.withArguments arguments
& Type.withArguments pkArguments
& Type.withArguments
( Type.inputValue
(encodeOutsidePKNames table "set")
(tableSetInput table)
& Type.inputValueWithDescription "Fields to be updated"
& Type.renameInputValue
(encodeOutsidePKNames table "_set")
"Unify naming with Hasura"
)
tableDeleteField :: AccessMode -> TableEntry -> Type.Field
@ -426,7 +427,7 @@ tableDeleteField accessMode table = do
& Type.withArguments
( Type.inputValue
"filter"
(Type.nonNull $ filterType table)
(filterType table)
& Type.inputValueWithDescription "Filter to select rows to be deleted"
& Type.renameInputValue "where" "Unify naming with Hasura"
)

View file

@ -102,7 +102,7 @@ makeType =
if depth >= 30
then
makeConstField
(IType.field field.name IType.typeString)
(IType.field field.name $ IType.nonNull IType.typeString)
(Type.String "Maximum depth exceeded")
else makeChildField (depth + 1) field
pure (field.name, resolver)
@ -112,21 +112,20 @@ makeType =
(IType.field "__typename" $ IType.nonNull IType.typeString)
(Type.String name)
pure
$ Out.NamedObjectType
$ Type.ObjectType
name
ty.description
[]
$ HashMap.fromList
$ ("__typename", typenameResolver) : resolvers
pure $
Out.NamedObjectType $
Type.ObjectType name ty.description [] $
HashMap.fromList $
("__typename", typenameResolver) : resolvers
_ -> do
Left $ "invalid type in out position: " <> show (toGraphQL ty)
-- Creates a field which looks up it's value in the object returned by the
-- Creates a field which looks up its value in the object returned by the
-- parent resolver.
makeChildField :: Int -> IType.Field -> Result (Out.Resolver IO)
makeChildField depth field = do
-- These lines are the same as `makeField`, except calling
-- `makeTypeWithDepthMemo` instead of `makeType`
args <- P.for field.args $ \arg -> do
ty <- makeInType arg.type_
pure (arg.name, In.Argument arg.description ty arg.defaultValue)
@ -145,7 +144,7 @@ makeType =
<> "' not found "
else pure Type.Null
case context.values of
result <- case context.values of
Type.Object obj -> do
let errorValue = HashMap.lookup ("__error_" <> field.name) obj
P.for_ errorValue $ \case
@ -153,9 +152,11 @@ makeType =
_ -> pure ()
case HashMap.lookup field.name obj of
Just value -> field.customResolver value
Just value -> pure value
Nothing -> defaultValue
_ -> defaultValue
field.customResolver result
in
makeTypeWithDepth 0