-
Notifications
You must be signed in to change notification settings - Fork 35
IFC-1886: Paginated branch graphql query #7418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 3 commits
1102ae7
4e16ec7
c0b3b31
9a07e23
41b1849
c8fbca1
dd242d9
9f1dc4a
3a7ff90
e659340
2ad4b2d
32c72ad
a38cec2
84fac0a
f7d4828
491ad04
86dbefa
9eba0b8
9fe2763
8e4dca9
f0aa561
089b015
fb7d0a6
1157cc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,10 @@ | |
|
|
||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from graphene import ID, Field, List, NonNull, String | ||
| from graphene import ID, Field, Int, List, NonNull, String | ||
|
|
||
| from infrahub.graphql.field_extractor import extract_graphql_fields | ||
| from infrahub.graphql.types import BranchType | ||
| from infrahub.graphql.types import BranchType, InfrahubBranchType | ||
|
|
||
| if TYPE_CHECKING: | ||
| from graphql import GraphQLResolveInfo | ||
|
|
@@ -28,3 +28,36 @@ async def branch_resolver( | |
| resolver=branch_resolver, | ||
| required=True, | ||
| ) | ||
|
|
||
|
|
||
| async def infrahub_branch_resolver( | ||
| root: dict, # noqa: ARG001 | ||
| info: GraphQLResolveInfo, | ||
| **kwargs: Any, | ||
| ) -> dict[str, Any]: | ||
| page = kwargs.pop("page", 1) | ||
| limit = kwargs.pop("limit", 100) | ||
| offset = (page - 1) * limit | ||
solababs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fields = {name: str(field.type) for name, field in BranchType._meta.fields.items()} | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| branches = await BranchType.get_list( | ||
| fields=fields, graphql_context=info.context, limit=limit, offset=offset, **kwargs | ||
| ) | ||
|
|
||
| return { | ||
| "current_page": page, | ||
| "count_per_page": limit, | ||
| "branches": branches, | ||
| } | ||
solababs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| InfrahubBranchQueryList = Field( | ||
| InfrahubBranchType, | ||
| ids=List(ID), | ||
solababs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| name=String(), | ||
|
||
| page=Int(default_value=1), | ||
| limit=Int(default_value=100), | ||
solababs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description="Retrieve paginated information about active branches.", | ||
| resolver=infrahub_branch_resolver, | ||
| required=True, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.