mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-20 06:58:39 +03:00
server: fix bug when executing a custom function with a row type argument
GitOrigin-RevId: d3a1fa8c9f6b420f4c88eb60c92019c8d0fdc58d
This commit is contained in:
parent
3fad5f6678
commit
d7ccf81526
@ -6,6 +6,7 @@
|
||||
|
||||
(Add entries below in the order of: server, console, cli, docs, others)
|
||||
|
||||
- server: fix query execution of custom function containing a composite argument type
|
||||
- server: fix a bug in query validation that would cause some queries using default variable values to be rejected (fix #6867)
|
||||
- server: custom URI schemes are now supported in CORS config (fix #5818) (#5940)
|
||||
- console: read-only modify page for mssql
|
||||
|
@ -285,6 +285,7 @@ data PGScalarType
|
||||
| PGLquery
|
||||
| PGLtxtquery
|
||||
| PGUnknown !Text
|
||||
| PGCompositeScalar !Text
|
||||
deriving (Show, Eq, Ord, Generic, Data)
|
||||
instance NFData PGScalarType
|
||||
instance Hashable PGScalarType
|
||||
@ -292,34 +293,35 @@ instance Cacheable PGScalarType
|
||||
|
||||
instance ToSQL PGScalarType where
|
||||
toSQL = \case
|
||||
PGSmallInt -> "smallint"
|
||||
PGInteger -> "integer"
|
||||
PGBigInt -> "bigint"
|
||||
PGSerial -> "serial"
|
||||
PGBigSerial -> "bigserial"
|
||||
PGFloat -> "real"
|
||||
PGDouble -> "float8"
|
||||
PGNumeric -> "numeric"
|
||||
PGMoney -> "money"
|
||||
PGBoolean -> "boolean"
|
||||
PGChar -> "bpchar"
|
||||
PGVarchar -> "varchar"
|
||||
PGText -> "text"
|
||||
PGCitext -> "citext"
|
||||
PGDate -> "date"
|
||||
PGTimeStamp -> "timestamp"
|
||||
PGTimeStampTZ -> "timestamptz"
|
||||
PGTimeTZ -> "timetz"
|
||||
PGJSON -> "json"
|
||||
PGJSONB -> "jsonb"
|
||||
PGGeometry -> "geometry"
|
||||
PGGeography -> "geography"
|
||||
PGRaster -> "raster"
|
||||
PGUUID -> "uuid"
|
||||
PGLtree -> "ltree"
|
||||
PGLquery -> "lquery"
|
||||
PGLtxtquery -> "ltxtquery"
|
||||
PGUnknown t -> TB.text t
|
||||
PGSmallInt -> "smallint"
|
||||
PGInteger -> "integer"
|
||||
PGBigInt -> "bigint"
|
||||
PGSerial -> "serial"
|
||||
PGBigSerial -> "bigserial"
|
||||
PGFloat -> "real"
|
||||
PGDouble -> "float8"
|
||||
PGNumeric -> "numeric"
|
||||
PGMoney -> "money"
|
||||
PGBoolean -> "boolean"
|
||||
PGChar -> "bpchar"
|
||||
PGVarchar -> "varchar"
|
||||
PGText -> "text"
|
||||
PGCitext -> "citext"
|
||||
PGDate -> "date"
|
||||
PGTimeStamp -> "timestamp"
|
||||
PGTimeStampTZ -> "timestamptz"
|
||||
PGTimeTZ -> "timetz"
|
||||
PGJSON -> "json"
|
||||
PGJSONB -> "jsonb"
|
||||
PGGeometry -> "geometry"
|
||||
PGGeography -> "geography"
|
||||
PGRaster -> "raster"
|
||||
PGUUID -> "uuid"
|
||||
PGLtree -> "ltree"
|
||||
PGLquery -> "lquery"
|
||||
PGLtxtquery -> "ltxtquery"
|
||||
PGUnknown t -> TB.text t
|
||||
PGCompositeScalar t -> TB.text t
|
||||
|
||||
instance ToJSON PGScalarType where
|
||||
toJSON = String . toSQLTxt
|
||||
@ -509,12 +511,7 @@ typeToTable (QualifiedPGType sch n _) =
|
||||
mkFunctionArgScalarType :: QualifiedPGType -> PGScalarType
|
||||
mkFunctionArgScalarType (QualifiedPGType _schema name type') =
|
||||
case type' of
|
||||
-- When the function argument is a row type argument
|
||||
-- then it's possible that there can be an object type
|
||||
-- with the table name depending upon whether the table
|
||||
-- is tracked or not. As a result, we get a conflict between
|
||||
-- both these types (scalar and object type with same name).
|
||||
-- To avoid this, we suffix the table name with `_scalar`
|
||||
-- and create a new scalar type
|
||||
PGKindComposite -> PGUnknown $ toTxt name <> "_scalar"
|
||||
-- The suffix `_scalar` is added in
|
||||
-- the @mkScalarTypeName@ function.
|
||||
PGKindComposite -> PGCompositeScalar $ toTxt name
|
||||
_ -> name
|
||||
|
@ -202,6 +202,8 @@ parsePGValue ty val = case (ty, val) of
|
||||
PGLtxtquery -> PGValLtxtquery <$> parseJSON val
|
||||
PGUnknown tyName ->
|
||||
fail $ "A string is expected for type: " ++ T.unpack tyName
|
||||
PGCompositeScalar tyName ->
|
||||
fail $ "A string is expected for type: " ++ T.unpack tyName
|
||||
|
||||
txtEncodedVal :: PGScalarValue -> TxtEncodedVal
|
||||
txtEncodedVal = \case
|
||||
@ -243,34 +245,35 @@ txtEncodedVal = \case
|
||||
|
||||
pgTypeOid :: PGScalarType -> PQ.Oid
|
||||
pgTypeOid = \case
|
||||
PGSmallInt -> PTI.int2
|
||||
PGInteger -> PTI.int4
|
||||
PGBigInt -> PTI.int8
|
||||
PGSerial -> PTI.int4
|
||||
PGBigSerial -> PTI.int8
|
||||
PGFloat -> PTI.float4
|
||||
PGDouble -> PTI.float8
|
||||
PGNumeric -> PTI.numeric
|
||||
PGMoney -> PTI.numeric
|
||||
PGBoolean -> PTI.bool
|
||||
PGChar -> PTI.char
|
||||
PGVarchar -> PTI.varchar
|
||||
PGText -> PTI.text
|
||||
PGCitext -> PTI.text -- Explict type cast to citext needed, See also Note [Type casting prepared params]
|
||||
PGDate -> PTI.date
|
||||
PGTimeStamp -> PTI.timestamp
|
||||
PGTimeStampTZ -> PTI.timestamptz
|
||||
PGTimeTZ -> PTI.timetz
|
||||
PGJSON -> PTI.json
|
||||
PGJSONB -> PTI.jsonb
|
||||
PGGeometry -> PTI.text -- we are using the ST_GeomFromGeoJSON($i) instead of $i
|
||||
PGGeography -> PTI.text
|
||||
PGRaster -> PTI.text -- we are using the ST_RastFromHexWKB($i) instead of $i
|
||||
PGUUID -> PTI.uuid
|
||||
PGLtree -> PTI.text
|
||||
PGLquery -> PTI.text
|
||||
PGLtxtquery -> PTI.text
|
||||
(PGUnknown _) -> PTI.auto
|
||||
PGSmallInt -> PTI.int2
|
||||
PGInteger -> PTI.int4
|
||||
PGBigInt -> PTI.int8
|
||||
PGSerial -> PTI.int4
|
||||
PGBigSerial -> PTI.int8
|
||||
PGFloat -> PTI.float4
|
||||
PGDouble -> PTI.float8
|
||||
PGNumeric -> PTI.numeric
|
||||
PGMoney -> PTI.numeric
|
||||
PGBoolean -> PTI.bool
|
||||
PGChar -> PTI.char
|
||||
PGVarchar -> PTI.varchar
|
||||
PGText -> PTI.text
|
||||
PGCitext -> PTI.text -- Explict type cast to citext needed, See also Note [Type casting prepared params]
|
||||
PGDate -> PTI.date
|
||||
PGTimeStamp -> PTI.timestamp
|
||||
PGTimeStampTZ -> PTI.timestamptz
|
||||
PGTimeTZ -> PTI.timetz
|
||||
PGJSON -> PTI.json
|
||||
PGJSONB -> PTI.jsonb
|
||||
PGGeometry -> PTI.text -- we are using the ST_GeomFromGeoJSON($i) instead of $i
|
||||
PGGeography -> PTI.text
|
||||
PGRaster -> PTI.text -- we are using the ST_RastFromHexWKB($i) instead of $i
|
||||
PGUUID -> PTI.uuid
|
||||
PGLtree -> PTI.text
|
||||
PGLquery -> PTI.text
|
||||
PGLtxtquery -> PTI.text
|
||||
(PGUnknown _) -> PTI.auto
|
||||
PGCompositeScalar _ -> PTI.auto
|
||||
|
||||
binEncoder :: PGScalarValue -> Q.PrepArg
|
||||
binEncoder = \case
|
||||
|
@ -392,6 +392,17 @@ mkScalarTypeName PG.PGBoolean = pure boolScalar
|
||||
mkScalarTypeName PG.PGFloat = pure floatScalar
|
||||
mkScalarTypeName PG.PGText = pure stringScalar
|
||||
mkScalarTypeName PG.PGVarchar = pure stringScalar
|
||||
mkScalarTypeName (PG.PGCompositeScalar compositeScalarType) =
|
||||
-- When the function argument is a row type argument
|
||||
-- then it's possible that there can be an object type
|
||||
-- with the table name depending upon whether the table
|
||||
-- is tracked or not. As a result, we get a conflict between
|
||||
-- both these types (scalar and object type with same name).
|
||||
-- To avoid this, we suffix the table name with `_scalar`
|
||||
-- and create a new scalar type
|
||||
(<> $$(G.litName "_scalar")) <$> G.mkName compositeScalarType `onNothing` throw400 ValidationFailed
|
||||
("cannot use SQL type " <> compositeScalarType <<> " in the GraphQL schema because its name is not a "
|
||||
<> "valid GraphQL identifier")
|
||||
mkScalarTypeName scalarType = G.mkName (toSQLTxt scalarType) `onNothing` throw400 ValidationFailed
|
||||
("cannot use SQL type " <> scalarType <<> " in the GraphQL schema because its name is not a "
|
||||
<> "valid GraphQL identifier")
|
||||
|
@ -38,3 +38,20 @@
|
||||
kind
|
||||
}
|
||||
}
|
||||
|
||||
- description: Execute the tracked function with a composite row type argument
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
query:
|
||||
query: |
|
||||
query {
|
||||
search_post_by_test (args: {t: "(1, hasura,311cf381-71e7-449b-bac5-86cd6deafd5b)"}) {
|
||||
title
|
||||
content
|
||||
}
|
||||
}
|
||||
response:
|
||||
data:
|
||||
search_post_by_test:
|
||||
- title: post by hasura
|
||||
content: content for post
|
||||
|
Loading…
Reference in New Issue
Block a user