Last active
April 8, 2025 02:01
-
-
Save reallistic/79782004a19fa6cb76fbdac607a0dee8 to your computer and use it in GitHub Desktop.
ariadne-auth nested decorators error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio, dataclasses | |
from ariadne import make_executable_schema, graphql, QueryType | |
from ariadne_auth.authz import AuthorizationExtension | |
class AlwaysHasPermission: | |
@classmethod | |
def has_permissions(cls, *_): | |
return True | |
authz = AuthorizationExtension(lambda *_: AlwaysHasPermission) | |
query = QueryType() | |
def inject_user(resolver): | |
def wrapper(obj, info, *args, **kwargs): | |
return resolver(obj, info, kwargs["uid"], *args, **kwargs) | |
return wrapper | |
@query.field("posts") | |
@inject_user | |
@authz.require_permissions(["read:Posts"]) | |
async def resolve_posts(_obj, _info, uid, *args, **kwargs): | |
return ["hello world"] | |
schema = make_executable_schema("type Query { posts(uid: Int): [String] }", query) | |
print(asyncio.run(graphql(schema, {"query": "{ posts(uid: 1) }"}, extensions=[authz]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment