Skip to content

QuerydslDataFetcher does not preserve path prefix when flattening nested parameters #1215

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

Open
zeng-alt opened this issue May 17, 2025 · 0 comments
Labels
in: data Issues related to working with data status: waiting-for-triage An issue we've not yet triaged

Comments

@zeng-alt
Copy link

Describe the Bug

In org.springframework.graphql.data.query.QuerydslDataFetcher, the private method addParameters(...) fails to preserve the parent path prefix when recursively processing nested input arguments. This leads to incorrect flattening of nested object fields into parameter names.

Expected Behavior

Given a GraphQL query with nested object fields, such as:

query {
  userBy(filter: { profile: { name: "test1" } }) {
    id
  }
}

The expected parameter map should include keys like:

{
  "profile.name": ["test1"]
}

But currently it produces:

{
  "name": ["test1"]
}

The profile. prefix is missing.

Actual Behavior

The path prefix is dropped during recursion because the method call:

addParameters(entry.getKey(), (Map<String, Object>) nested, parameters);

does not incorporate the existing prefix. As a result, only the current key is passed as the new prefix, and the hierarchical path is not preserved.

Affected Code

private void addParameters(
    @Nullable String prefix,
    Map<String, Object> arguments,
    MultiValueMap<String, Object> parameters) {

    for (Map.Entry<String, Object> entry : arguments.entrySet()) {
        Object value = entry.getValue();
        if (value instanceof Map<?, ?> nested) {
            addParameters(entry.getKey(), (Map<String, Object>) nested, parameters); // ❌ This line is incorrect
            continue;
        }
        List<Object> values = (value instanceof List) ? (List<Object>) value : Collections.singletonList(value);
        parameters.put(((prefix != null) ? prefix + "." : "") + entry.getKey(), values);
    }
}

Suggested Fix

Update the recursive call to include the full path:

addParameters(
    (prefix != null ? prefix + "." + entry.getKey() : entry.getKey()),
    (Map<String, Object>) nested,
    parameters
);

This ensures nested paths are flattened correctly into fully qualified keys.

Version

  • spring-graphql: 1.3.4 (or whichever version you're using)
  • Affects: likely all versions since QuerydslDataFetcher was introduced

Impact

This issue causes incorrect behavior when using nested input types (e.g., object fields like profile.name) in queries. It breaks parameter-based filtering when relying on QuerydslBindings.

zeng-alt added a commit to zeng-alt/spring-graphql that referenced this issue May 17, 2025
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 17, 2025
@bclozel bclozel added the in: data Issues related to working with data label May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues related to working with data status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants