class Query(graphene.ObjectType): """Query objects for GraphQL API.""" node = graphene.relay.Node.Field() user = graphene.relay.Node.Field(schema_user.User) users = FilterableConnectionField(schema_user.User, filters=schema_user.UserFilter()) role = graphene.relay.Node.Field(schema_role.Role) roles = FilterableConnectionField(schema_role.Role, filters=schema_role.RoleFilter())
class Query(ObjectType): """Create Query object list""" node = relay.Node.Field() city_state = Field(CityStateNode, postalcode=String(required=True), resolver=resolve_city_states) address = Field(AddressNode, postalcode=Argument(String, required=True), address1=Argument(String, required=True), address2=Argument(String), city=Argument(String), state=Argument(String), resolver=resolve_address) # address = relay.Node.Field(AddressNode) # citystate = relay.Node.Field(CityStateNode) sport = relay.Node.Field(SportNode) team = relay.Node.Field(TeamNode) referee = relay.Node.Field(RefereeNode) coach = relay.Node.Field(CoachNode) player = relay.Node.Field(PlayerNode) all_team = FilterableConnectionField(TeamConnection) all_sport = FilterConnectionField(SportConnection) all_referee = FilterConnectionField(RefereeConnection) all_coach = FilterConnectionField(CoachConnection) all_player = FilterConnectionField(PlayerConnection)
class Query(graphene.ObjectType): userList = FilterableConnectionField(user_schema.UserConnection, filters=user_schema.UserFilter()) groupList = FilterableConnectionField(group_schema.GroupConnection, filters=group_schema.GroupFilter()) filedriveList = FilterableConnectionField( filedrive_schema.FiledriveConnection, filters=filedrive_schema.FiledriveFilter()) revisionList = FilterableConnectionField( revision_schema.RevisionConnection, filters=revision_schema.RevisionFilter()) historyList = FilterableConnectionField( revision_schema.RevisionConnection, filters=revision_schema.RevisionFilter()) podcastList = FilterableConnectionField( podcast_schema.PodcastConnection, filters=podcast_schema.PodcastFilter()) episodeList = FilterableConnectionField( episode_schema.EpisodeConnection, filters=episode_schema.EpisodeFilter()) permissionList = FilterableConnectionField( permission_schema.PermissionConnection, filters=permission_schema.PermissionFilter()) group = graphene.Field(group_schema.GroupNode, id=graphene.Int()) def resolve_group(self, info, **kwargs): return group_schema.GroupNode.get_query(info).get(kwargs.get('id')) permission = graphene.Field(permission_schema.PermissionNode, id=graphene.Int()) def resolve_permission(self, info, **kwargs): return permission_schema.PermissionNode.get_query(info).get( kwargs.get('id')) user = graphene.Field(user_schema.UserNode, id=graphene.Int()) def resolve_user(self, info, **kwargs): return user_schema.UserNode.get_query(info).get(kwargs.get('id')) filedrive = graphene.Field(filedrive_schema.FiledriveNode, id=graphene.Int()) def resolve_filedrive(self, info, **kwargs): return filedrive_schema.FiledriveNode.get_query(info).get( kwargs.get('id')) podcast = graphene.Field(podcast_schema.PodcastNode, id=graphene.Int()) def resolve_podcast(self, info, **kwargs): return podcast_schema.PodcastNode.get_query(info).get(kwargs.get('id')) episode = graphene.Field(episode_schema.EpisodeNode, id=graphene.Int()) def resolve_episode(self, info, **kwargs): return episode_schema.EpisodeNode.get_query(info).get(kwargs.get('id'))
class Query(graphene.ObjectType): node = graphene.relay.Node.Field() question_set = graphene.relay.Node.Field(QuestionSetNode) promotion_action = graphene.relay.Node.Field(PromotionActionNode) question_answer = graphene.relay.Node.Field(QuestionAnswerNode) question = graphene.relay.Node.Field(QuestionNode) question_set_tag = graphene.relay.Node.Field(QuestionSetTagNode) question_set_report = graphene.relay.Node.Field(QuestionSetReportNode) all_question_sets = FilterableConnectionField(QuestionSetConnection, filters=QuestionSetFilter()) all_users = FilterableConnectionField(UserProfileConnection, filters=UserProfileFilter()) me = me_field
def init_custom_connection_field( custom_connection_field: FilterableConnectionField, declarative_base: DeclarativeMeta, custom_filters_path, exclude_models=None, base_filter_class=FilterSet, ): if exclude_models is None: exclude_models = [] models = [ m_cls for m_cls in declarative_base._decl_class_registry.values() if isinstance(m_cls, type) and issubclass(m_cls, declarative_base) if m_cls.__name__ not in exclude_models ] # all models except exclude_models generated_filters = { sqla_model: filter_factory(base_filter_class, sqla_model, custom_filters_path)() for sqla_model in models } filters = {**custom_connection_field.filters, **generated_filters} custom_connection_field.filters = filters custom_connection_field.factory = FilterableFieldFactory(filters)
class Query(graphene.ObjectType): #This allows to query all services by query=query {serviceList{ edges{ node{ id passphrase service }}} node = graphene.relay.Node.Field() find_service = graphene.Field(lambda: graphene.List(schema_services.Services), service=graphene.String()) #Query is in this form: query { findService(service: "FaceBook") { id passphrase service } } def resolve_find_service(self, info, service): service_name = db_session.query(ModelService).filter_by(service=service) return service_name #This query allows you to resolve functions with any attributes in one statement using a filterable library #Simpiflies the amount of resolvers #This query is in the form query=query{serviceList( input: { service: "Instagram", }) { service { id service passphrase } } } serviceList = FilterableConnectionField(schema_services.Services, filters=schema_services.ServiceFilter())
class Query(ObjectType): node = relay.Node.Field() '''Department's queries''' departments = List(Department, q=String()) department = Field(Department, dept_no=String(required=True)) def resolve_departments(self, info, **args): q = args.get("q") return Department.filter_by_q(info=info, q=q or '') def resolve_department(self, info, **args): dept_no = args.get("dept_no") return Department.get_by_dept_no(info=info, dept_no=dept_no) '''Employee's queries''' employees = FilterableConnectionField(EmployeeConnection, filters=EmployeeFilter()) employee = Field(Employee, emp_no=String(required=True)) def resolve_employee(self, info, **args): emp_no = args.get("emp_no") return Employee.get_by_emp_no(info=info, emp_no=emp_no)
def test_connection_field_without_filters(): field = FilterableConnectionField(UserConnection) assert 'filters' not in field.args
class Query(graphene.ObjectType): field = FilterableConnectionField(UserConnection, filters=UserFilter())
class Query(graphene.ObjectType): node = graphene.relay.Node.Field() user = FilterableConnectionField(connection=User, filters=UserFilter(), sort=User.sort_argument())
def test_connection_field_with_filters(): field = FilterableConnectionField(UserConnection, filters=UserFilter()) assert 'filters' in field.args
class Query(graphene.ObjectType): node = graphene.relay.Node.Field() # MovieSerie = SQLAlchemyConnectionField(MovieSerie, name=graphene.String()) MovieSerie = FilterableConnectionField(connection=MovieSerie, filters=MovieSerieFilter(), sort=MovieSerie.sort_argument())