class UnauthorizedException(Exception):
pass
class FeaturesRequired(BasePermission):
message = "Keine Rechte"
error_class = UnauthorizedException
error_extensions = {"code": 401}
def __init__(self, *features):
self.features = features
async def has_permission(self, source: Any, info: Info, **kwargs) -> bool:
return 'test' in self.features
@strawberry.type
class MyType:
@strawberry.field(extensions=[PermissionExtension(permissions=[FeaturesRequired('test')])])
def hello(self) -> str:
return 'world'
# schema_1.py
@strawberry.type
class Query1:
@strawberry.field
def my_type(self, info: Info) -> MyType:
return MyType()
schema_1 = Schema(query=Query)
# schema_2.py:
@strawberry.type
class Query2:
@strawberry.field
def my_type(self, info: Info) -> MyType:
return MyType()
schema_2 = Schema(query=Query)
generate the gql file:
from schema_1 import schema_1
from strawberry.printer import print_schema
with open('test.graphql', 'w') as f:
f.write(print_schema(schema_1))
generates:
hello: String! @featuresRequired @featuresRequired
which leads to errors in vsc like The directive "@featuresRequired" can only be used once at this location.
Bug: This code is getting called twice, one time for schema_1 and one time for schema_2
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too