mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
bugfix(NativeQueries): fix validation failed on name with uppercase on postgres
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8790 GitOrigin-RevId: f3b9b041fd96c6087ff4bd3379ef6283befcdc54
This commit is contained in:
parent
41ed0d369b
commit
5ed9fcc0a3
@ -350,6 +350,34 @@ tests = do
|
||||
path: $.args
|
||||
|]
|
||||
|
||||
it "when the native query name has a non-standard character" $
|
||||
\testEnvironment -> do
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ getBackendTypeConfig testEnvironment
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
|
||||
dividedStuffNativeQuery :: Schema.NativeQuery
|
||||
dividedStuffNativeQuery =
|
||||
(Schema.nativeQuery "Divided-Stuff" simpleQuery "divided_stuff")
|
||||
{ Schema.nativeQueryArguments =
|
||||
[ Schema.nativeQueryColumn "denominator" Schema.TInt,
|
||||
Schema.nativeQueryColumn "target_date" Schema.TUTCTime
|
||||
]
|
||||
}
|
||||
|
||||
Schema.trackCustomReturnType sourceName dividedReturnType testEnvironment
|
||||
|
||||
actual <-
|
||||
GraphqlEngine.postMetadataWithStatus
|
||||
400
|
||||
testEnvironment
|
||||
(Schema.trackNativeQueryCommand sourceName backendTypeMetadata dividedStuffNativeQuery)
|
||||
let expected =
|
||||
[yaml|
|
||||
code: parse-failed
|
||||
path: $.args.root_field_name
|
||||
|]
|
||||
actual `shouldAtLeastBe` expected
|
||||
|
||||
describe "Validation succeeds" do
|
||||
it "when tracking then untracking then re-tracking a native query" $
|
||||
\testEnvironment -> do
|
||||
@ -372,3 +400,21 @@ tests = do
|
||||
Schema.untrackNativeQuery sourceName dividedStuffNativeQuery testEnvironment
|
||||
|
||||
Schema.trackNativeQuery sourceName dividedStuffNativeQuery testEnvironment
|
||||
|
||||
it "when the native query name has an uppercase letter" $
|
||||
\testEnvironment -> do
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ getBackendTypeConfig testEnvironment
|
||||
sourceName = BackendType.backendSourceName backendTypeMetadata
|
||||
|
||||
dividedStuffNativeQuery :: Schema.NativeQuery
|
||||
dividedStuffNativeQuery =
|
||||
(Schema.nativeQuery "DividedStuff" simpleQuery "divided_stuff")
|
||||
{ Schema.nativeQueryArguments =
|
||||
[ Schema.nativeQueryColumn "denominator" Schema.TInt,
|
||||
Schema.nativeQueryColumn "target_date" Schema.TUTCTime
|
||||
]
|
||||
}
|
||||
|
||||
Schema.trackCustomReturnType sourceName dividedReturnType testEnvironment
|
||||
|
||||
Schema.trackNativeQuery sourceName dividedStuffNativeQuery testEnvironment
|
||||
|
@ -244,6 +244,42 @@ tests = do
|
||||
|
||||
shouldReturnYaml testEnvironment actual expected
|
||||
|
||||
it "Runs the a simple query with uppercase letters in the name" $ \testEnvironment -> do
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ getBackendTypeConfig testEnvironment
|
||||
source = BackendType.backendSourceName backendTypeMetadata
|
||||
|
||||
uppercaseNativeQuery :: Schema.NativeQuery
|
||||
uppercaseNativeQuery =
|
||||
(Schema.nativeQuery "UppercaseNativeQuery" query "hello_world_return_type")
|
||||
|
||||
Schema.trackCustomReturnType source helloWorldReturnType testEnvironment
|
||||
Schema.trackNativeQuery source uppercaseNativeQuery testEnvironment
|
||||
|
||||
let expected =
|
||||
[yaml|
|
||||
data:
|
||||
UppercaseNativeQuery:
|
||||
- one: "hello"
|
||||
two: "world"
|
||||
- one: "welcome"
|
||||
two: "friend"
|
||||
|]
|
||||
|
||||
actual :: IO Value
|
||||
actual =
|
||||
GraphqlEngine.postGraphql
|
||||
testEnvironment
|
||||
[graphql|
|
||||
query {
|
||||
UppercaseNativeQuery {
|
||||
one
|
||||
two
|
||||
}
|
||||
}
|
||||
|]
|
||||
|
||||
shouldReturnYaml testEnvironment actual expected
|
||||
|
||||
it "Runs simple query with a basic where clause" $ \testEnvironment -> do
|
||||
let backendTypeMetadata = fromMaybe (error "Unknown backend") $ getBackendTypeConfig testEnvironment
|
||||
source = BackendType.backendSourceName backendTypeMetadata
|
||||
|
@ -34,7 +34,7 @@ import Hasura.NativeQuery.Metadata
|
||||
NativeQueryArgumentName,
|
||||
NativeQueryMetadata (..),
|
||||
)
|
||||
import Hasura.NativeQuery.Types (NullableScalarType (nstType), getNativeQueryName)
|
||||
import Hasura.NativeQuery.Types (NullableScalarType (nstType))
|
||||
import Hasura.Prelude
|
||||
import Hasura.SQL.Backend
|
||||
|
||||
@ -205,11 +205,10 @@ nativeQueryToPreparedStatement ::
|
||||
NativeQueryMetadata ('Postgres pgKind) ->
|
||||
m (BS.ByteString, Text)
|
||||
nativeQueryToPreparedStatement customReturnType model = do
|
||||
let name = getNativeQueryName $ _nqmRootFieldName model
|
||||
let (preparedIQ, argumentMapping) = renameIQ $ _nqmCode model
|
||||
logimoCode :: Text
|
||||
logimoCode = renderIQ preparedIQ
|
||||
prepname = "_logimo_vali_" <> toTxt name
|
||||
prepname = "_logimo_vali_"
|
||||
|
||||
occurringArguments, declaredArguments, undeclaredArguments :: Set NativeQueryArgumentName
|
||||
occurringArguments = Set.fromList (Map.elems argumentMapping)
|
||||
|
@ -110,7 +110,7 @@ spec = do
|
||||
(first showQErr actual) `shouldSatisfy` isRight
|
||||
let Right rendered = actual
|
||||
rendered
|
||||
`shouldBe` "PREPARE _logimo_vali_root_field_name(varchar) AS WITH _cte_logimo_vali_root_field_name AS (\nSELECT $1, $1\n)\nSELECT \nFROM _cte_logimo_vali_root_field_name"
|
||||
`shouldBe` "PREPARE _logimo_vali_(varchar) AS WITH _cte_logimo_vali_ AS (\nSELECT $1, $1\n)\nSELECT \nFROM _cte_logimo_vali_"
|
||||
|
||||
it "Handles multiple variables " do
|
||||
let Right code = parseInterpolatedQuery "SELECT {{hey}}, {{ho}}"
|
||||
@ -131,4 +131,4 @@ spec = do
|
||||
(first showQErr actual) `shouldSatisfy` isRight
|
||||
let Right rendered = actual
|
||||
rendered
|
||||
`shouldBe` "PREPARE _logimo_vali_root_field_name(varchar, integer) AS WITH _cte_logimo_vali_root_field_name AS (\nSELECT $1, $2\n)\nSELECT \nFROM _cte_logimo_vali_root_field_name"
|
||||
`shouldBe` "PREPARE _logimo_vali_(varchar, integer) AS WITH _cte_logimo_vali_ AS (\nSELECT $1, $2\n)\nSELECT \nFROM _cte_logimo_vali_"
|
||||
|
Loading…
Reference in New Issue
Block a user