Skip to content

Commit

Permalink
🐛 fix: context and fk
Browse files Browse the repository at this point in the history
  • Loading branch information
MDKVMT committed May 30, 2024
1 parent 0389308 commit b5f4031
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/tutorial/auth/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def dl_filter(data, context):
return data


def query_filter(model, info):
def query_filter(model, context):
if model.__name__ == 'Resource':
return model.category.in_(info.context['user']['categories'])
return model.category.in_(context['user']['categories'])
return True


Expand Down
27 changes: 12 additions & 15 deletions graphemy/schemas/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,16 @@ class Schema:
attr.target if isinstance(attr.target, list) else [attr.target]
)
target = [returned_class.__tablename__ + '.' + t for t in target]
filtered_pairs = [
(s, t)
for s, t in zip(source, target)
if not (
isinstance(s, int)
or s.startswith('_')
or isinstance(t, int)
or t.startswith('_')
)
]
source, target = (
zip(*filtered_pairs) if filtered_pairs else ([], [])
)

if len(source) > 0 and len(target) > 0:
if (
len(source) > 0
and len(target) > 0
and not any(
isinstance(item, int)
or (isinstance(item, str) and item.startswith('_'))
for item in source + target
)
):
cls.__table__.append_constraint(
ForeignKeyConstraint(source, target)
)
Expand Down Expand Up @@ -212,7 +207,9 @@ async def query(
) -> list[cls.__strawberry_schema__]:
if not await Setup.has_permission(cls, info.context, 'query'):
return []
data = await get_all(cls, filters, Setup.query_filter(cls, info.context))
data = await get_all(
cls, filters, Setup.query_filter(cls, info.context)
)
return data

return (
Expand Down

0 comments on commit b5f4031

Please sign in to comment.