Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Permissions: applying IsAuthenticated directive to entire schema #187

Open
gghdev opened this issue Mar 14, 2023 · 3 comments
Open

Permissions: applying IsAuthenticated directive to entire schema #187

gghdev opened this issue Mar 14, 2023 · 3 comments

Comments

@gghdev
Copy link

gghdev commented Mar 14, 2023

Hi there,

Instead of applying the IsAuthenticated() directive to individual fields, I'm looking to apply this to an entire schema.

I'd wondered if this might work, but it doesn't:

authenticated_schema = gql.Schema(
    query=AuthenticatedQueries,
    mutation=AuthenticatedMutations,
    extensions=[SchemaDirectiveExtension],
    directives=[IsAuthenticated()]
)

I get a type error:
Expected type 'Iterable[StrawberryDirective]', got 'list[IsAuthenticated]' instead
And an actual error:
AttributeError: 'IsAuthenticated' object has no attribute 'arguments'.

Any thoughts?

@bellini666
Copy link
Member

Hey @gghdev ,

That directives argument in Schema is just so that you can pass directives that can be used by the client, like this one (strawberry has support for that but it is missing documentation)

There isn't an easy way to insert IsAuthenticated in all queries currently, but if you ensure that all queries inside the Query type and all mutations inside the Mutation type have this directive, then it should do what you need, since the root queries are required to retrieve any information below them

@Mapiarz
Copy link

Mapiarz commented Mar 21, 2023

@bellini666 So I presume there's no way to apply a directive to an object either? Would that be difficult to implement? Where one would have to start?

@bellini666
Copy link
Member

@Mapiarz I believe that this functionality that got merged on strawberry some days ago is thr way to go.

I'll actually rewrite the permissioning to use it when porting it to strawberry-graphql-django

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants