Skip to content

Unchecked Java warnings in generated classes #6430

@lanusau

Description

@lanusau

Version

4.1.1

Summary

I created example project at https://github.com/lanusau/apollo_warnings to illustrate the issue:

plugins {
    java
    id("com.apollographql.apollo") version "4.1.1"
}

apollo {
    service("example") {
        generateKotlinModels.set(false)
        packageName.set("example")
        srcDir("src/main/graphql")
        useSemanticNaming.set(true)
    }
}

Simple schema:

type Dog {
    id: Int!
    name: String!
    owner: String
}

input CreateDogInput {
    id: Int!
    name: String!
    owner: String
}

type Query {
    dogs(filter: String): [Dog!]
}

type Mutation {
    createDog(input: CreateDogInput!): Dog!
}

Simple query and mutation:

fragment DogFields on Dog {
    id
    name
    owner
}

query Dogs($filter: String) {
    dogs(filter: $filter) {
        ...DogFields
    }
}

mutation CreateDog($id: Int!, $name: String!, $owner: String) {
    createDog(input: {id: $id, name: $name, owner: $name}) {
        id
    }
}

Generates multiple Java compiler warnings of 2 types:

First is related to Optional.absent() not implemented correctly. It should be implemented like Java Optional with unchecked warnings suppressed

Second is using raw type of ImmutableMapBuilder

  required: Optional<String>
  found:    Absent
/Users/laianusa/GitRepos/github/apollo_warnings/build/generated/source/apollo/example/example/CreateDogMutation.java:151: warning: [unchecked] unchecked conversion
    private Optional<String> owner = Optional.absent();

/Users/laianusa/GitRepos/github/apollo_warnings/build/generated/source/apollo/example/example/selections/CreateDogMutationSelections.java:26: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type ImmutableMapBuilder
    new CompiledField.Builder("createDog", new CompiledNotNullType(Dog.type)).arguments(Arrays.asList(new CompiledArgument.Builder(Mutation.__createDog_input).value(new ImmutableMapBuilder().put("id", new CompiledVariable("id")).put("name", new CompiledVariable("name")).put("owner", new CompiledVariable("name")).build()).build())).selections(__createDog).build()
                                                                                                                                                                                                                                        ^
  where K,V are type-variables:
    K extends Object declared in class ImmutableMapBuilder
    V extends Object declared in class ImmutableMapBuilder

Steps to reproduce the behavior

No response

Logs

(Your logs here)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions