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

Code generation using gradle plugin fails for NonNullType of List with empty list as default value (Version: graphql-java-codegen 1.7.3) #177

Closed
IntiG opened this issue Jun 16, 2020 · 3 comments · Fixed by #179
Assignees
Labels
bug Something isn't working
Milestone

Comments

@IntiG
Copy link

IntiG commented Jun 16, 2020

Issue Description

Code generation using gradle plugin from graphql schema fails with this message:
Unexpected array default value for non-list type

Here is a snippet of the schema, I actually identified the part that fails:

type Query {
  "Select error events"
  select_error(
    "Maximum number of objects to return"
    first: Int! = 1000, 
    "List of possible options for the group by"
    group_by: [bus_error_groupby_enum!]! = []
  ): [error_activity]

the part that causes the issue is this:
group_by: [bus_error_groupby_enum!]! = []
changing it to this, gets rid of the issue:
group_by: [bus_error_groupby_enum!] = []

I tried the code to understand where it came from and apparently it is in
src/main/java/com/kobylynskyi/graphql/codegen/mapper/DefaultValueMapper.java

  private static String mapArray(MappingContext mappingContext, ArrayValue defaultValue, Type<?> graphQLType) {
        if (!(graphQLType instanceof ListType)) {
            throw new IllegalArgumentException("Unexpected array default value for non-list type");
        }

the defaultValue is a list while the type is actually not a ListType but a NonNullType

Steps to Reproduce

Add this to your schema and try to generate the code
group_by: [bus_error_groupby_enum!]! = []

Expected Result

I would expect a NonNullType of List to accept a default value of type List

Actual Result

Code generation using gradle plugin from graphql schema fails with this message:
Unexpected array default value for non-list type

Your Environment and Setup

  • graphql-java-codegen: 1.7.3
  • Build tool: Gradle
  • Java tool: AdoptOpenJdk 11.0.6.10-hotspot
  • Mapping Config:
graphqlCodegen {
    graphqlSchemaPaths = ["$projectDir/generated_schema.graphqls".toString()]
    outputDir = new File("$buildDir/generated")
    generateApis = true
    generateToString = true
    modelValidationAnnotation = ""
    generateRequests = true
}

@kobylynskyi
Copy link
Owner

@IntiG, thanks for a very explanatory description!
The fix is on the way and should be available this week as part of version 2.0.0.

@kobylynskyi
Copy link
Owner

Please also note that generateRequests was deprecated in favor of generateClient (see #169)

@IntiG
Copy link
Author

IntiG commented Jun 17, 2020

@kobylynskyi thanks for this very cool plugin of yours, I like how readable and easy it is to build queries with the generated code :)
I'll switch to using generateClient thanks for letting me know.

On a side note, may I ask if you plan on supporting sbt plugin again? I know that there was one but not published and with a bit less "capabilities".

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

Successfully merging a pull request may close this issue.

2 participants