diff --git a/tests/types/test_validators.py b/tests/types/test_validators.py index ffa185577f..be85b7b128 100644 --- a/tests/types/test_validators.py +++ b/tests/types/test_validators.py @@ -2,6 +2,8 @@ def upper_validator(value, info): + if info.context and info.context in value: + raise ValueError("Invalid value") return value.upper() @@ -23,6 +25,11 @@ def type() -> Type: assert not result.errors assert result.data["type"]["string"] == "HELLO" + # error case + result = schema.execute_sync("{ type { string } }", context_value="hello") + + assert result.errors[0].message == "Invalid value" + def test_validator_decorator(): @strawberry.type @@ -68,3 +75,10 @@ def mutation(self, input: Input) -> str: assert not result.errors assert result.data["mutation"] == "HELLO" + + # error case + result = schema.execute_sync( + 'mutation { mutation(input: { string: "hello" }) }', context_value="hello" + ) + + assert result.errors[0].message == "Invalid value"