graphql-java-generator / graphql-maven-plugin-project

graphql-maven-plugin is a Maven Plugin for GraphQL, based on graphql-java. It accelerates the development for both the client and the server, by generating the Java code. It allows a quicker development when in contract-first approach, by avoiding to code the boilerplate code.
https://graphql-maven-plugin-project.graphql-java-generator.com
MIT License
118 stars 47 forks source link

Capitalization issue in QueryController with generated code. #217

Open gottschd opened 1 month ago

gottschd commented 1 month ago

Hello,

I want to support an external available graphql schema with this graphql-java-generator.

Given the (simplified) schema example below with a Query definition that begins with an uppercase letter:

type MyDataObject {
  email: String
  uuid: ID!
  version: Int!
}

input MyDataObjectWhereUniqueInput {
  email: String
}

type Query {
  MyDataObjectFindUnique(where: MyDataObjectWhereUniqueInput!): MyDataObject!
}

GraphQL Java Generator maven plugin generates a DataFetchersDelegateQuery interface with a lowercase method name

public com.acme.MyDataObject myDataObjectFindUnique(
            DataFetchingEnvironment dataFetchingEnvironment,
            com.acme.MyDataObjectWhereUniqueInput where);

However, the generated QueryController expects an uppercase variant of the interface's method in the DataFetchersDelegateQuery.

    public Object MyDataObjectFindUnique(DataFetchingEnvironment dataFetchingEnvironment, 
            @Argument("where") com.acme.MyDataObjectWhereUniqueInput where) {
                // Compile error - cannot find symbol: the method in the interface begins with a lower case .
        return  this.dataFetchersDelegateQuery.MyDataObjectFindUnique(dataFetchingEnvironment , where); 
    }

I'm using spring boot 3.3.1 and the version of the graphql-java-server-runtime is 2.7. The outcome is a compile error when generating the server code.

Am i missing something?

Kind regards, Danny

etienne-sf commented 1 month ago

Hello,

You missed nothing.

GraphQL good practice is that field names start with lower case letters. It respected so much, that you're the first to encounter this issue.

It's actually a bug of the plugin.

I'll correct it in the next version.

Etienne

gottschd commented 1 month ago

Hello Etienne,

thanks for both, the link and the bugfix.

Much appreciated!

Danny