Parse session variables to their correct type in mssql

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2908
GitOrigin-RevId: d9d8811e0d0658f6396a7c94bce9b7d2deb5245e
This commit is contained in:
Gil Mizrahi 2021-11-20 11:02:49 +02:00 committed by hasura-bot
parent 0e65932355
commit 39002bc572
4 changed files with 43 additions and 2 deletions

View File

@ -33,6 +33,7 @@ import Hasura.Prelude hiding (first)
import Hasura.RQL.IR
import Hasura.RQL.Types.Column qualified as RQL
import Hasura.SQL.Backend
import Hasura.SQL.Types
import Hasura.Session
import Language.GraphQL.Draft.Syntax qualified as G
@ -66,11 +67,18 @@ prepareValueQuery sessionVariables =
GraphQL.UVLiteral x -> pure x
GraphQL.UVSession -> pure $ ValueExpression $ ODBC.ByteStringValue $ toStrict $ J.encode sessionVariables
GraphQL.UVParameter _ RQL.ColumnValue {..} -> pure $ ValueExpression cvValue
GraphQL.UVSessionVar _typ sessionVariable -> do
GraphQL.UVSessionVar typ sessionVariable -> do
value <-
getSessionVariableValue sessionVariable sessionVariables
`onNothing` throw400 NotFound ("missing session variable: " <>> sessionVariable)
pure $ ValueExpression $ ODBC.TextValue value
-- See https://github.com/fpco/odbc/pull/34#issuecomment-812223147
-- We first cast to nvarchar(max) because casting from ntext is not supported
CastExpression (CastExpression (ValueExpression $ ODBC.TextValue value) "nvarchar(max)")
<$> case typ of
CollectableTypeScalar baseTy ->
pure (scalarTypeDBName baseTy)
CollectableTypeArray {} ->
throw400 NotSupported "Array types are currently not supported in MS SQL Server"
planSubscription ::
MonadError QErr m =>

View File

@ -0,0 +1,20 @@
description: Author can view their information only
url: /v1/graphql
status: 200
headers:
X-Hasura-Role: user
X-Hasura-User-Id: '2'
response:
data:
author:
- id: 2
name: Author 2
query:
query: |
query {
author {
id
name
}
}

View File

@ -99,3 +99,12 @@ args:
foreign_key_constraint_on:
table: article_multi
columns: ["author_id1", "author_id2"]
- type: mssql_create_select_permission
args:
source: mssql
table: author
role: user
permission:
columns: "*"
filter: {"id":{"_eq":"X-Hasura-User-Id"}}

View File

@ -342,6 +342,10 @@ class TestGraphQLQueryBasicMSSQL:
def test_select_query_author_pk_null(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_author_by_pkey_null.yaml', transport)
def test_author_with_permission(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/author_with_permission_mssql.yaml', transport)
@classmethod
def dir(cls):
return 'queries/graphql_query/basic'