From b5f403133072437e3a1c1bd708edd95cdb2f47ce Mon Sep 17 00:00:00 2001 From: Matheus Doreto Date: Thu, 30 May 2024 00:18:35 -0300 Subject: [PATCH] :bug: fix: context and fk --- examples/tutorial/auth/main.py | 4 ++-- graphemy/schemas/generators.py | 27 ++++++++++++--------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/examples/tutorial/auth/main.py b/examples/tutorial/auth/main.py index 3f9bdbc..44bb5ed 100644 --- a/examples/tutorial/auth/main.py +++ b/examples/tutorial/auth/main.py @@ -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 diff --git a/graphemy/schemas/generators.py b/graphemy/schemas/generators.py index f8bc290..86dfacb 100644 --- a/graphemy/schemas/generators.py +++ b/graphemy/schemas/generators.py @@ -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) ) @@ -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 (