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

Invalid generated Java source code for GraphQL interfaces with disabled generateParameterizedFieldsResolvers #976

Closed
Syquel opened this issue May 26, 2022 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Syquel
Copy link

Syquel commented May 26, 2022

Issue Description

The Gradle plugin graphql-java-codegen produces invalid Java source code for GraphQL types which implement an interface if the option generateParameterizedFieldsResolvers is disabled.

This bug might have been introduced by #913 .

Steps to Reproduce

GraphQL:

interface A {
    foo(arg: String): String
}

type B implements A {
    foo(arg: String): String
}

Expected Result

The Java interface A and class B should have a method String getFoo() without parameters.

A.java

public interface A {
    String getFoo();
}

B.java

public class B implements java.io.Serializable, A {

    private static final long serialVersionUID = 1L;

    private String foo;

    public B() {
    }

    public B(String foo) {
        this.foo = foo;
    }

    public String getFoo() {
        return foo;
    }
    public void setFoo(String foo) {
        this.foo = foo;
    }

    [...]
}

Actual Result

The Java interface A has a method String getFoo(String arg) with a parameter while the Java class B has a method public String getFoo() * without* parameters.
This prevents class B to be compiled, because the contract of interface A is not fulfilled.

A.java

public interface A {
    String getFoo(String arg);
}

B.java

public class B implements java.io.Serializable, A {

    private static final long serialVersionUID = 1L;

    private String foo;

    public B() {
    }

    public B(String foo) {
        this.foo = foo;
    }

    public String getFoo() {
        return foo;
    }
    public void setFoo(String foo) {
        this.foo = foo;
    }

    [...]
}

Your Environment and Setup

  • graphql-java-codegen version: 5.4.0
  • Build tool: Gradle
  • Mapping Config:
generateApis = false
generateClient = true
generateParameterizedFieldsResolvers = false
@kobylynskyi
Copy link
Owner

@Syquel good catch. I've created PR, please take a look: #977

@kobylynskyi kobylynskyi self-assigned this May 28, 2022
@kobylynskyi kobylynskyi added this to the 5.4.1 milestone May 28, 2022
kobylynskyi added a commit that referenced this issue May 29, 2022
 (#977)

* Fix generated interfaces with disabled ParameterizedFieldsResolvers #976

* Fix LineLengthCheck checkstyle rule in FieldDefinitionToParameterMapper

* Add null-safe boolean check
@kobylynskyi
Copy link
Owner

Will be released as part of version 5.4.1 #980

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

No branches or pull requests

2 participants