Split single and multiple directives tests
@@ -11,21 +11,6 @@ from ariadne import (
)
-def test_directives():
- type_defs = """
- directive @upper on FIELD_DEFINITION
- directive @reverse on FIELD_DEFINITION
-
- type Query {
- test: Custom
- }
-
- type Custom {
- node: String @upper
- name: String @reverse @upper
- }
- """
-
class UpperDirective(SchemaDirectiveVisitor):
def visit_field_definition(
self,
@@ -41,6 +26,7 @@ def test_directives():
field.resolve = resolve_upper
return field
+
class ReverseDirective(SchemaDirectiveVisitor):
def visit_field_definition(
self,
@@ -49,13 +35,29 @@ def test_directives():
) -> GraphQLField:
original_resolver = field.resolve or default_field_resolver
- def resolve_upper(obj, info, **kwargs):
+ def resolve_reverse(obj, info, **kwargs):
result = original_resolver(obj, info, **kwargs)
return result[::-1]
- field.resolve = resolve_upper
+ field.resolve = resolve_reverse
return field
+
+def test_single_directive_without_args():
+ type_defs = """
+ directive @upper on FIELD_DEFINITION
+ directive @reverse on FIELD_DEFINITION
+
+ type Query {
+ test: Custom
+ }
+
+ type Custom {
+ node: String @upper
+ name: String @reverse
+ }
+ """
+
query = QueryType()
query.set_field("test", lambda *_: {"node": "custom", "name": "uppercase"})
upper_dir = DirectiveType("upper", UpperDirective)
@@ -65,4 +67,26 @@ def test_directives():
result = graphql_sync(schema, "{ test { node name }}")
assert result.errors is None
- assert result.data == {"test": {"node": "CUSTOM", "name": "ESACREPPU"}}
+ assert result.data == {"test": {"node": "CUSTOM", "name": "esacreppu"}}
+
+
+def test_many_directives_without_args():
+ type_defs = """
+ directive @upper on FIELD_DEFINITION
+ directive @reverse on FIELD_DEFINITION
+
+ type Query {
+ hello: String @upper @reverse
+ }
+ """
+
+ query = QueryType()
+ query.set_field("hello", lambda *_: "hello world")
+ upper_dir = DirectiveType("upper", UpperDirective)
+ reverse_dir = DirectiveType("reverse", ReverseDirective)
+
+ schema = make_executable_schema(type_defs, [query, upper_dir, reverse_dir])
+
+ result = graphql_sync(schema, "{ hello }")
+ assert result.errors is None
+ assert result.data == {"hello": "DLROW OLLEH"}
