这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion server/src-lib/Hasura/GraphQL/Validate/InputValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions server/tests-py/queries/graphql_validation/null_value_err.yaml
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions server/tests-py/queries/graphql_validation/setup.yaml
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions server/tests-py/queries/graphql_validation/teardown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: bulk
args:
- type: run_sql
args:
sql: |
drop table author
8 changes: 6 additions & 2 deletions server/tests-py/super_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def dir(self):
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):
Expand All @@ -69,3 +70,6 @@ def ensure_transact(self, transact):
@abstractmethod
def dir(self):
pass

class DefaultTestSelectQueries(GraphQLEngineTest):
pass
20 changes: 20 additions & 0 deletions server/tests-py/test_validation.py
Original file line number Diff line number Diff line change
@@ -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"