Skip to content
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

Closes #16224 GraphQL Pagination #18903

Merged
merged 10 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/integrations/graphql-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ Certain queries can return multiple types of objects, for example cable terminat
```
The field "class_type" is an easy way to distinguish what type of object it is when viewing the returned data, or when filtering. It contains the class name, for example "CircuitTermination" or "ConsoleServerPort".

## Pagination

Queries can be paginated by specifying pagination in the query and supplying an offset and optionaly a limit in the query. If no limit is given, a default of 100 is used. Queries are not paginated unless requested in the query. An example paginated query is shown below:

```
query {
device_list(pagination: { offset: 0, limit: 20 }) {
id
}
}
```

## Authentication

NetBox's GraphQL API uses the same API authentication tokens as its REST API. Authentication tokens are included with requests by attaching an `Authorization` HTTP header in the following form:
Expand Down
33 changes: 22 additions & 11 deletions netbox/circuits/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
@strawberry_django.type(
models.Provider,
fields='__all__',
filters=ProviderFilter
filters=ProviderFilter,
pagination=True
)
class ProviderType(NetBoxObjectType, ContactsMixin):

Expand All @@ -45,7 +46,8 @@ class ProviderType(NetBoxObjectType, ContactsMixin):
@strawberry_django.type(
models.ProviderAccount,
fields='__all__',
filters=ProviderAccountFilter
filters=ProviderAccountFilter,
pagination=True
)
class ProviderAccountType(NetBoxObjectType):
provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')]
Expand All @@ -56,7 +58,8 @@ class ProviderAccountType(NetBoxObjectType):
@strawberry_django.type(
models.ProviderNetwork,
fields='__all__',
filters=ProviderNetworkFilter
filters=ProviderNetworkFilter,
pagination=True
)
class ProviderNetworkType(NetBoxObjectType):
provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')]
Expand All @@ -67,7 +70,8 @@ class ProviderNetworkType(NetBoxObjectType):
@strawberry_django.type(
models.CircuitTermination,
exclude=['termination_type', 'termination_id', '_location', '_region', '_site', '_site_group', '_provider_network'],
filters=CircuitTerminationFilter
filters=CircuitTerminationFilter,
pagination=True
)
class CircuitTerminationType(CustomFieldsMixin, TagsMixin, CabledObjectMixin, ObjectType):
circuit: Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]
Expand All @@ -86,7 +90,8 @@ def termination(self) -> Annotated[Union[
@strawberry_django.type(
models.CircuitType,
fields='__all__',
filters=CircuitTypeFilter
filters=CircuitTypeFilter,
pagination=True
)
class CircuitTypeType(OrganizationalObjectType):
color: str
Expand All @@ -97,7 +102,8 @@ class CircuitTypeType(OrganizationalObjectType):
@strawberry_django.type(
models.Circuit,
fields='__all__',
filters=CircuitFilter
filters=CircuitFilter,
pagination=True
)
class CircuitType(NetBoxObjectType, ContactsMixin):
provider: ProviderType
Expand All @@ -113,7 +119,8 @@ class CircuitType(NetBoxObjectType, ContactsMixin):
@strawberry_django.type(
models.CircuitGroup,
fields='__all__',
filters=CircuitGroupFilter
filters=CircuitGroupFilter,
pagination=True
)
class CircuitGroupType(OrganizationalObjectType):
tenant: TenantType | None
Expand All @@ -122,7 +129,8 @@ class CircuitGroupType(OrganizationalObjectType):
@strawberry_django.type(
models.CircuitGroupAssignment,
exclude=['member_type', 'member_id'],
filters=CircuitGroupAssignmentFilter
filters=CircuitGroupAssignmentFilter,
pagination=True
)
class CircuitGroupAssignmentType(TagsMixin, BaseObjectType):
group: Annotated["CircuitGroupType", strawberry.lazy('circuits.graphql.types')]
Expand All @@ -138,7 +146,8 @@ def member(self) -> Annotated[Union[
@strawberry_django.type(
models.VirtualCircuitType,
fields='__all__',
filters=VirtualCircuitTypeFilter
filters=VirtualCircuitTypeFilter,
pagination=True
)
class VirtualCircuitTypeType(OrganizationalObjectType):
color: str
Expand All @@ -149,7 +158,8 @@ class VirtualCircuitTypeType(OrganizationalObjectType):
@strawberry_django.type(
models.VirtualCircuitTermination,
fields='__all__',
filters=VirtualCircuitTerminationFilter
filters=VirtualCircuitTerminationFilter,
pagination=True
)
class VirtualCircuitTerminationType(CustomFieldsMixin, TagsMixin, ObjectType):
virtual_circuit: Annotated[
Expand All @@ -165,7 +175,8 @@ class VirtualCircuitTerminationType(CustomFieldsMixin, TagsMixin, ObjectType):
@strawberry_django.type(
models.VirtualCircuit,
fields='__all__',
filters=VirtualCircuitFilter
filters=VirtualCircuitFilter,
pagination=True
)
class VirtualCircuitType(NetBoxObjectType):
provider_network: ProviderNetworkType = strawberry_django.field(select_related=["provider_network"])
Expand Down
15 changes: 11 additions & 4 deletions netbox/core/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
@strawberry_django.type(
models.DataFile,
exclude=['data',],
filters=DataFileFilter
filters=DataFileFilter,
pagination=True
)
class DataFileType(BaseObjectType):
source: Annotated["DataSourceType", strawberry.lazy('core.graphql.types')]
Expand All @@ -28,7 +29,8 @@ class DataFileType(BaseObjectType):
@strawberry_django.type(
models.DataSource,
fields='__all__',
filters=DataSourceFilter
filters=DataSourceFilter,
pagination=True
)
class DataSourceType(NetBoxObjectType):

Expand All @@ -38,12 +40,17 @@ class DataSourceType(NetBoxObjectType):
@strawberry_django.type(
models.ObjectChange,
fields='__all__',
filters=ObjectChangeFilter
filters=ObjectChangeFilter,
pagination=True
)
class ObjectChangeType(BaseObjectType):
pass


@strawberry_django.type(DjangoContentType, fields='__all__')
@strawberry_django.type(
DjangoContentType,
fields='__all__',
pagination=True
)
class ContentType:
pass
Loading