Skip to content

Commit

Permalink
Add test for arguments with description
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Aug 6, 2022
1 parent 0b8e8ce commit 2152c8b
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/test_printer/test_schema_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def hello(
str, strawberry.argument(directives=[Sensitive(reason="example")])
],
) -> str:
return "Hello " + name
return f"Hello {name} of {age}"

expected_output = """
directive @sensitive(reason: String!) on ARGUMENT_DEFINITION
Expand All @@ -584,3 +584,42 @@ def hello(
schema = strawberry.Schema(query=Query)

assert print_schema(schema) == textwrap.dedent(expected_output).strip()


def test_print_directive_on_argument_with_description():
@strawberry.schema_directive(locations=[Location.ARGUMENT_DEFINITION])
class Sensitive:
reason: str

@strawberry.type
class Query:
@strawberry.field
def hello(
self,
name: Annotated[
str,
strawberry.argument(
description="Name", directives=[Sensitive(reason="example")]
),
],
age: Annotated[
str, strawberry.argument(directives=[Sensitive(reason="example")])
],
) -> str:
return f"Hello {name} of {age}"

expected_output = """
directive @sensitive(reason: String!) on ARGUMENT_DEFINITION
type Query {
hello(
\"\"\"Name\"\"\"
name: String! @sensitive(reason: "example")
age: String! @sensitive(reason: "example")
): String!
}
"""

schema = strawberry.Schema(query=Query)

assert print_schema(schema) == textwrap.dedent(expected_output).strip()

0 comments on commit 2152c8b

Please sign in to comment.