这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
db9f137
Add Postgres comments to table descriptions
ajeetdsouza Jun 19, 2019
e1a9bd0
Create newtype for PGDescription
ajeetdsouza Jun 21, 2019
10635b3
Merge branch 'master' into issue-446-comments
rakeshkky Jul 2, 2019
4a9a261
update cache on change in comment
ajeetdsouza Jul 11, 2019
ac8f9b1
move table comments in API explorer
ajeetdsouza Jul 11, 2019
c26324b
add Postgres comments to function description
ajeetdsouza Jul 12, 2019
9dc8a97
Merge branch 'master' into issue-446-comments
rakeshkky Jul 23, 2019
2558d4a
Merge branch 'master' into issue-446-comments
rakeshkky Aug 1, 2019
aef5d0f
fix hdb_table_info_agg view
rakeshkky Aug 1, 2019
78ddc3c
support column comments
rakeshkky Aug 1, 2019
7c54604
add table description to table type and remove from resolvers
rakeshkky Aug 1, 2019
23baa47
capture functions' description update in run_sql
rakeshkky Aug 1, 2019
43ef44c
fix table_meta.sql
rakeshkky Aug 5, 2019
06cfe5c
Merge branch 'master' into issue-446-comments
rakeshkky Aug 5, 2019
4af9f9b
Merge branch 'master' into issue-446-comments
rakeshkky Aug 20, 2019
e22bebc
Merge branch 'issue-446-comments' of github.com:ajeetdsouza/graphql-e…
rakeshkky Aug 20, 2019
8254304
Merge branch 'master' into issue-446-comments
rakeshkky Sep 4, 2019
10f2ec0
fix table descriptions are not capturing
rakeshkky Sep 4, 2019
64dfe20
Merge branch 'master' into issue-446-comments
rakeshkky Sep 16, 2019
4111019
fix typo 'psuedo'; rename it to 'pseudo' in server code
rakeshkky Sep 16, 2019
458506c
Merge branch 'master' into issue-446-comments
lexi-lambda Sep 16, 2019
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
9 changes: 8 additions & 1 deletion server/src-exec/Migrate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import qualified Data.Yaml.TH as Y
import qualified Database.PG.Query as Q

curCatalogVer :: T.Text
curCatalogVer = "22"
curCatalogVer = "23"

migrateMetadata
:: ( MonadTx m
Expand Down Expand Up @@ -360,6 +360,12 @@ from21To22 = do
$(Q.sqlFromFile "src-rsr/migrate_from_21_to_22.sql")
pure ()

from22To23 :: (MonadTx m) => m ()
from22To23 = do
Q.Discard () <- liftTx $ Q.multiQE defaultTxErrorHandler
$(Q.sqlFromFile "src-rsr/migrate_from_22_to_23.sql")
pure ()

migrateCatalog
:: ( MonadTx m
, CacheRWM m
Expand Down Expand Up @@ -403,6 +409,7 @@ migrateCatalog migrationTime = migrateFrom =<< getCatalogVersion
, ("19", from19To20)
, ("20", from20To21)
, ("21", from21To22)
, ("22", from22To23)
]

postMigrate = do
Expand Down
24 changes: 14 additions & 10 deletions server/src-lib/Hasura/GraphQL/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ isValidRel rn rt = isValidName (mkRelName rn) && isValidObjectName rt

isValidField :: FieldInfo PGColumnInfo -> Bool
isValidField = \case
FIColumn (PGColumnInfo col _ _) -> isValidCol col
FIColumn colInfo -> isValidCol $ pgiName colInfo
FIRelationship (RelInfo rn _ _ remTab _) -> isValidRel rn remTab

upsertable :: [ConstraintName] -> Bool -> Bool -> Bool
Expand Down Expand Up @@ -114,8 +114,11 @@ isAggFld = flip elem (numAggOps <> compAggOps)

mkGCtxRole'
:: QualifiedTable
-- Postgres description
-> Maybe PGDescription
-- insert permission
-> Maybe ([PGColumnInfo], RelationInfoMap)
-- ^ insert permission
-- select permission
-> Maybe (Bool, [SelField])
-- ^ select permission
-> Maybe [PGColumnInfo]
Expand All @@ -132,7 +135,7 @@ mkGCtxRole'
-> Maybe EnumValues
-- ^ present iff this table is an enum table (see "Hasura.RQL.Schema.Enum")
-> TyAgg
mkGCtxRole' tn insPermM selPermM updColsM
mkGCtxRole' tn descM insPermM selPermM updColsM
delPermM pkeyCols constraints viM funcs enumValuesM =

TyAgg (mkTyInfoMap allTypes) fieldMap scalars ordByCtx
Expand Down Expand Up @@ -244,7 +247,7 @@ mkGCtxRole' tn insPermM selPermM updColsM
&& any (`isMutable` viM) [viIsInsertable, viIsUpdatable, viIsDeletable]

-- table obj
selObjM = mkTableObj tn <$> selFldsM
selObjM = mkTableObj tn descM <$> selFldsM

-- aggregate objs and order by inputs
(aggObjs, aggOrdByInps) = case selPermM of
Expand Down Expand Up @@ -372,7 +375,7 @@ getRootFldsRole' tn primCols constraints fields funcs insM selM updM delM viM =
funcFldHelper f g pFltr pLimit hdrs =
flip map funcs $ \fi ->
( f . FuncQOpCtx tn hdrs pFltr pLimit (fiName fi) $ mkFuncArgItemSeq fi
, g fi
, g fi $ fiDescription fi
)

mkFuncArgItemSeq fi = Seq.fromList $ procFuncArgs (fiInputArgs fi)
Expand Down Expand Up @@ -470,6 +473,7 @@ mkGCtxRole
:: (MonadError QErr m)
=> TableCache PGColumnInfo
-> QualifiedTable
-> Maybe PGDescription
-> FieldInfoMap PGColumnInfo
-> [PGCol]
-> [ConstraintName]
Expand All @@ -479,7 +483,7 @@ mkGCtxRole
-> RoleName
-> RolePermInfo
-> m (TyAgg, RootFields, InsCtxMap)
mkGCtxRole tableCache tn fields pCols constraints funcs viM enumValuesM role permInfo = do
mkGCtxRole tableCache tn descM fields pCols constraints funcs viM enumValuesM role permInfo = do
selPermM <- mapM (getSelPerm tableCache fields role) $ _permSel permInfo
tabInsInfoM <- forM (_permIns permInfo) $ \ipi -> do
ctx <- mkInsCtx role tableCache fields ipi $ _permUpd permInfo
Expand All @@ -489,7 +493,7 @@ mkGCtxRole tableCache tn fields pCols constraints funcs viM enumValuesM role per
let insPermM = snd <$> tabInsInfoM
insCtxM = fst <$> tabInsInfoM
updColsM = filterColInfos . upiCols <$> _permUpd permInfo
tyAgg = mkGCtxRole' tn insPermM selPermM updColsM
tyAgg = mkGCtxRole' tn descM insPermM selPermM updColsM
(void $ _permDel permInfo) pColInfos constraints viM funcs enumValuesM
rootFlds = getRootFldsRole tn pCols constraints fields funcs viM permInfo
insCtxMap = maybe Map.empty (Map.singleton tn) insCtxM
Expand Down Expand Up @@ -535,16 +539,16 @@ mkGCtxMapTable
-> m (Map.HashMap RoleName (TyAgg, RootFields, InsCtxMap))
mkGCtxMapTable tableCache funcCache tabInfo = do
m <- Map.traverseWithKey
(mkGCtxRole tableCache tn fields pkeyCols validConstraints tabFuncs viewInfo enumValues)
(mkGCtxRole tableCache tn descM fields pkeyCols validConstraints tabFuncs viewInfo enumValues)
rolePerms
adminInsCtx <- mkAdminInsCtx tn tableCache fields
let adminCtx = mkGCtxRole' tn (Just (colInfos, icRelations adminInsCtx))
let adminCtx = mkGCtxRole' tn descM (Just (colInfos, icRelations adminInsCtx))
(Just (True, selFlds)) (Just colInfos) (Just ())
pkeyColInfos validConstraints viewInfo tabFuncs enumValues
adminInsCtxMap = Map.singleton tn adminInsCtx
return $ Map.insert adminRole (adminCtx, adminRootFlds, adminInsCtxMap) m
where
TableInfo tn _ fields rolePerms constraints pkeyCols viewInfo _ enumValues = tabInfo
TableInfo tn descM _ fields rolePerms constraints pkeyCols viewInfo _ enumValues = tabInfo
validConstraints = mkValidConstraints constraints
colInfos = getValidCols fields
validColNames = map pgiName colInfos
Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/GraphQL/Schema/BoolExp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ mkBoolExpInp tn fields =
]

mkFldExpInp = \case
Left (PGColumnInfo colName colTy _) ->
Left (PGColumnInfo colName colTy _ _) ->
mk (mkColName colName) (mkCompExpTy colTy)
Right (RelInfo relName _ _ remTab _, _, _, _, _) ->
mk (mkRelName relName) (mkBoolExpTy remTab)
11 changes: 11 additions & 0 deletions server/src-lib/Hasura/GraphQL/Schema/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ module Hasura.GraphQL.Schema.Common
, mkTableAggTy

, mkColumnEnumVal
, mkDescriptionWith
, mkDescription
) where

import qualified Data.HashMap.Strict as Map
import qualified Data.Text as T
import qualified Language.GraphQL.Draft.Syntax as G

import Hasura.GraphQL.Validate.Types
Expand Down Expand Up @@ -63,3 +66,11 @@ mkTableAggTy = addTypeSuffix "_aggregate" . mkTableTy
mkColumnEnumVal :: PGCol -> EnumValInfo
mkColumnEnumVal (PGCol col) =
EnumValInfo (Just "column name") (G.EnumValue $ G.Name col) False

mkDescriptionWith :: Maybe PGDescription -> Text -> G.Description
mkDescriptionWith descM defaultTxt = G.Description $ case descM of
Nothing -> defaultTxt
Just (PGDescription descTxt) -> T.unlines [descTxt, "\n", defaultTxt]

mkDescription :: PGDescription -> G.Description
mkDescription = G.Description . getPGDescription
12 changes: 6 additions & 6 deletions server/src-lib/Hasura/GraphQL/Schema/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ mkFuncArgs funInfo =
funcInpArgs = bool [funcInpArg] [] $ null funcArgs

mkFuncQueryFld
:: FunctionInfo -> ObjFldInfo
mkFuncQueryFld funInfo =
:: FunctionInfo -> Maybe PGDescription -> ObjFldInfo
mkFuncQueryFld funInfo descM =
mkHsraObjFldInfo (Just desc) fldName (mkFuncArgs funInfo) ty
where
retTable = fiReturnType funInfo
funcName = fiName funInfo

desc = G.Description $ "execute function " <> funcName
desc = mkDescriptionWith descM $ "execute function " <> funcName
<<> " which returns " <>> retTable
fldName = qualObjectToName funcName

Expand All @@ -116,14 +116,14 @@ function_aggregate(
-}

mkFuncAggQueryFld
:: FunctionInfo -> ObjFldInfo
mkFuncAggQueryFld funInfo =
:: FunctionInfo -> Maybe PGDescription -> ObjFldInfo
mkFuncAggQueryFld funInfo descM =
mkHsraObjFldInfo (Just desc) fldName (mkFuncArgs funInfo) ty
where
funcName = fiName funInfo
retTable = fiReturnType funInfo

desc = G.Description $ "execute function " <> funcName
desc = mkDescriptionWith descM $ "execute function " <> funcName
<<> " and query aggregates on result of table type "
<>> retTable

Expand Down
4 changes: 2 additions & 2 deletions server/src-lib/Hasura/GraphQL/Schema/Mutation/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import Hasura.RQL.Types
import Hasura.SQL.Types

mkPGColInp :: PGColumnInfo -> InpValInfo
mkPGColInp (PGColumnInfo colName colTy _) =
InpValInfo Nothing (G.Name $ getPGColTxt colName) Nothing $
mkPGColInp (PGColumnInfo colName colTy _ descM) =
InpValInfo (mkDescription <$> descM) (G.Name $ getPGColTxt colName) Nothing $
G.toGT $ mkColumnType colTy

-- table_mutation_response
Expand Down
17 changes: 10 additions & 7 deletions server/src-lib/Hasura/GraphQL/Schema/Select.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import qualified Data.HashMap.Strict as Map
import qualified Data.HashSet as Set
import qualified Language.GraphQL.Draft.Syntax as G

import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.BoolExp
import Hasura.GraphQL.Schema.Common
import Hasura.GraphQL.Schema.OrderBy
import Hasura.GraphQL.Validate.Types
import Hasura.Prelude
Expand Down Expand Up @@ -58,9 +58,10 @@ mkPGColParams colType
| otherwise = Map.empty

mkPGColFld :: PGColumnInfo -> ObjFldInfo
mkPGColFld (PGColumnInfo colName colTy isNullable) =
mkHsraObjFldInfo Nothing n (mkPGColParams colTy) ty
mkPGColFld (PGColumnInfo colName colTy isNullable pgDesc) =
mkHsraObjFldInfo desc n (mkPGColParams colTy) ty
where
desc = (G.Description . getPGDescription) <$> pgDesc
n = G.Name $ getPGColTxt colName
ty = bool notNullTy nullTy isNullable
columnType = mkColumnType colTy
Expand Down Expand Up @@ -136,15 +137,16 @@ type table {
-}
mkTableObj
:: QualifiedTable
-> Maybe PGDescription
-> [SelField]
-> ObjTyInfo
mkTableObj tn allowedFlds =
mkTableObj tn descM allowedFlds =
mkObjTyInfo (Just desc) (mkTableTy tn) Set.empty (mapFromL _fiName flds) TLHasuraType
where
flds = concatMap (either (pure . mkPGColFld) mkRelFld') allowedFlds
mkRelFld' (relInfo, allowAgg, _, _, isNullable) =
mkRelFld allowAgg relInfo isNullable
desc = G.Description $ "columns and relationships of " <>> tn
desc = mkDescriptionWith descM $ "columns and relationships of " <>> tn

{-
type table_aggregate {
Expand Down Expand Up @@ -268,8 +270,9 @@ mkSelFldPKey tn cols =
fldName = mkTableByPkName tn
args = fromInpValL $ map colInpVal cols
ty = G.toGT $ mkTableTy tn
colInpVal (PGColumnInfo n typ _) =
InpValInfo Nothing (mkColName n) Nothing $ G.toGT $ G.toNT $ mkColumnType typ
colInpVal (PGColumnInfo n typ _ descM) =
InpValInfo (mkDescription <$> descM)
(mkColName n) Nothing $ G.toGT $ G.toNT $ mkColumnType typ

{-

Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/RQL/DDL/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ runRunSQL (RunSQL t cascade mChkMDCnstcy) = do
isAltrDropReplace = either throwErr return . matchRegex regex False
where
throwErr s = throw500 $ "compiling regex failed: " <> T.pack s
regex = "alter|drop|replace|create function"
regex = "alter|drop|replace|create function|comment on"

data RunSQLRes
= RunSQLRes
Expand Down
4 changes: 3 additions & 1 deletion server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,13 @@ withMetadataCheck cascade action = do
delFunctionFromCache qf

-- Process altered functions
forM_ alteredFuncs $ \(qf, newTy) ->
forM_ alteredFuncs $ \(qf, newTy, newDescM) -> do
when (newTy == FTVOLATILE) $
throw400 NotSupported $
"type of function " <> qf <<> " is altered to \"VOLATILE\" which is not supported now"

updateFunctionDescription qf newDescM

-- update the schema cache and hdb_catalog with the changes
reloadRequired <- processSchemaChanges schemaDiff

Expand Down
Loading