Skip to content

Changed enum capitalization when using java reserved words (Version: 2.4.0) #249

@Nithanim

Description

@Nithanim

Issue Description

Using reserved java words as enum names results in capitalization which is then used in the query. This results in a rejected request (by AWS Appsync) because the enum is not defined in the schema.

Steps to Reproduce

Let's assume the following graphql schema:

type Mutation {
    updateTest(message: TestEnum): String
}

enum TestEnum {
    long,
    short,
    high,
    low
}

and generate the model and client from it. We use it like this:

public static void main(String[] args) {
    UpdateTestMutationRequest mutReq = new UpdateTestMutationRequest();
    mutReq.setMessage(TestEnumTO.Long);
    GraphQLRequest req = new GraphQLRequest(mutReq);
    String json = GraphQLRequestSerializer.toHttpJsonBody(req);
    System.out.println(json);
}

The printed line is the query later sent to the server.

Expected Result

{"query":"mutation { updateTest(message: long) }"}

Actual Result

{"query":"mutation { updateTest(message: Long) }"}

Since the query is generated by the serializer using #toString() the capitalized name is used.

Your Environment and Setup

  • graphql-java-codegen: 2.4.0

  • Build tool: Maven

  • Java tool: openjdk version "1.8.0_252"; OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)

  • Mapping Config:

<configuration>
    <graphqlSchemas>
        <rootDir>${project.basedir}/schema</rootDir>
    </graphqlSchemas>
    <outputDir>${project.build.directory}/generated-sources/graphql</outputDir>
    <packageName>test.model</packageName>
    <modelNameSuffix>TO</modelNameSuffix>
    <generateClient>true</generateClient>
</configuration>

Additional context

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions