dotCMS / dotCMS/core

GraphQL API: Pagination fieldName should support aliases for multiple search queries

Open
#33,044 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

OKR : Technical User Experience Priority : 3 Average Team : Scout
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Problem

The dotCMS GraphQL API's pagination object does not support aliases, which creates ambiguity when performing multiple search queries in a single GraphQL request. Currently, when executing multiple search operations (e.g., searching for different content types), all pagination objects have the same fieldName value, making it impossible to determine which pagination data corresponds to which search query.

Current Behavior

When performing multiple searches like:

query ContentAPI {
  test: search(query: "+parentPath:/", limit: 10) {
    inode
  }
  blog: search(query: "+contentType:Blog", limit: 10) {
    title
  }
  destination: DestinationCollection {
    title
  }
  pagination: Pagination {
    page
    pageSize
    totalRecords
    fieldName
  }
}

The response contains multiple pagination objects with identical fieldName values:

{
  "data": {
    "test": [ ],
    "blog": [ ],
    "destination": [ ],
    "pagination": [
      {
        "page": 1,
        "pageSize": 10,
        "totalRecords": 364,
        "fieldName": "search"
      },
      {
        "page": 1,
        "pageSize": 10,
        "totalRecords": 6,
        "fieldName": "search"
      },
      {
        "page": 1,
        "pageSize": 100,
        "totalRecords": 5,
        "fieldName": "DestinationCollection"
      }
    ]
  }
}

Expected Behavior

The pagination fieldName should respect GraphQL aliases and return unique identifiers that correspond to each aliased search query, allowing developers to properly associate pagination data with their respective search results.

For example, if we alias our searches as test, blog, and destination, the pagination objects should have fieldName values of "test", "blog", and "destination" respectively, instead of all having "search" or "DestinationCollection".

The GraphQL resolver for pagination should dynamically assign fieldName based on the query alias if one is used, otherwise fall back to the default field name (search, DestinationCollection, etc.).

Impact

This limitation significantly affects:

  • Complex queries that need to search multiple content types simultaneously
  • Frontend applications that rely on pagination metadata to implement proper pagination UI
  • API consumers who need to efficiently batch multiple search operations

Suggested Solution

Modify the GraphQL pagination resolver to:

  1. Detect when a search query uses an alias
  2. Use the alias name as the fieldName in the corresponding pagination object
  3. Maintain backward compatibility for queries without aliases

Additional Context

This issue affects the ContentAPI's search functionality and impacts developers building applications that require multiple simultaneous searches with proper pagination handling.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the ContentAPI GraphQL pagination resolver and the search resolver that produces pagination objects. Trace how fieldName is currently assigned for aliased and unaliased queries. Done means aliased searches report their aliases as fieldName, unaliased fields retain their existing names, and the behavior is covered by the relevant GraphQL tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, java
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.