Skip to content

Mapping fields for Input Types with different names between schema and Java Object #1146

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
gaganis opened this issue Mar 6, 2025 · 2 comments
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@gaganis
Copy link

gaganis commented Mar 6, 2025

Is there a way to map fields for input types? I have been unable to find how to do this neither in the documentation or by searching the web.

For example to be able to map full_name in the schema to fullName in the java object:

input CreateUserInput {
    full_name: String
}

to

public class CreateUserInput {
    private String fullName;  // Must match GraphQL schema

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
}

We are migrating our app from https://github.com/graphql-java-kickstart and we used to do that using jackson@JsonProperty.

Any pointers would be greatly appreciated

Thanks
Giorgos

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 6, 2025
@rstoyanchev
Copy link
Contributor

We used to decode through Jackson, but it involves serializing the argument map to JSON first, which can cause issues with scalar value formatting, see #122. We now use our own mechanism, the GraphQlArgumentBinder. Currently, it does not support this kind of mapping. We could consider some sort of naming strategy, or a Function to map keys from the argument map.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Mar 6, 2025
@gaganis
Copy link
Author

gaganis commented Mar 7, 2025

Thanks for you reply

In my POV something like this would make a lot of sense to me. Not sure if this would fit any of your suggestions @rstoyanchev

public class CreateUserInput {

    @ShemaMapping(field="full_name")
    private String fullName;  // Must match GraphQL schema
    ...
}

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants