11import re
22
33import pytest
4- from hypothesis import given
4+ from hypothesis import find , given
55from hypothesis import strategies as st
66from hypothesis .errors import InvalidArgument
77
88from hypothesis_graphql import nodes
99from hypothesis_graphql import strategies as gql_st
10- from hypothesis_graphql ._strategies import factories
1110
1211CUSTOM_SCALAR_TEMPLATE = """
1312scalar Date
2120 id: String!
2221}}
2322
23+ input RequiredQueryInput {{
24+ created: Date!
25+ }}
26+
2427type Query {{
2528 {query}
2629}}
@@ -62,25 +65,24 @@ def test(query):
6265 assert num_of_queries == 2
6366
6467
68+ @pytest .mark .parametrize ("input_type" , ("Date" , "RequiredQueryInput" ))
6569@given (data = st .data ())
66- def test_custom_scalar_argument (data ):
70+ def test_custom_scalar_argument (data , input_type ):
6771 # When a custom scalar type is defined
6872 # And is used in an argument position
6973 # And is not nullable
7074
71- schema = CUSTOM_SCALAR_TEMPLATE .format (query = "getByDate(created: Date !): Object" )
75+ schema = CUSTOM_SCALAR_TEMPLATE .format (query = f "getByDate(created: { input_type } !): Object" )
7276
7377 with pytest .raises (TypeError , match = "Scalar 'Date' is not supported" ):
7478 data .draw (gql_st .queries (schema ))
7579
7680
77- @given (data = st .data ())
7881@pytest .mark .parametrize ("other_type" , ("String!" , "String" ))
79- def test_custom_scalar_nested_argument (data , validate_operation , other_type ):
82+ def test_custom_scalar_nested_argument (validate_operation , other_type ):
8083 # When a custom scalar type is defined
8184 # And is used as a field inside an input type
8285 # And is nullable
83-
8486 schema = f"""
8587scalar Date
8688
@@ -94,8 +96,15 @@ def test_custom_scalar_nested_argument(data, validate_operation, other_type):
9496}}"""
9597
9698 # Then it could be skipped
97- query = data .draw (gql_st .queries (schema ))
98- validate_operation (schema , query )
99+ strategy = gql_st .queries (schema )
100+
101+ @given (strategy )
102+ def test (query ):
103+ validate_operation (schema , query )
104+
105+ test ()
106+ # And "id" is still possible to generate
107+ assert find (strategy , lambda x : "id" in x ).strip () == '{\n getByDate(created: {id: ""})\n }'
99108
100109
101110@given (data = st .data ())
0 commit comments