Skip to content

GraphQL Pagination #16224

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

Closed
jepify opened this issue May 21, 2024 · 4 comments
Closed

GraphQL Pagination #16224

jepify opened this issue May 21, 2024 · 4 comments
Assignees
Labels
breaking change This change modifies or removes some previously documented functionality complexity: high Expected to require a large amont of time and effort to implement relative to other tasks netbox status: backlog Awaiting selection for work topic: GraphQL type: feature Introduction of new functionality to the application
Milestone

Comments

@jepify
Copy link

jepify commented May 21, 2024

NetBox version

v4.0.2

Feature type

Data model extension

Proposed functionality

Pagination in GraphQL.
With the newly Strawberry.rocks GraphQL engine, it is possible to implement Pagination with a few simple modifications.

GraphQL Pagination
Strawberry Pagination
Strawberry Django offset-based
Strawberry Django cursor-based

Given the different ways of implementing pagination, it should be able to co-exist with non paginated queries, if needed.
This could be done by e.g. keeping the regular e.g. device_list query and a device_connection query.

Use case

With large tables with e.g. interfaces doing queries with nested objects takes a lot of time due to the translation from QuerySets via the Execution of fields part of the spec.

Other forks like Nautobot supports offset-based pagination and the Rest API supports offset-based, so it would be a nice addition to the future use of GraphQL.

Currently if we want to do pagination for GraphQL we are to utilize the ordering and pagination of the Rest API with ordering and id__gtqueries.

The query could be:

query MyQuery {
  device_list(first: 2, after:"YXJyYXljb25uZWN0aW9uOjM=") {
    edges {
      cursor
      node {
        id
        name
      }
    }
    page_info {
      has_next_page
      has_previous_page
      start_cursor
      end_cursor
    }
  }
  device_role_list(pagination: {offset: 2, limit: 2}) {
    name
    id
  }
}

And would result in:

{
  "data": {
    "device_list": {
      "edges": [
        {
          "cursor": "YXJyYXljb25uZWN0aW9uOjQ=",
          "node": {
            "id": "33577",
            "name": "01-02-1 Cable management (U22)"
          }
        },
        {
          "cursor": "YXJyYXljb25uZWN0aW9uOjU=",
          "node": {
            "id": "33576",
            "name": "01-02-1 RJ45 PP (U26)"
          }
        }
      ],
      "page_info": {
        "has_next_page": true,
        "has_previous_page": true,
        "start_cursor": "YXJyYXljb25uZWN0aW9uOjQ=",
        "end_cursor": "YXJyYXljb25uZWN0aW9uOjU="
      }
    },
    "device_role_list": [
      {
        "name": "Access Switch",
        "id": "30"
      },
      {
        "name": "Analyzer",
        "id": "826"
      }
    ]
  }
}

Database changes

None

External dependencies

None

@jepify jepify added status: needs triage This issue is awaiting triage by a maintainer type: feature Introduction of new functionality to the application labels May 21, 2024
@arthanson arthanson added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation and removed status: needs triage This issue is awaiting triage by a maintainer labels May 21, 2024
@arthanson arthanson removed their assignment May 21, 2024
@jeremystretch jeremystretch added the complexity: high Expected to require a large amont of time and effort to implement relative to other tasks label May 21, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Aug 20, 2024
@jeremystretch jeremystretch added status: backlog Awaiting selection for work and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation pending closure Requires immediate attention to avoid being closed for inactivity labels Sep 13, 2024
@jeremystretch jeremystretch added the netbox label Nov 1, 2024 — with Linear
@jeremypng
Copy link

If we can get my PR in for the GraphQL filtering redesign, I'll add this feature as well.

@tyler-8
Copy link
Contributor

tyler-8 commented Feb 11, 2025

Just want to add my support for this feature. Without pagination I end up having to use more inefficient workarounds (querying devices by regions, or arbitrary groupings of sites) which add unnecessary complexity for what is ultimately trying to have pagination-like behavior without pagination.

Throw in various bits of nested relationship data and complexity is tough to manage. Pagination would significantly improve the experience and simplicity of API workflows.

@jeremystretch jeremystretch added this to the v4.3 milestone Feb 20, 2025
@jeremystretch jeremystretch added the breaking change This change modifies or removes some previously documented functionality label Feb 20, 2025
@jeremystretch
Copy link
Member

Note: When this is implemented, we'll need to ensure we don't introduce the bug cited in #18729, which results from non-deterministic ordering of a queryset.

@arthanson arthanson self-assigned this Mar 13, 2025
jnovinger pushed a commit that referenced this issue Mar 20, 2025
* 16244 add pagination

* 16244 add pagination

* 16244 fix order_by pagination

* 16224 document pagination

* 16224 remove extraneous code

* 16224 missing core types

* 16224 review changes

* 16224 review changes

* 16224 review changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change This change modifies or removes some previously documented functionality complexity: high Expected to require a large amont of time and effort to implement relative to other tasks netbox status: backlog Awaiting selection for work topic: GraphQL type: feature Introduction of new functionality to the application
Projects
None yet
5 participants