mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
server: add code field to warning object in metadata API responses
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8601 GitOrigin-RevId: 7034c0a04b87c44731680917aa3946084b705959
This commit is contained in:
parent
3cef692dd7
commit
774075a709
@ -213,6 +213,7 @@ HTTP/1.1 200 OK
|
||||
"inconsistent_objects": [],
|
||||
"warnings: [
|
||||
{
|
||||
"code": "illegal-event-trigger-name",
|
||||
"message": "The event trigger with name \"weird]name]\" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name",
|
||||
"type": "event_trigger",
|
||||
"name": "event_trigger weird]name] in table hasura.authors in source mssql"
|
||||
@ -232,6 +233,7 @@ HTTP/1.1 400 Bad Request
|
||||
"error": "failed due to metadata warnings",
|
||||
"internal": [
|
||||
{
|
||||
"code": "illegal-event-trigger-name",
|
||||
"message": "The event trigger with name \"weird]name]\" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name",
|
||||
"name": "event_trigger weird]name] in table hasura.authors in source mssql",
|
||||
"type": "event_trigger"
|
||||
|
@ -120,7 +120,8 @@ tests = do
|
||||
is_consistent: true
|
||||
inconsistent_objects: []
|
||||
warnings:
|
||||
- message: >-
|
||||
- code: source-cleanup-failed
|
||||
message: >-
|
||||
Could not cleanup the source '"postgres"' while dropping it from the graphql-engine as it is
|
||||
inconsistent. Please consider cleaning the resources created by the graphql engine, refer
|
||||
https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-footprints-manually
|
||||
|
@ -45,7 +45,8 @@ tests = do
|
||||
code: metadata-warnings
|
||||
error: failed due to metadata warnings
|
||||
internal:
|
||||
- message: The event trigger with name "weird$name" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name
|
||||
- code: illegal-event-trigger-name
|
||||
message: The event trigger with name "weird$name" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name
|
||||
name: event_trigger weird$name in table hasura.table1 in source postgres
|
||||
type: event_trigger
|
||||
path: $.args
|
||||
@ -60,7 +61,8 @@ tests = do
|
||||
is_consistent: true
|
||||
inconsistent_objects: []
|
||||
warnings:
|
||||
- message: The event trigger with name "weird$name" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name
|
||||
- code: illegal-event-trigger-name
|
||||
message: The event trigger with name "weird$name" may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name
|
||||
name: event_trigger weird$name in table hasura.table1 in source postgres
|
||||
type: event_trigger
|
||||
|]
|
||||
|
@ -77,7 +77,8 @@ tests = describe "weird trigger names are allowed" do
|
||||
[yaml|
|
||||
message: success
|
||||
warnings:
|
||||
- message: >-
|
||||
- code: illegal-event-trigger-name
|
||||
message: >-
|
||||
The event trigger with name "weird]name]" may not work as expected,
|
||||
hasura suggests to use only alphanumeric, underscore and hyphens in
|
||||
an event trigger name
|
||||
|
@ -58,7 +58,7 @@ compareTimeLimitWith userTimeLimitMaybe = do
|
||||
-- warning message if the user time limit API limit is greater than the cloud time limit API limit
|
||||
warningMessage :: MaxTime -> MaxTime -> MetadataWarning
|
||||
warningMessage userTimeLimit cloudTimeLimit =
|
||||
MetadataWarning (MOSource defaultSource) $
|
||||
MetadataWarning WCTimeLimitExceededSystemLimit (MOSource defaultSource) $
|
||||
"the configured time limit: "
|
||||
<> tshow (seconds $ unMaxTime userTimeLimit)
|
||||
<> " exceeds the project time limit: "
|
||||
|
@ -114,7 +114,7 @@ postDropSourceHookHelper oldSchemaCache sourceName sourceMetadataBackend = do
|
||||
<> " Please consider cleaning the resources created by the graphql engine,"
|
||||
<> " refer https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-footprints-manually"
|
||||
HL.unLogger logger $ MetadataLog HL.LevelWarn message J.Null
|
||||
warn $ MetadataWarning (MOSource sourceName) message
|
||||
warn $ MetadataWarning WCSourceCleanupFailed (MOSource sourceName) message
|
||||
Just sourceInfo -> runPostDropSourceHook defaultSource sourceInfo
|
||||
|
||||
runClearMetadata ::
|
||||
@ -327,7 +327,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
|
||||
mkEventTriggerObjID tableName triggerName = MOSourceObjId source $ AB.mkAnyBackend $ SMOTableObj @b tableName $ MTOTrigger triggerName
|
||||
mkIllegalEventTriggerNameWarning (tableName, triggerName) =
|
||||
-- TODO: capture the path as well
|
||||
MetadataWarning (mkEventTriggerObjID tableName triggerName) $
|
||||
MetadataWarning WCIllegalEventTriggerName (mkEventTriggerObjID tableName triggerName) $
|
||||
"The event trigger with name "
|
||||
<> dquote (triggerNameToTxt triggerName)
|
||||
<> " may not work as expected, hasura suggests to use only alphanumeric, underscore and hyphens in an event trigger name"
|
||||
@ -485,7 +485,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
|
||||
<> " Please refer https://hasura.io/docs/latest/graphql/core/event-triggers/remove-event-triggers/#clean-up-event-trigger-footprints-manually "
|
||||
<> " to delete the sql triggers from the database manually."
|
||||
<> " For more details, please refer https://hasura.io/docs/latest/graphql/core/event-triggers/index.html "
|
||||
warn $ MetadataWarning sourceObjID message
|
||||
warn $ MetadataWarning WCSourceCleanupFailed sourceObjID message
|
||||
logger $ MetadataLog HL.LevelWarn message J.Null
|
||||
Just sourceConfig -> do
|
||||
for_ droppedEventTriggers $
|
||||
@ -496,7 +496,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
|
||||
case tableNameMaybe of
|
||||
Nothing -> do
|
||||
let message = sqlTriggerError triggerName
|
||||
warn $ MetadataWarning sourceObjID message
|
||||
warn $ MetadataWarning WCSourceCleanupFailed sourceObjID message
|
||||
logger $ MetadataLog HL.LevelWarn message J.Null
|
||||
Just tableName ->
|
||||
dropTriggerAndArchiveEvents @b sourceConfig triggerName tableName
|
||||
@ -504,7 +504,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
|
||||
case OMap.lookup retainedNewTriggerName oldTriggersMap of
|
||||
Nothing -> do
|
||||
let message = sqlTriggerError retainedNewTriggerName
|
||||
warn $ MetadataWarning sourceObjID message
|
||||
warn $ MetadataWarning WCSourceCleanupFailed sourceObjID message
|
||||
logger $ MetadataLog HL.LevelWarn message J.Null
|
||||
Just oldTriggerConf -> do
|
||||
let newTriggerOps = etcDefinition retainedNewTriggerConf
|
||||
@ -519,7 +519,7 @@ runReplaceMetadataV2' ReplaceMetadataV2 {..} = do
|
||||
case tableNameMaybe of
|
||||
Nothing -> do
|
||||
let message = sqlTriggerError retainedNewTriggerName
|
||||
warn $ MetadataWarning sourceObjID message
|
||||
warn $ MetadataWarning WCSourceCleanupFailed sourceObjID message
|
||||
logger $ MetadataLog HL.LevelWarn message J.Null
|
||||
Just tableName ->
|
||||
dropDanglingSQLTrigger @b sourceConfig retainedNewTriggerName tableName (HS.fromList $ catMaybes droppedOps)
|
||||
|
@ -21,6 +21,7 @@ module Hasura.RQL.DDL.Warnings
|
||||
runMetadataWarnings,
|
||||
mkSuccessResponseWithWarnings,
|
||||
successMsgWithWarnings,
|
||||
WarningCode (..),
|
||||
)
|
||||
where
|
||||
|
||||
@ -74,18 +75,31 @@ instance ToJSON AllowWarnings where
|
||||
toBool AllowWarnings = True
|
||||
toBool NoAllowWarnings = False
|
||||
|
||||
data WarningCode
|
||||
= WCSourceCleanupFailed
|
||||
| WCIllegalEventTriggerName
|
||||
| WCTimeLimitExceededSystemLimit
|
||||
deriving (Eq, Ord)
|
||||
|
||||
instance ToJSON WarningCode where
|
||||
toJSON WCIllegalEventTriggerName = "illegal-event-trigger-name"
|
||||
toJSON WCTimeLimitExceededSystemLimit = "time-limit-exceeded-system-limit"
|
||||
toJSON WCSourceCleanupFailed = "source-cleanup-failed"
|
||||
|
||||
data MetadataWarning = MetadataWarning
|
||||
{ _mwMetadataObj :: MetadataObjId,
|
||||
{ _mwCode :: WarningCode,
|
||||
_mwMetadataObj :: MetadataObjId,
|
||||
_mwMessage :: Text
|
||||
}
|
||||
deriving (Eq, Ord)
|
||||
|
||||
instance ToJSON MetadataWarning where
|
||||
toJSON (MetadataWarning mObj msg) =
|
||||
toJSON (MetadataWarning code mObj msg) =
|
||||
Aeson.object
|
||||
[ "message" .= msg,
|
||||
"type" .= moiTypeName mObj,
|
||||
"name" .= moiName mObj
|
||||
"name" .= moiName mObj,
|
||||
"code" .= code
|
||||
]
|
||||
|
||||
type MetadataWarnings = Seq MetadataWarning
|
||||
|
Loading…
Reference in New Issue
Block a user