mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
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:
parent
82e2e382f1
commit
53beef47ea
@ -76,10 +76,12 @@ const makeRequest = (
|
||||
) => {
|
||||
return (dispatch, getState) => {
|
||||
const source = getState().tables.currentDataSource;
|
||||
const { resourceVersion } = getState().metadata;
|
||||
const upQuery = {
|
||||
type: 'bulk',
|
||||
source,
|
||||
args: upQueries,
|
||||
resource_version: resourceVersion,
|
||||
};
|
||||
|
||||
const downQuery = {
|
||||
|
@ -601,7 +601,8 @@ export const getUntrackFunctionQuery = (
|
||||
name: string,
|
||||
schema: string,
|
||||
source: string
|
||||
) => getMetadataQuery('untrack_function', source, { name, schema });
|
||||
) =>
|
||||
getMetadataQuery('untrack_function', source, { function: { name, schema } });
|
||||
|
||||
export const getRenameRelationshipQuery = (
|
||||
table: QualifiedTable,
|
||||
|
@ -140,8 +140,10 @@ Remove an SQL function ``search_articles``:
|
||||
{
|
||||
"type": "pg_untrack_function",
|
||||
"args": {
|
||||
"function": {
|
||||
"schema": "public",
|
||||
"name": "search_articles",
|
||||
"name": "search_articles"
|
||||
},
|
||||
"source": "default"
|
||||
}
|
||||
}
|
||||
@ -156,7 +158,7 @@ Args syntax
|
||||
- Required
|
||||
- Schema
|
||||
- Description
|
||||
* - table
|
||||
* - function
|
||||
- true
|
||||
- :ref:`FunctionName <FunctionName>`
|
||||
- Name of the SQL function
|
||||
|
@ -104,12 +104,37 @@ instance (Backend b) => ToJSON (UnTrackFunction b) where
|
||||
toJSON = genericToJSON hasuraJSON
|
||||
|
||||
instance (Backend b) => FromJSON (UnTrackFunction b) where
|
||||
parseJSON v = withSource <|> withoutSource
|
||||
where
|
||||
withoutSource = UnTrackFunction <$> parseJSON v <*> pure defaultSource
|
||||
withSource = flip (withObject "UnTrackFunction") v \o ->
|
||||
UnTrackFunction <$> o .: "function"
|
||||
<*> o .:? "source" .!= defaultSource
|
||||
-- Following was the previous implementation, which while seems to be correct,
|
||||
-- has an unexpected behaviour. In the case when @source@ key is present but
|
||||
-- @function@ key is absent, it would silently coerce it into a @default@
|
||||
-- source. The culprint being the _alternative_ operator, which silently fails
|
||||
-- the first parse. This note exists so that we don't try to simplify using
|
||||
-- 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
|
||||
:: forall b m
|
||||
|
Loading…
Reference in New Issue
Block a user