Skip to content

Commit

Permalink
added a test
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Bayr committed Oct 21, 2024
1 parent e89afd1 commit d77bc51
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/test_printer/test_schema_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing_extensions import Annotated

import strawberry
from strawberry import BasePermission, Info
from strawberry.permission import PermissionExtension
from strawberry.printer import print_schema
from strawberry.schema.config import StrawberryConfig
from strawberry.schema_directive import Location
Expand Down Expand Up @@ -531,6 +533,65 @@ class Query:

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

def test_dedupe_multiple_equal_directives():
class MemberRoleRequired(BasePermission):
message = "Keine Rechte"

def has_permission(self, source, info: Info, **kwargs) -> bool:
return True

@strawberry.interface
class MyInterface:
id: strawberry.ID

@strawberry.field(extensions=[PermissionExtension(permissions=[MemberRoleRequired()])])
def hello(info: Info) -> str:
return 'world'

@strawberry.type
class MyType1(MyInterface):
name: str

@strawberry.type
class MyType2(MyInterface):
age: int

@strawberry.type
class Query:

@strawberry.field
def my_type(info: Info) -> MyInterface:
return MyType1(id='1', name='Hello')

expected_output = """
directive @memberRoleRequired on FIELD_DEFINITION
interface MyInterface {
id: ID!
hello: String! @memberRoleRequired
}
type MyType1 implements MyInterface {
id: ID!
hello: String! @memberRoleRequired
name: String!
}
type MyType2 implements MyInterface {
id: ID!
hello: String! @memberRoleRequired
age: Int!
}
type Query {
myType: MyInterface!
}
"""

schema = strawberry.Schema(Query, types=[MyType1, MyType2])

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


def test_print_directive_on_union():
@strawberry.type
Expand Down

0 comments on commit d77bc51

Please sign in to comment.