mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
test: logimo validation prepared statement is deallocated
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8175 GitOrigin-RevId: 35ec7e69b616ebd7a4a30760b1698bd379e07d74
This commit is contained in:
parent
8d02c88c1a
commit
60bd355a99
@ -521,3 +521,51 @@ tests opts = do
|
||||
statement: "PREPARE _logimo_vali_divided_stuff AS SELECT thing / $1 AS divided FROM does_not_exist WHERE date = $2"
|
||||
path: "$.args"
|
||||
|]
|
||||
|
||||
describe "Validation succeeds" do
|
||||
it "when tracking then untracking then re-tracking a logical model" $
|
||||
\testEnv -> do
|
||||
shouldReturnYaml
|
||||
opts
|
||||
( GraphqlEngine.postMetadata
|
||||
testEnv
|
||||
[yaml|
|
||||
type: bulk
|
||||
args:
|
||||
- type: pg_track_logical_model
|
||||
args:
|
||||
type: query
|
||||
source: postgres
|
||||
root_field_name: divided_stuff2
|
||||
code: *simpleQuery
|
||||
arguments:
|
||||
denominator: int
|
||||
target_date: date
|
||||
returns:
|
||||
columns:
|
||||
divided:
|
||||
type: integer
|
||||
- type: pg_untrack_logical_model
|
||||
args:
|
||||
root_field_name: divided_stuff2
|
||||
source: postgres
|
||||
- type: pg_track_logical_model
|
||||
args:
|
||||
type: query
|
||||
source: postgres
|
||||
root_field_name: divided_stuff2
|
||||
code: *simpleQuery
|
||||
arguments:
|
||||
denominator: int
|
||||
target_date: date
|
||||
returns:
|
||||
columns:
|
||||
divided:
|
||||
type: integer
|
||||
|]
|
||||
)
|
||||
[yaml|
|
||||
- message: success
|
||||
- message: success
|
||||
- message: success
|
||||
|]
|
||||
|
@ -32,22 +32,27 @@ validateLogicalModel env connConf model = do
|
||||
i <- get
|
||||
modify (+ 1)
|
||||
pure $ "$" <> tshow i
|
||||
result <-
|
||||
liftIO $
|
||||
withPostgresDB env connConf $
|
||||
PG.rawQE
|
||||
( \e ->
|
||||
(err400 ValidationFailed "Failed to validate query")
|
||||
{ qeInternal = Just $ ExtraInternal $ toJSON e
|
||||
}
|
||||
)
|
||||
(PG.fromText $ "PREPARE _logimo_vali_" <> toTxt name <> " AS " <> code)
|
||||
[]
|
||||
False
|
||||
case result of
|
||||
-- running the query failed
|
||||
Left err ->
|
||||
throwError err
|
||||
-- running the query succeeded
|
||||
Right () ->
|
||||
pure ()
|
||||
runRaw :: (MonadIO m, MonadError QErr m) => PG.Query -> m ()
|
||||
runRaw stmt =
|
||||
liftEither
|
||||
=<< liftIO
|
||||
( withPostgresDB
|
||||
env
|
||||
connConf
|
||||
( PG.rawQE
|
||||
( \e ->
|
||||
(err400 ValidationFailed "Failed to validate query")
|
||||
{ qeInternal = Just $ ExtraInternal $ toJSON e
|
||||
}
|
||||
)
|
||||
stmt
|
||||
[]
|
||||
False
|
||||
)
|
||||
)
|
||||
prepname = "_logimo_vali_" <> toTxt name
|
||||
|
||||
-- We don't need to deallocate because 'withPostgresDB' opens a connection,
|
||||
-- runs a statement, and then closes the connection. Since a prepared statement only
|
||||
-- lasts the duration of the session, once it closes, it is deallocated as well.
|
||||
runRaw (PG.fromText $ "PREPARE " <> prepname <> " AS " <> code)
|
||||
|
Loading…
Reference in New Issue
Block a user