Skip to content

Commit

Permalink
keep order
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Bayr committed Oct 21, 2024
1 parent a736a61 commit 9b4e9c9
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions strawberry/permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,15 @@ def __init__(
self.use_directives = use_directives

def apply(self, field: StrawberryField) -> None:
"""Applies all of the permission directives to the schema and sets up silent permissions."""
"""Applies all of the permission directives (deduped) to the schema and sets up silent permissions."""
if self.use_directives:
# Dedupe multiple directives
# https://github.com/strawberry-graphql/strawberry/issues/3596
permission_directives = {
p.schema_directive for p in self.permissions if p.schema_directive
}
existing_field_directives = set(field.directives)
extend_directives = permission_directives - existing_field_directives
field.directives.extend(extend_directives)
permission_directives = [perm.schema_directive for perm in self.permissions if perm.schema_directive]
# Iteration, because we want to keep order
for perm_directive in permission_directives:
# Dedupe multiple directives
if perm_directive in field.directives:
continue
field.directives.append(perm_directive)
# We can only fail silently if the field is optional or a list
if self.fail_silently:
if isinstance(field.type, StrawberryOptional):
Expand Down

0 comments on commit 9b4e9c9

Please sign in to comment.