mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-09-20 23:17:30 +03:00
parent
ed3e9caf2f
commit
7151f1387f
@ -303,7 +303,11 @@ withParsed
|
||||
withParsed expectedTy valParser val fn = do
|
||||
parsedVal <- valParser val
|
||||
case unP parsedVal of
|
||||
Nothing -> AnnInpVal expectedTy Nothing <$> fn Nothing
|
||||
Nothing ->
|
||||
if G.isNullable expectedTy
|
||||
then AnnInpVal expectedTy Nothing <$> fn Nothing
|
||||
else throwVE $ "null value found for non-nullable type: "
|
||||
<> G.showGT expectedTy
|
||||
Just (Right v) -> AnnInpVal expectedTy Nothing <$> fn (Just v)
|
||||
Just (Left (var, v)) -> do
|
||||
let varTxt = G.unName $ G.unVariable var
|
||||
|
@ -0,0 +1,19 @@
|
||||
description: Passing null value for non nullable type
|
||||
url: /v1alpha1/graphql
|
||||
status: 400
|
||||
response:
|
||||
errors:
|
||||
- extensions:
|
||||
path: "$.selectionSet.update_author.args.where"
|
||||
code: "validation-failed"
|
||||
message: "null value found for non-nullable type: author_bool_exp!"
|
||||
query:
|
||||
query: |
|
||||
mutation update_author {
|
||||
update_author(where: null _set: {name: ""}) {
|
||||
returning {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
description: Passing null value for non nullable type
|
||||
url: /v1alpha1/graphql
|
||||
status: 400
|
||||
response:
|
||||
errors:
|
||||
- extensions:
|
||||
path: "$.variableValues.author_id"
|
||||
code: "validation-failed"
|
||||
message: "null value found for non-nullable type: Int!"
|
||||
query:
|
||||
variables:
|
||||
author_id: null
|
||||
query: |
|
||||
mutation update_author($author_id: Int!) {
|
||||
update_author(where: {id: {_eq: $author_id}}, _set: {name: ""}) {
|
||||
returning {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
15
server/tests-py/queries/graphql_validation/setup.yaml
Normal file
15
server/tests-py/queries/graphql_validation/setup.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
type: bulk
|
||||
args:
|
||||
|
||||
#Author table
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
create table author(
|
||||
id serial primary key,
|
||||
name text unique
|
||||
);
|
||||
- type: track_table
|
||||
args:
|
||||
schema: public
|
||||
name: author
|
6
server/tests-py/queries/graphql_validation/teardown.yaml
Normal file
6
server/tests-py/queries/graphql_validation/teardown.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
type: bulk
|
||||
args:
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
drop table author
|
@ -51,8 +51,9 @@ class DefaultTestMutations(ABC):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class DefaultTestSelectQueries(ABC):
|
||||
# Any test which has a setup and a teardown
|
||||
# Ideally, DefaultTestSelectQueries should just be this
|
||||
class GraphQLEngineTest(ABC):
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def transact(self, request, hge_ctx):
|
||||
@ -69,3 +70,6 @@ class DefaultTestSelectQueries(ABC):
|
||||
@abstractmethod
|
||||
def dir(self):
|
||||
pass
|
||||
|
||||
class DefaultTestSelectQueries(GraphQLEngineTest):
|
||||
pass
|
||||
|
20
server/tests-py/test_validation.py
Normal file
20
server/tests-py/test_validation.py
Normal file
@ -0,0 +1,20 @@
|
||||
import pytest
|
||||
import yaml
|
||||
from validate import check_query_f
|
||||
from super_classes import GraphQLEngineTest
|
||||
|
||||
# @pytest.mark.parametrize("transport", ['http','websocket'])
|
||||
# graphql parser can't seem to parse {where: null}, disabling
|
||||
# websocket till then
|
||||
@pytest.mark.parametrize("transport", ['http'])
|
||||
class TestGraphQLValidation(GraphQLEngineTest):
|
||||
|
||||
def test_null_value(self, hge_ctx, transport):
|
||||
check_query_f(hge_ctx, self.dir() + "/null_value_err.yaml", transport)
|
||||
|
||||
def test_null_variable_value(self, hge_ctx, transport):
|
||||
check_query_f(hge_ctx, self.dir() + "/null_variable_value_err.yaml", transport)
|
||||
|
||||
@classmethod
|
||||
def dir(cls):
|
||||
return "queries/graphql_validation"
|
Loading…
Reference in New Issue
Block a user