class ScheduleManagement(graphene.ObjectType): pipeline_sequences = OffsetSQLAlchemyConnectionField( PipelineSequencesConnection, sort=graphene.Argument(graphene.List(PipelineSequenceSortEnum), default_value=utils.EnumValue( 'source_name_asc', None))) @staticmethod def resolve_pipeline_sequences(_, info, sort=None, **kwargs): if sort in ('source_name_asc', 'source_name_desc'): query = PipelineSequencesConnection.get_query(info, **kwargs).join( PipelineSequenceModel.source) if sort.endswith('_asc'): query = query.order_by( SourceModel.name.asc(), PipelineSequenceModel.id.asc(), ) else: query = query.order_by( SourceModel.name.desc(), PipelineSequenceModel.id.desc(), ) else: query = PipelineSequencesConnection.get_query(info, sort=sort, **kwargs) return query
class Query(ObjectType): node = Node.Field() all_persons = SQLAlchemyConnectionField( PersonConnection, sort=Argument(SortEnumPerson, default_value=utils.EnumValue('id_asc', PersonModel.id.asc()))) all_next_person = SQLAlchemyConnectionField(PersonsConnection, sort=None) all_email = SQLAlchemyConnectionField(EmailsConnection)
class Query(graphene.ObjectType): node = relay.Node.Field() # Supports sorting only over one field all_employees = SQLAlchemyConnectionField(Employee, sort=graphene.Argument(SortEnumEmployee, default_value=utils.EnumValue('id_asc', EmployeeModel.id.asc()))) # Add sort over multiple fields, sorting by default over the primary key all_roles = SQLAlchemyConnectionField(Role) # Disable sorting over this field all_departments = SQLAlchemyConnectionField(Department, sort=None)
class Query(graphene.ObjectType): node = relay.Node.Field() # Allow only single column sorting all_employees = SQLAlchemyConnectionField( EmployeeConnection, sort=graphene.Argument( SortEnumEmployee, default_value=utils.EnumValue('id_asc', EmployeeModel.id.asc()))) # Allows sorting over multiple columns, by default over the primary key all_roles = SQLAlchemyConnectionField(RoleConnection) # Disable sorting over this field all_departments = SQLAlchemyConnectionField(DepartmentConnection, sort=None)
class Query(graphene.ObjectType): node = relay.Node.Field() # Allow only single column sorting all_users = SQLAlchemyConnectionField( UserConnections, sort=graphene.Argument(SortEnumUser, default_value=utils.EnumValue( 'id_asc', UserModel.id.asc()))) # Allows sorting over multiple columns, by default over the primary key all_roles = SQLAlchemyConnectionField(RoleConnection) # Disable sorting over this field all_blogs = SQLAlchemyConnectionField(BlogConnection, sort=None)
class Query(graphene.ObjectType): node = relay.Node.Field() employee = graphene.Field(Employee, name=graphene.String()) def resolve_employee(self, info, **args): query = Employee.get_query(info) return query.filter_by(name=args['name']).first() # Allow only single column sorting all_employees = SQLAlchemyConnectionField( EmployeeConnection__, sort=graphene.Argument(SortEnumEmployee, default_value=utils.EnumValue( 'id_asc', models.Employee.id.asc()))) # Allows sorting over multiple columns, by default over the primary key all_roles = SQLAlchemyConnectionField(RoleConnection__) # Disable sorting over this field all_departments = SQLAlchemyConnectionField(DepartmentConnection__, sort=None)
class UserManagement(graphene.ObjectType): users = OffsetSQLAlchemyConnectionField( UsersConnection, list_filter=graphene.Argument(UserFilter), sort=graphene.Argument(graphene.List(UserSortEnum), default_value=utils.EnumValue( 'user_number_asc', UserModel.user_number.asc()))) cognito_display_statuses = graphene.List(graphene.String) @staticmethod def resolve_users(_, info, sort=None, list_filter=None, **kwargs): query = UsersConnection.get_query(info, sort=sort, **kwargs) if list_filter: if list_filter.user_number: query = query.filter( UserModel.user_number.ilike( f'%{list_filter.user_number}%')) if list_filter.display_name: # TODO introduce real users.display_name column to the db query = query.filter( UserModel.first_name.ilike( f'%{list_filter.display_name}%')) if list_filter.cognito_display_status: if list_filter.cognito_display_status == 'UNKNOWN': query = query.filter( or_( UserModel.cognito_display_status == None, UserModel.cognito_display_status == 'UNKNOWN', )) else: query = query.filter(UserModel.cognito_display_status == list_filter.cognito_display_status) return query @staticmethod def resolve_cognito_display_statuses(_, info): # TODO support as enum in code ? query = db.session.query( UserModel.cognito_display_status).distinct().order_by( UserModel.cognito_display_status.asc()) return [row[0] if row[0] else 'UNKNOWN' for row in query]
class User(RegisteredUserObjectType): class Meta: model = UserModel interfaces = (relay.Node,) only_fields = ( 'user_number', 'exists_in_cognito', 'cognito_enabled', 'cognito_status', 'cognito_display_status', 'cognito_phone_verified', 'cognito_email_verified', 'username', 'username_set_manually', 'first_name', 'last_name', 'email', 'phone', 'registration_finished', 'is_creator', 'avatar', 'bio', 'theme_groups', 'followed_creators', 'follower_count', ) selected_themes = OffsetSQLAlchemyConnectionField( ThemesConnection, sort=graphene.Argument( SelectedThemesSortEnum, default_value=SORT_SELECTED_THEMES_SORT_ORDER, ), ) selected_theme_groups = OffsetSQLAlchemyConnectionField(ThemeGroupsConnection) allowed_cognito_actions = graphene.List(graphene.String) user_address = graphene.Field(UserAddress) user_subscription = graphene.Field(UserSubscription) user_cards = OffsetSQLAlchemyConnectionField( UserCardsConnection, sort=graphene.Argument( # graphene.List( UserCardSortEnum, # ), default_value=utils.EnumValue( 'display_order_asc', UserCardModel.display_order.asc() ) ) ) proposed_order = graphene.Field(Order) upcoming_order = graphene.Field(Order) #current_orders = graphene.List(Order) current_orders = OffsetSQLAlchemyConnectionField(OrdersConnection) all_orders = graphene.List(Order) order_history = OffsetSQLAlchemyConnectionField(OrdersConnection) credit_card = graphene.Field(CreditCard) @staticmethod def get_model_owner(model): return model @staticmethod def is_node_shared(model, owner, identity): return owner.is_creator or identity.can(registered_user_permission) @staticmethod def resolve_theme_groups(model, info, sort=None, **kwargs): return get_creator_theme_groups_data_loader().load(model.id) @staticmethod def resolve_selected_themes(model, info, sort=None, **kwargs): return get_user_selected_themes_data_loader(sort).load(model.id) @staticmethod def resolve_selected_theme_groups(model, info, sort=None, **kwargs): return get_user_selected_theme_groups_data_loader().load(model.id) @staticmethod def optimize_resolve_followed_creators(query_parent_path): query_child_path = '.'.join([query_parent_path, 'followed_creators']) return OptimizeResolveTuple( query_options=joinedload(query_child_path), query_child_path=query_child_path, child_node_class=User ) @staticmethod def resolve_allowed_cognito_actions(model, info): return [DISABLE_COGNITO_ACTION if model.cognito_enabled else ENABLE_COGNITO_ACTION] @staticmethod @registered_user_permission.require(http_exception=401, pass_identity=True) def resolve_credit_card(model, info, identity): if not _can_return_sensitive_info(model, identity): return None card_dct = get_credit_card(model.id) if card_dct is None: return return CreditCard(**card_dct) @staticmethod @registered_user_permission.require(http_exception=401, pass_identity=True) def resolve_user_address(model, info, identity): if not _can_return_sensitive_info(model, identity): return None return model.primary_user_address @staticmethod def optimize_resolve_user_address(query_parent_path): query_child_path = '.'.join([query_parent_path, 'primary_user_address']) return OptimizeResolveTuple( query_options=joinedload(query_child_path), query_child_path=query_child_path, child_node_class=UserAddress ) @staticmethod def resolve_user_subscription(model, info): return model.primary_user_subscription @staticmethod def optimize_resolve_user_subscription(query_parent_path): query_child_path = '.'.join([query_parent_path, 'primary_user_subscription']) return OptimizeResolveTuple( query_options=joinedload(query_child_path), query_child_path=query_child_path, child_node_class=UserSubscription ) @staticmethod def resolve_user_cards(model, info, sort=None, **kwargs): return UserCardsConnection.get_query(info, sort=sort, **kwargs).filter( UserCardModel.user_id == model.id ) @staticmethod def resolve_proposed_order(model, info): return db.session.query(OrderModel).filter( OrderModel.user_id == model.id, OrderModel.state.in_(USER_PROPOSED_ORDER_STATES), ).first() @staticmethod def resolve_upcoming_order(model, info): return db.session.query(OrderModel).filter( OrderModel.user_id == model.id, OrderModel.state.in_(USER_UPCOMING_ORDER_STATES), ).first() #@staticmethod #def resolve_current_orders(model, info): # return db.session.query(OrderModel).filter( # OrderModel.user_id == model.id, # OrderModel.state.in_(USER_PROPOSED_ORDER_STATES + USER_UPCOMING_ORDER_STATES), # ).order_by(OrderModel.state_changed_at.desc()) @staticmethod def resolve_all_orders(model, info): return db.session.query(OrderModel).filter( OrderModel.user_id == model.id, ).order_by(OrderModel.state_changed_at.desc()) @staticmethod def resolve_current_orders(model, info, sort=None, **kwargs): return OrdersConnection.get_query(info, sort=None, **kwargs).filter( OrderModel.user_id == model.id, OrderModel.state.in_(USER_PROPOSED_ORDER_STATES + USER_UPCOMING_ORDER_STATES), ).order_by(OrderModel.state_changed_at.desc()) @staticmethod def resolve_order_history(model, info, sort=None, **kwargs): return OrdersConnection.get_query(info, sort=None, **kwargs).filter( OrderModel.user_id == model.id, OrderModel.state.in_(USER_ORDER_HISTORY_STATES), ).order_by(OrderModel.state_changed_at.desc())
class Query(graphene.ObjectType): node = graphene.Node.Field() current_time_loc = graphene.DateTime() current_time_utc = graphene.DateTime() domain_cards = OffsetSQLAlchemyConnectionField( DomainCardsConnection, sort=graphene.Argument( # graphene.List( DomainCardSortEnum, # ), default_value=utils.EnumValue( 'display_order_asc', DomainCardModel.display_order.asc() ) ) ) themes = OffsetSQLAlchemyConnectionField(ThemesConnection) theme_groups = OffsetSQLAlchemyConnectionField(ThemeGroupsConnection) user = graphene.Field(User) creator = graphene.Field(User, username=graphene.Argument(graphene.String, required=True)) user_management = graphene.Field(UserManagement) order_management = graphene.Field(OrderManagement) schedule_management = graphene.Field(ScheduleManagement) @staticmethod @system_user_permission.require(http_exception=401) def resolve_current_time_loc(_, info): # convenience method to check what time it is on the server (local timezone) return datetime.now() @staticmethod @system_user_permission.require(http_exception=401) def resolve_current_time_utc(_, info): # convenience method to check what time it is on the server (utc timezone) return datetime.utcnow() @staticmethod def resolve_domain_cards(_, info, sort=None, **kwargs): return DomainCardsConnection.get_query( info, sort=sort, **kwargs ).filter( DomainCardModel.category_id == current_app.config['M3_DOMAIN_CATEGORY_ID'] ) @staticmethod def resolve_themes(_, info, sort=None, **kwargs): return ThemesConnection.get_query( info, sort=None, **kwargs ).outerjoin( ThemeModel.theme_group ).filter( ThemeGroupModel.is_active != False ).order_by( ThemeGroupModel.is_promoted.desc(), ThemeGroupModel.sort_order.asc(), ThemeGroupModel.title.asc(), ThemeModel.sort_order.asc(), ThemeModel.title.asc(), ) @staticmethod def resolve_theme_groups(_, info, sort=None, **kwargs): return ThemeGroupsConnection.get_query( info, sort=None, **kwargs ).join( ThemeGroupModel.themes ).filter( ThemeGroupModel.is_active != False ).order_by( ThemeGroupModel.is_promoted.desc(), ThemeGroupModel.sort_order.asc(), ThemeGroupModel.title.asc(), ) @staticmethod @registered_user_permission.require(http_exception=401, pass_identity=True) def resolve_user(_, info, identity): return get_user_by_sub(identity.id.subject) @staticmethod def resolve_creator(_, info, username=None): user = get_user_by_username(username) if not user.is_creator: registered_user_permission.test() return user @staticmethod @admin_user_permission.require(http_exception=401, pass_identity=False) def resolve_user_management(_, info): return UserManagement() @staticmethod @admin_user_permission.require(http_exception=401, pass_identity=False) def resolve_order_management(_, info): return OrderManagement() @staticmethod @admin_user_permission.require(http_exception=401, pass_identity=False) def resolve_schedule_management(_, info): return ScheduleManagement()