Skip to content
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

Primitive types should not be used #1023

Open
vlagorce opened this issue Jan 5, 2023 · 1 comment
Open

Primitive types should not be used #1023

vlagorce opened this issue Jan 5, 2023 · 1 comment
Labels
bug Something isn't working help-wanted Extra attention is needed

Comments

@vlagorce
Copy link

vlagorce commented Jan 5, 2023

Issue Description

When a field of type Int!, Boolean!, Float! are declared the codegen use the corresponding primitive type.
While using generated client model if a mandatory integer field is not set the generated mutation will send 0 whereas a validation error should have bean thrown.

Steps to Reproduce

send a mutation query for a input having field with the above mentioned types without filling the values.

Expected Result

Fails with Validation error server side.

Actual Result

Primitive types have a default value. The generated query will have those values when none where provided

Your Environment and Setup

  • graphql-java-codegen version: 5.5.0
  • Build tool: Gradle

============
Primitive types should be removed. The issue might also happen to queries with parameters.

@vlagorce vlagorce added the bug Something isn't working label Jan 5, 2023
@vlagorce vlagorce changed the title Primitive types should not be used for input object Primitive types should not be used Jan 5, 2023
@kobylynskyi kobylynskyi added this to the 5.5.1 milestone Feb 19, 2023
@kobylynskyi kobylynskyi added the help-wanted Extra attention is needed label Feb 22, 2023
@kobylynskyi kobylynskyi removed this from the 5.6.0 milestone Feb 26, 2023
@kobylynskyi
Copy link
Owner

kobylynskyi commented Mar 18, 2023

This will become a breaking change if we modify how GraphQL request is serialized.
Some existing users of the plugin might already expect that the plugin will send default primitive values if they don't supply it in the input, for example:

public class PrimitivesInput {
    private double floatVal;
    private boolean booleanVal;
    private int intVal;
}

new GraphQLRequest(new PrimitivesQueryRequest.Builder()
                .input(new PrimitivesInput()).build());

Right now this would result in the following query:

query {
    primitives(input: { floatVal: 0.0, booleanVal: false, intVal: 0 })
}

And, as I understand, your expectation is the following:

query {
    primitives(input: { })
}

This can be achieved by amending your build.gradle configuration:

    customTypesMapping = [
            "Int!": "Integer",
            "Float!": "Double",
            "Boolean!": "Boolean"
    ]

This configuration will generate your model classes with Integer/Double/Boolean fields + @NotNull annotations. Which you can use then to validate your objects prior sending to a GraphQL server. And also the resulting query will be generated without default primitive values (0 for int, false for boolean, etc) if they are not supplied in the input
Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help-wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants