server, console, docs: fix untrack_function metadata query bug

Co-authored-by: Sameer Kolhar <6604943+kolharsam@users.noreply.github.com>
GitOrigin-RevId: a68a6f8b5c5243372332bfec7d9cdcd3011c001f
This commit is contained in:
Anon Ray 2021-05-24 21:26:32 +05:30 committed by hasura-bot
parent 82e2e382f1
commit 53beef47ea
4 changed files with 40 additions and 10 deletions

View File

@ -76,10 +76,12 @@ const makeRequest = (
) => { ) => {
return (dispatch, getState) => { return (dispatch, getState) => {
const source = getState().tables.currentDataSource; const source = getState().tables.currentDataSource;
const { resourceVersion } = getState().metadata;
const upQuery = { const upQuery = {
type: 'bulk', type: 'bulk',
source, source,
args: upQueries, args: upQueries,
resource_version: resourceVersion,
}; };
const downQuery = { const downQuery = {

View File

@ -601,7 +601,8 @@ export const getUntrackFunctionQuery = (
name: string, name: string,
schema: string, schema: string,
source: string source: string
) => getMetadataQuery('untrack_function', source, { name, schema }); ) =>
getMetadataQuery('untrack_function', source, { function: { name, schema } });
export const getRenameRelationshipQuery = ( export const getRenameRelationshipQuery = (
table: QualifiedTable, table: QualifiedTable,

View File

@ -140,8 +140,10 @@ Remove an SQL function ``search_articles``:
{ {
"type": "pg_untrack_function", "type": "pg_untrack_function",
"args": { "args": {
"schema": "public", "function": {
"name": "search_articles", "schema": "public",
"name": "search_articles"
},
"source": "default" "source": "default"
} }
} }
@ -156,7 +158,7 @@ Args syntax
- Required - Required
- Schema - Schema
- Description - Description
* - table * - function
- true - true
- :ref:`FunctionName <FunctionName>` - :ref:`FunctionName <FunctionName>`
- Name of the SQL function - Name of the SQL function

View File

@ -104,12 +104,37 @@ instance (Backend b) => ToJSON (UnTrackFunction b) where
toJSON = genericToJSON hasuraJSON toJSON = genericToJSON hasuraJSON
instance (Backend b) => FromJSON (UnTrackFunction b) where instance (Backend b) => FromJSON (UnTrackFunction b) where
parseJSON v = withSource <|> withoutSource -- Following was the previous implementation, which while seems to be correct,
where -- has an unexpected behaviour. In the case when @source@ key is present but
withoutSource = UnTrackFunction <$> parseJSON v <*> pure defaultSource -- @function@ key is absent, it would silently coerce it into a @default@
withSource = flip (withObject "UnTrackFunction") v \o -> -- source. The culprint being the _alternative_ operator, which silently fails
UnTrackFunction <$> o .: "function" -- the first parse. This note exists so that we don't try to simplify using
<*> o .:? "source" .!= defaultSource -- the _alternative_ pattern here.
-- Previous implementation :-
-- Consider the following JSON -
-- {
-- "source": "custom_source",
-- "schema": "public",
-- "name": "my_function"
-- }
-- it silently fails parsing the source here because @function@ key is not
-- present, and proceeds to parse using @withoutSource@ as default source. Now
-- this is surprising for the user, because they mention @source@ key
-- explicitly. A better behaviour is to explicitly look for @function@ key if
-- a @source@ key is present.
-- >>
-- parseJSON v = withSource <|> withoutSource
-- where
-- withoutSource = UnTrackFunction <$> parseJSON v <*> pure defaultSource
-- withSource = flip (withObject "UnTrackFunction") v \o -> do
-- UnTrackFunction <$> o .: "function"
-- <*> o .:? "source" .!= defaultSource
parseJSON v = flip (withObject "UnTrackFunction") v $ \o -> do
source <- o .:? "source"
case source of
Just src -> flip UnTrackFunction src <$> o .: "function"
Nothing -> UnTrackFunction <$> parseJSON v <*> pure defaultSource
askFunctionInfo askFunctionInfo
:: forall b m :: forall b m