Skip to content

Commit 9b4e9c9

Browse files
author
Arthur Bayr
committed
keep order
1 parent a736a61 commit 9b4e9c9

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

strawberry/permission.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,15 @@ def __init__(
156156
self.use_directives = use_directives
157157

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

0 commit comments

Comments
 (0)