这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions console/cypress/integration/data/modify/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const passCreateUniqueKey = () => {
cy.get(getElementFromAlias('unique-key-0-column-1')).select('1');
cy.wait(1000);
cy.get(getElementFromAlias('modify-table-unique-key-0-save')).click();
cy.wait(5000);
cy.wait(10000);
cy.get('div').contains(
`${getTableName(0, testName)}_id_${getColName(0)}_key`
);
Expand All @@ -222,14 +222,14 @@ export const passModifyUniqueKey = () => {
cy.get(getElementFromAlias('modify-table-edit-unique-key-0')).click();
cy.get(getElementFromAlias('remove-uk-0-column-0')).click();
cy.get(getElementFromAlias('modify-table-unique-key-0-save')).click();
cy.wait(5000);
cy.wait(10000);
cy.get('div').contains(`${getTableName(0, testName)}_${getColName(0)}_key`);
};

export const passRemoveUniqueKey = () => {
cy.get(getElementFromAlias('modify-table-edit-unique-key-0')).click();
cy.get(getElementFromAlias('modify-table-unique-key-0-remove')).click();
cy.wait(5000);
cy.wait(10000);
};

export const passMTDeleteCol = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const deleteFunctionSql = () => {
let functionString = '(';
inputArgTypes.forEach((i, index) => {
functionString +=
i + ' ' + (index === inputArgTypes.length - 1 ? ')' : ',');
i.name + ' ' + (index === inputArgTypes.length - 1 ? ')' : ',');
});
functionWSchemaName += functionString;
}
Expand Down
14 changes: 12 additions & 2 deletions 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 = "17"
curCatalogVer = "18"

migrateMetadata
:: ( MonadTx m
Expand Down Expand Up @@ -327,6 +327,13 @@ from16To17 =
AND table_name = 'hdb_allowlist';
|]

from17To18 :: (MonadTx m) => m ()
from17To18 = liftTx $ do
-- Migrate database
Q.Discard () <- Q.multiQE defaultTxErrorHandler
$(Q.sqlFromFile "src-rsr/migrate_from_17_to_18.sql")
return ()

migrateCatalog
:: ( MonadTx m
, CacheRWM m
Expand Down Expand Up @@ -358,10 +365,13 @@ migrateCatalog migrationTime = do
| preVer == "14" -> from14ToCurrent
| preVer == "15" -> from15ToCurrent
| preVer == "16" -> from16ToCurrent
| preVer == "17" -> from17ToCurrent
| otherwise -> throw400 NotSupported $
"unsupported version : " <> preVer
where
from16ToCurrent = from16To17 >> postMigrate
from17ToCurrent = from17To18 >> postMigrate

from16ToCurrent = from16To17 >> from17ToCurrent

from15ToCurrent = from15To16 >> from16ToCurrent

Expand Down
127 changes: 81 additions & 46 deletions server/src-lib/Hasura/GraphQL/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,15 @@ mkHsraObjFldInfo
:: Maybe G.Description
-> G.Name
-> ParamMap
-> Maybe PGColTyAnn
-> G.GType
-> ObjFldInfo
mkHsraObjFldInfo descM name params ty =
ObjFldInfo descM name params ty HasuraType
mkHsraObjFldInfo descM name params pgTy ty =
ObjFldInfo descM name params pgTy ty HasuraType

mkHsraPGTyObjFld :: Maybe G.Description -> G.Name -> ParamMap -> PGColType -> ObjFldInfo
mkHsraPGTyObjFld descM name params colTy =
mkHsraObjFldInfo descM name params (Just $ PTCol colTy) $ mkPGColGTy colTy

mkHsraObjTyInfo
:: Maybe G.Description
Expand Down Expand Up @@ -164,14 +169,29 @@ mkHsraEnumTyInfo descM ty enumVals =
EnumTyInfo descM ty enumVals HasuraType

mkHsraScalarTyInfo :: PGColType -> ScalarTyInfo
mkHsraScalarTyInfo ty = ScalarTyInfo Nothing ty HasuraType
mkHsraScalarTyInfo ty =
ScalarTyInfo Nothing (G.Name $ pgColTyToScalar ty) (Just ty) HasuraType

fromInpValL :: [InpValInfo] -> Map.HashMap G.Name InpValInfo
fromInpValL = mapFromL _iviName

mkCompExpName :: PGColType -> G.Name
mkCompExpName pgColTy =
G.Name $ T.pack (show pgColTy) <> "_comparison_exp"
mkCompExpName colTy =
G.Name $ colTyTxt colTy <> "_comparison_exp"
where
colTyTxt t = case pgColTyDetails t of
PGTyBase b -> T.pack (show b)
PGTyDomain b -> colTyTxt b
_ -> asArray t

asArray t = case getArrayBaseTy t of
Nothing -> qualTyToScalar $ pgColTyName t
-- Array type
Just b -> case pgColTyDetails b of
PGTyBase bb -> T.pack $ show bb <> "_"
<> show (getPGTyArrDim t) <> "d"
_ -> qualTyToScalar (pgColTyName b)


mkCompExpTy :: PGColType -> G.NamedType
mkCompExpTy =
Expand Down Expand Up @@ -202,28 +222,38 @@ stDWithinGeographyInpTy = G.NamedType "st_d_within_geography_input"
mkCompExpInp :: PGColType -> InpObjTyInfo
mkCompExpInp colTy =
InpObjTyInfo (Just tyDesc) (mkCompExpTy colTy) (fromInpValL $ concat
[ map (mk colScalarTy) typedOps
, map (mk $ G.toLT colScalarTy) listOps
, bool [] (map (mk $ mkScalarTy PGText) stringOps) isStringTy
[ map (mkPGTy colTy) typedOps
, map (mk (Just $ arrOfCol colTy) $ G.toLT colGQLTy) listOps
, bool [] (map (mkPGTy textColTy) stringOps) isStringTy
, bool [] (map (mkPGTy colTy) arrOps) isArrTy
, bool [] (map jsonbOpToInpVal jsonbOps) isJsonbTy
, bool [] (stDWithinGeoOpInpVal stDWithinGeometryInpTy :
map geoOpToInpVal (geoOps ++ geomOps)) isGeometryType
, bool [] (stDWithinGeoOpInpVal stDWithinGeographyInpTy :
map geoOpToInpVal geoOps) isGeographyType
, [InpValInfo Nothing "_is_null" Nothing $ G.TypeNamed (G.Nullability True) $ G.NamedType "Boolean"]
, [ InpValInfo Nothing "_is_null" Nothing (Just $ PTCol boolColTy) $
mkPGColGTy boolColTy
]
]) HasuraType
where
colDtls = pgColTyDetails colTy
arrOfCol = PTArr . PTCol
tyDesc = mconcat
[ "expression to compare columns of type "
, G.Description (T.pack $ show colTy)
, G.Description (G.showGT $ mkPGColGTy colTy)
, ". All fields are combined with logical 'AND'."
]
isStringTy = case colTy of
PGVarchar -> True
PGText -> True
_ -> False
mk t n = InpValInfo Nothing n Nothing $ G.toGT t
colScalarTy = mkScalarTy colTy
bTy = case colDtls of
PGTyBase b -> return b
_ -> Nothing
isStringTy = case bTy of
Just PGVarchar -> True
Just PGText -> True
_ -> False
isArrTy = getPGTyArrDim colTy > 0
mk pt t n = InpValInfo Nothing n Nothing pt $ G.toGT t
mkPGTy ty = mk (Just $ PTCol ty) $ mkPGColGTy ty
colGQLTy = mkPGColGTy colTy
-- colScalarListTy = GA.GTList colGTy
typedOps =
["_eq", "_neq", "_gt", "_lt", "_gte", "_lte"]
Expand All @@ -237,50 +267,54 @@ mkCompExpInp colTy =
, "_similar", "_nsimilar"
]

isJsonbTy = case colTy of
PGJSONB -> True
_ -> False
jsonbOpToInpVal (op, ty, desc) = InpValInfo (Just desc) op Nothing ty
arrOps =
[ "_contains", "_is_contained_by"]

isJsonbTy = case bTy of
Just PGJSONB -> True
_ -> False
jsonbOpToInpVal (op, pgTy, desc) = InpValInfo (Just desc) op Nothing (Just pgTy) $ pgTyAnnToGTy pgTy
jsonbOps =
[ ( "_contains"
, G.toGT $ mkScalarTy PGJSONB
, PTCol jsonbColTy
, "does the column contain the given json value at the top level"
)
, ( "_contained_in"
, G.toGT $ mkScalarTy PGJSONB
, PTCol jsonbColTy
, "is the column contained in the given json value"
)
, ( "_has_key"
, G.toGT $ mkScalarTy PGText
, PTCol textColTy
, "does the string exist as a top-level key in the column"
)
, ( "_has_keys_any"
, G.toGT $ G.toLT $ G.toNT $ mkScalarTy PGText
, PTArr $ PTCol textColTy
, "do any of these strings exist as top-level keys in the column"
)
, ( "_has_keys_all"
, G.toGT $ G.toLT $ G.toNT $ mkScalarTy PGText
, PTArr $ PTCol textColTy
, "do all of these strings exist as top-level keys in the column"
)
]

stDWithinGeoOpInpVal ty =
InpValInfo (Just stDWithinGeoDesc) "_st_d_within" Nothing $ G.toGT ty
InpValInfo (Just stDWithinGeoDesc) "_st_d_within" Nothing Nothing $ G.toGT ty
stDWithinGeoDesc =
"is the column within a distance from a " <> colTyDesc <> " value"

-- Geometry related ops
isGeometryType = case colTy of
PGGeometry -> True
_ -> False
isGeometryType = case bTy of
Just PGGeometry -> True
_ -> False

-- Geography related ops
isGeographyType = case colTy of
PGGeography -> True
_ -> False
isGeographyType = case bTy of
Just PGGeography -> True
_ -> False

geoOpToInpVal (op, desc) =
InpValInfo (Just desc) op Nothing $ G.toGT $ mkScalarTy colTy
InpValInfo (Just desc) op Nothing (Just $ PTCol colTy) $
G.toGT $ mkScalarTy colTy

colTyDesc = G.Description $ T.pack $ show colTy

Expand Down Expand Up @@ -349,7 +383,7 @@ ordByEnumTy =
]

defaultTypes :: [TypeInfo]
defaultTypes = $(fromSchemaDocQ defaultSchema HasuraType)
defaultTypes = $(fromSchemaDocQ defaultSchema defaultPGColTyMap HasuraType)


mkGCtx :: TyAgg -> RootFlds -> InsCtxMap -> GCtx
Expand All @@ -376,6 +410,7 @@ mkGCtx tyAgg (RootFlds flds) insCtxMap =
TyAgg tyInfos fldInfos scalars ordByEnums = tyAgg
colTys = Set.toList $ Set.fromList $ map pgiType $
lefts $ Map.elems fldInfos
colTyDets = map pgColTyDetails colTys
mkMutRoot =
mkHsraObjTyInfo (Just "mutation root") (G.NamedType "mutation_root") Set.empty .
mapFromL _fiName
Expand All @@ -385,34 +420,34 @@ mkGCtx tyAgg (RootFlds flds) insCtxMap =
(G.NamedType "subscription_root") Set.empty . mapFromL _fiName
subRootM = bool (Just $ mkSubRoot qFlds) Nothing $ null qFlds
(qFlds, mFlds) = partitionEithers $ map snd $ Map.elems flds
schemaFld = mkHsraObjFldInfo Nothing "__schema" Map.empty $
schemaFld = mkHsraObjFldInfo Nothing "__schema" Map.empty Nothing $
G.toGT $ G.toNT $ G.NamedType "__Schema"
typeFld = mkHsraObjFldInfo Nothing "__type" typeFldArgs $
typeFld = mkHsraObjFldInfo Nothing "__type" typeFldArgs Nothing $
G.toGT $ G.NamedType "__Type"
where
typeFldArgs = mapFromL _iviName [
InpValInfo (Just "name of the type") "name" Nothing
$ G.toGT $ G.toNT $ G.NamedType "String"
mkPGTyInpValNT (Just "name of the type") "name" textColTy
]

-- _st_d_within has to stay with geometry type
stDWithinGeometryInpM =
bool Nothing (Just $ stDWithinGeomInp) (PGGeometry `elem` colTys)
bool Nothing (Just stDWithinGeomInp) (PGTyBase PGGeometry `elem` colTyDets)
-- _st_d_within_geography is created for geography type
stDWithinGeographyInpM =
bool Nothing (Just $ stDWithinGeogInp) (PGGeography `elem` colTys)
bool Nothing (Just stDWithinGeogInp) (PGTyBase PGGeography `elem` colTyDets)

stDWithinGeomInp =
mkHsraInpTyInfo Nothing stDWithinGeometryInpTy $ fromInpValL
[ InpValInfo Nothing "from" Nothing $ G.toGT $ G.toNT $ mkScalarTy PGGeometry
, InpValInfo Nothing "distance" Nothing $ G.toNT $ mkScalarTy PGFloat
[ mkPGTyInpValNT Nothing "from" geometryColTy
, mkPGTyInpValNT Nothing "distance" floatColTy
]
stDWithinGeogInp =
mkHsraInpTyInfo Nothing stDWithinGeographyInpTy $ fromInpValL
[ InpValInfo Nothing "from" Nothing $ G.toGT $ G.toNT $ mkScalarTy PGGeography
, InpValInfo Nothing "distance" Nothing $ G.toNT $ mkScalarTy PGFloat
, InpValInfo
Nothing "use_spheroid" (Just $ G.VCBoolean True) $ G.toGT $ mkScalarTy PGBoolean
[ mkPGTyInpValNT Nothing "from" geographyColTy
, mkPGTyInpValNT Nothing "distance" floatColTy
, InpValInfo Nothing "use_spheroid"
(Just $ G.VCBoolean True) (Just $ PTCol boolColTy) $
G.toGT $ mkPGColGTy boolColTy
]

emptyGCtx :: GCtx
Expand Down
4 changes: 2 additions & 2 deletions server/src-lib/Hasura/GraphQL/Execute/LiveQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ toMultiplexedQueryVar = \case
GR.UVSQL sqlExp -> return sqlExp
where
fromResVars colTy jPath =
S.withTyAnn colTy $ S.SEOpApp (S.SQLOp "#>>")
S.annotateExp colTy $ S.SEOpApp (S.SQLOp "#>>")
[ S.SEQIden $ S.QIden (S.QualIden $ Iden "_subs")
(Iden "result_vars")
, S.SEArray $ map S.SELit jPath
Expand Down Expand Up @@ -240,7 +240,7 @@ validateAnnVarValsOnPg pgExecCtx annVarVals = do

Q.Discard _ <- runTx' $ liftTx $
Q.rawQE valPgErrHandler (Q.fromBuilder $ toSQL valSel) [] False
return $ fmap (txtEncodedPGVal . snd) annVarVals
return $ fmap (txtEncodePGVal . snd) annVarVals

where
mkExtrs = map (flip S.Extractor Nothing . uncurry toTxtValue)
Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/GraphQL/Execute/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ prepareWithPlan = \case
addPrepArg argNum $ binEncoder colVal
return $ toPrepParam argNum colTy
R.UVSessVar colTy sessVar ->
return $ S.withTyAnn colTy $ withGeoVal colTy $
return $ S.annotateExp colTy $ withGeoVal colTy $
S.SEOpApp (S.SQLOp "->>")
[S.SEPrep 1, S.SELit $ T.toLower sessVar]
R.UVSQL sqlExp -> return sqlExp
Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/GraphQL/Explain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ resolveVal userInfo = \case
txtConverter annPGVal
RS.UVSessVar colTy sessVar -> do
sessVarVal <- getSessVarVal userInfo sessVar
return $ S.withTyAnn colTy $ withGeoVal colTy $
return $ S.annotateExp colTy $ withGeoVal colTy $
S.SELit sessVarVal
RS.UVSQL sqlExp -> return sqlExp

Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/GraphQL/RemoteServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fetchRemoteSchema manager name def@(RemoteSchemaInfo url headerConf _) = do
either schemaErr return $ J.eitherDecode respData
let (sDoc, qRootN, mRootN, sRootN) =
fromIntrospection introspectRes
typMap <- either remoteSchemaErr return $ VT.fromSchemaDoc sDoc $
typMap <- either remoteSchemaErr return $ VT.fromSchemaDoc sDoc Map.empty $
VT.RemoteType name def
let mQrTyp = Map.lookup qRootN typMap
mMrTyp = maybe Nothing (\mr -> Map.lookup mr typMap) mRootN
Expand Down
Loading