Skip to content

GraphQL Pagination  #16224

Closed
Closed
Feature
@jepify

Description

@jepify

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

Metadata

Metadata

Assignees

Labels

breaking changeThis change modifies or removes some previously documented functionalitycomplexity: highExpected to require a large amont of time and effort to implement relative to other tasksnetboxstatus: backlogAwaiting selection for worktopic: GraphQLtype: featureIntroduction of new functionality to the application

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions