Beispiel #1
0
class Query(ObjectType):
    stream = relay.NodeField(StreamNode)
    all_streams = DjangoFilterConnectionField(StreamNode)

    task = relay.NodeField(TaskNode)
    all_tasks = DjangoFilterConnectionField(TaskNode)

    class Meta:
        abstract = True
Beispiel #2
0
class Query(ObjectType):
    category = relay.NodeField(CategoryNode)
    all_categories = DjangoFilterConnectionField(CategoryNode)

    ingredient = relay.NodeField(IngredientNode)
    all_ingredients = DjangoFilterConnectionField(IngredientNode)

    class Meta:
        abstract = True
Beispiel #3
0
class Query(ObjectType):
    category = relay.NodeField(CategoryNode)
    all_categories = DjangoFilterConnectionField(CategoryNode)

    project = relay.NodeField(ProjectsNode)
    all_projects = DjangoFilterConnectionField(ProjectsNode)

    class Meta:
        abstract = True
class Query(ObjectType):

    bucketlist = relay.NodeField(BucketlistNode)
    all_bucketlist = DjangoFilterConnectionField(BucketlistNode)

    Bucketlistitem = relay.NodeField(BucketlistItemNode)
    all_bucketlistitem = DjangoFilterConnectionField(BucketlistItemNode)

    debug = graphene.Field(DjangoDebug, name='__debug')
Beispiel #5
0
class Query(ObjectType):
    category = relay.NodeField(CategoryNode)
    all_categories = DjangoFilterConnectionField(CategoryNode)

    ingredient = relay.NodeField(IngredientNode)
    all_ingredients = DjangoFilterConnectionField(IngredientNode)

    debug = graphene.Field(DjangoDebug, name='__debug')

    class Meta:
        abstract = True
class Query(ObjectType):
    project = relay.NodeField(ProjectNode)
    all_projects = DjangoFilterConnectionField(ProjectNode)

    milestone = relay.NodeField(MilestoneNode)
    all_milestones = DjangoFilterConnectionField(MilestoneNode)

    ticket = relay.NodeField(TicketNode)
    all_tickets = DjangoFilterConnectionField(TicketNode)

    class Meta:
        abstract = True
Beispiel #7
0
class Query(ObjectType):
    customer = relay.NodeField(CustomerNode)
    category = relay.NodeField(CategoryNode)
    product = relay.NodeField(ProductNode)
    order = relay.NodeField(OrderNode)

    cart_item = relay.NodeField(CartItemNode)
    order_item = relay.NodeField(OrderItemNode)

    all_customers = DjangoFilterConnectionField(CustomerNode)
    all_categories = DjangoFilterConnectionField(CategoryNode)
    all_products = DjangoFilterConnectionField(ProductNode)
    all_orders = DjangoFilterConnectionField(OrderNode)

    class Meta:
        abstract = True
Beispiel #8
0
def test_filter_shortcut_filterset_arguments_list():
    field = DjangoFilterConnectionField(ArticleNode,
                                        fields=['pub_date', 'reporter'])
    assert_arguments(
        field,
        'pubDate',
        'reporter',
    )
Beispiel #9
0
def test_filter_filterset_information_on_meta():
    class ReporterFilterNode(DjangoNode):
        class Meta:
            model = Reporter
            filter_fields = ['first_name', 'articles']
            filter_order_by = True

    field = DjangoFilterConnectionField(ReporterFilterNode)
    assert_arguments(field, 'firstName', 'articles')
    assert_orderable(field)
Beispiel #10
0
def test_global_id_multiple_field_explicit_reverse():
    class ReporterPetsFilter(django_filters.FilterSet):
        class Meta:
            model = Reporter
            fields = ['articles']

    field = DjangoFilterConnectionField(ReporterNode,
                                        filterset_class=ReporterPetsFilter)
    filterset_class = field.filterset_class
    multiple_filter = filterset_class.base_filters['articles']
    assert isinstance(multiple_filter, GlobalIDMultipleChoiceFilter)
    assert multiple_filter.field_class == GlobalIDMultipleChoiceField
Beispiel #11
0
def test_global_id_field_explicit():
    class ArticleIdFilter(django_filters.FilterSet):
        class Meta:
            model = Article
            fields = ['id']

    field = DjangoFilterConnectionField(ArticleNode,
                                        filterset_class=ArticleIdFilter)
    filterset_class = field.filterset_class
    id_filter = filterset_class.base_filters['id']
    assert isinstance(id_filter, GlobalIDFilter)
    assert id_filter.field_class == GlobalIDFormField
Beispiel #12
0
def test_filter_shortcut_filterset_arguments_dict():
    field = DjangoFilterConnectionField(ArticleNode,
                                        fields={
                                            'headline': ['exact', 'icontains'],
                                            'reporter': ['exact'],
                                        })
    assert_arguments(
        field,
        'headline',
        'headline_Icontains',
        'reporter',
    )
Beispiel #13
0
def test_filter_explicit_filterset_arguments():
    field = DjangoFilterConnectionField(ArticleNode,
                                        filterset_class=ArticleFilter)
    assert_arguments(
        field,
        'headline',
        'headline_Icontains',
        'pubDate',
        'pubDate_Gt',
        'pubDate_Lt',
        'reporter',
    )
Beispiel #14
0
class Query(ObjectType):
    # user
    user = relay.NodeField(UserNode)
    all_users = DjangoFilterConnectionField(UserNode, s=graphene.String())
    # category
    section = relay.NodeField(SectionNode)
    all_sections = DjangoFilterConnectionField(SectionNode,
                                               filterset_class=SectionFilter,
                                               s=graphene.String())
    # category
    category = relay.NodeField(CategoryNode)
    all_categories = DjangoFilterConnectionField(
        CategoryNode, filterset_class=CategoryFilter, s=graphene.String())
    # tag
    tag = relay.NodeField(TagNode)
    all_tags = DjangoFilterConnectionField(TagNode,
                                           filterset_class=TagFilter,
                                           s=graphene.String())
    # entry
    entry = relay.NodeField(EntryNode)
    all_entries = DjangoFilterConnectionField(EntryNode,
                                              filterset_class=EntryFilter,
                                              s=graphene.String())
    # entrylink
    entrylink = relay.NodeField(EntrylinkNode)
    all_entrylinks = DjangoFilterConnectionField(EntrylinkNode,
                                                 s=graphene.String())

    class Meta:
        abstract = True
Beispiel #15
0
class Query(graphene.ObjectType):
    all_films = DjangoFilterConnectionField(Film)
    all_species = DjangoFilterConnectionField(Specie)
    all_characters = DjangoFilterConnectionField(Person)
    all_vehicles = DjangoFilterConnectionField(Vehicle)
    all_planets = DjangoFilterConnectionField(Planet)
    all_starships = DjangoFilterConnectionField(Starship)
    all_heroes = DjangoFilterConnectionField(Hero)
    film = relay.NodeField(Film)
    specie = relay.NodeField(Specie)
    character = relay.NodeField(Person)
    vehicle = relay.NodeField(Vehicle)
    planet = relay.NodeField(Planet)
    starship = relay.NodeField(Starship)
    hero = relay.NodeField(Hero)
    node = relay.NodeField()
    viewer = graphene.Field('self')

    debug = graphene.Field(DjangoDebug, name='__debug')

    def resolve_viewer(self, *args, **kwargs):
        return self
Beispiel #16
0
def test_global_id_multiple_field_implicit_reverse():
    field = DjangoFilterConnectionField(ReporterNode, fields=['articles'])
    filterset_class = field.filterset_class
    multiple_filter = filterset_class.base_filters['articles']
    assert isinstance(multiple_filter, GlobalIDMultipleChoiceFilter)
    assert multiple_filter.field_class == GlobalIDMultipleChoiceField
Beispiel #17
0
def test_global_id_field_relation():
    field = DjangoFilterConnectionField(ArticleNode, fields=['reporter'])
    filterset_class = field.filterset_class
    id_filter = filterset_class.base_filters['reporter']
    assert isinstance(id_filter, GlobalIDFilter)
    assert id_filter.field_class == GlobalIDFormField
Beispiel #18
0
 class Query(ObjectType):
     all_reporters = DjangoFilterConnectionField(ReporterFilterNode)
     all_articles = DjangoFilterConnectionField(ArticleFilterNode)
     reporter = NodeField(ReporterFilterNode)
     article = NodeField(ArticleFilterNode)
Beispiel #19
0
class ViolationQuery(ObjectType):
    violation = relay.NodeField(ViolationNode)
    all_violations = DjangoFilterConnectionField(ViolationNode)

    class Meta:
        abstract = True
Beispiel #20
0
def test_filter_explicit_filterset_not_orderable():
    field = DjangoFilterConnectionField(PetNode, filterset_class=PetFilter)
    assert_not_orderable(field)
Beispiel #21
0
def test_filter_shortcut_filterset_orderable_headline():
    field = DjangoFilterConnectionField(ArticleNode, order_by=['headline'])
    assert_orderable(field)
Beispiel #22
0
class Query(ObjectType):
    fundingRound = relay.NodeField(FundingRoundNode)
    allFundingRounds = DjangoFilterConnectionField(FundingRoundNode)

    object = relay.NodeField(ObjectNode)
    allObjects = DjangoFilterConnectionField(ObjectNode)

    relationship = relay.NodeField(RelationshipNode)
    allRelationships = DjangoFilterConnectionField(RelationshipNode)

    degree = relay.NodeField(DegreeNode)
    allDegrees = DjangoFilterConnectionField(DegreeNode)

    acquisition = relay.NodeField(AcquisitionNode)
    allAcquisitions = DjangoFilterConnectionField(AcquisitionNode)

    fund = relay.NodeField(FundNode)
    allFunds = DjangoFilterConnectionField(FundNode)

    investment = relay.NodeField(InvestmentNode)
    allInvestments = DjangoFilterConnectionField(InvestmentNode)

    ipo = relay.NodeField(IpoNode)
    allIpos = DjangoFilterConnectionField(IpoNode)

    milestone = relay.NodeField(MilestoneNode)
    allMilestones = DjangoFilterConnectionField(MilestoneNode)

    office = relay.NodeField(OfficeNode)
    allOffices = DjangoFilterConnectionField(OfficeNode)

    people = relay.NodeField(PeopleNode)
    allPeople = DjangoFilterConnectionField(PeopleNode)

    myObjects = relay.ConnectionField(ObjectNode, \
     description='Get objects by params.', \
     limit=graphene.Int(), \
     school=graphene.String(), \
     isInvestor=graphene.Boolean()
     )

    def resolve_myObjects(self, args, info):
        limit = args.get('limit')
        school = args.get('school')

        if (school is not None) and (school != ''):
            ret = []
            len = 0
            degrees = CbDegrees.objects.filter(institution=school)
            for degree in degrees:
                if len == limit:
                    break
                ret.append(degree.object)
                len += 1
            return ret
        return CbObjects.objects.all()[:limit]

    class Meta:
        abstract = True
Beispiel #23
0
    class Query(graphene.ObjectType):
        all_reporters = DjangoFilterConnectionField(ReporterType)

        def resolve_all_reporters(self, *args, **kwargs):
            return Reporter.objects.all()
Beispiel #24
0
class Catalog(graphene.relay.Node):
    """
    Dummy root-node class
    """
    all_books = DjangoFilterConnectionField(BookNode)
    all_categories = graphene.List(CategoryNode)
    bookNode = graphene.relay.NodeField(BookNode)
    root_category = graphene.Field(CategoryNode)
    search_results = graphene.Field(
        SearchResults,
        search_text=graphene.String().NonNull,
        categories=graphene.String(),
    )
    # search_suggestion = graphene.Field(
    #     SearchSuggestion,
    #     search_text=graphene.String().NonNull
    # )
    id = None

    def resolve_all_categories(self, args, info):
        return [CategoryNode(c) for c in Category.objects.all()]

    def resolve_search_suggestion(self, args, info):
        search_text = args.get('search_text')
        qs = Book.full_text_search.ranked_search(search_text).order_by(
            '-rank', 'title', 'subtitle')
        proportion = settings.CATALOG_SEARCH_SUGGEST_PROPORTION
        books = [BookNode(b) for b in qs[:proportion['books']]]
        suggestions = [
            "{title} {subtitle}".format(**b)
            for b in Book.full_text_search.autocomplete_search(search_text).
            order_by('-similarity', 'title', 'subtitle').values(
                'title', 'subtitle').distinct()[:proportion['suggestions']]
        ]

        authors = [
            b['author'] for b in Book.full_text_search.autocomplete_search(
                search_text, (
                    'author', ), settings.CATALOG_AUTHORS_SIMILARITY_THRESHOLD
            ).order_by('-similarity', 'author').values('author').distinct()
            [:proportion['authors']]
        ]
        categories_qs = Category.objects.annotate(Count('books')).filter(
            books__count__gt=0, title__trigram_similar=search_text)
        categories = [
            CategoryNode(cat)
            for cat in categories_qs[:proportion['categories']]
        ]
        log.debug("Resolved suggestions: %s, %s, %s, %s", suggestions, authors,
                  categories, books)
        return SearchSuggestion(
            suggestions=suggestions,
            books=books,
            authors=authors,
            categories=categories,
        )

    def resolve_search_results(self, args, info):
        search_text = args.get('search_text')
        qs = Book.full_text_search.ranked_search(search_text)
        totalBooksCount = qs.count()
        categories = args.get('categories', None)
        if categories is not None:
            qs = qs.filter(categories=from_global_id(categories)[1])
        books = [
            BookNode(b) for b in qs.order_by('-rank', 'title', 'subtitle')
        ]
        facets = {
            record['categories']: record['facet']
            for record in qs.order_by('categories').values(
                'categories').annotate(facet=Count('pk'))
        }
        root_category = CategoryNode(Category.objects.first(), facets=facets)
        facets_node = [
            CategoryFacet(category=CategoryNode(Category.objects.get(pk=pk)),
                          books_count=facets[pk]) for pk in facets
        ]

        return SearchResults(books=books,
                             root_category=root_category,
                             facets=facets_node,
                             totalBooksCount=totalBooksCount)

    def resolve_root_category(self, *args):
        return CategoryNode(Category.objects.first())

    @classmethod
    def get_node(cls, id, info):
        return cls()
Beispiel #25
0
def test_filter_explicit_filterset_orderable():
    field = DjangoFilterConnectionField(ArticleNode,
                                        filterset_class=ArticleFilter)
    assert_orderable(field)
Beispiel #26
0
def test_filter_shortcut_filterset_extra_meta():
    field = DjangoFilterConnectionField(ArticleNode,
                                        extra_filter_meta={'order_by': True})
    assert_orderable(field)
Beispiel #27
0
class NotesQuery(ObjectType):
    note = relay.NodeField(NotesNode)
    all_notes = DjangoFilterConnectionField(NotesNode)
Beispiel #28
0
def test_filter_shortcut_filterset_orderable_true():
    field = DjangoFilterConnectionField(ArticleNode, order_by=True)
    assert_orderable(field)