Type Mapping for Apollo Java Client

Hello Team,

I have a query regarding type Mapping generation in Apollo Client in Java. While i was exploring the Kotlin Client initially but as per the suggestions on the forum Android V2 version is more close for Java Functionality.

I tried using the Apollo Client and so far it looks good, I was able to generate Mappings for difference Schema, however i wanted to understand how the type mapping in the models gets generated.

I tried the following schema

mutation productDeleteByName($pid: Int) {
    delete_products(where: {product_id: {_eq: $pid}}) {
        returning {
            brand
            price
            product_id
            product_name
        }
    }
}

For which the corresponding Models that got generated had pid of Input<Integer> type viz

public ProductDeleteByNameMutation(@NotNull Input<Integer> pid) {
    Utils.checkNotNull(pid, "pid == null");
    variables = new ProductDeleteByNameMutation.Variables(pid);
  }

however when i use a non-nullable field like the following in schema

mutation productDeleteById($pid: Int!) {
    delete_products_by_pk(product_id: $pid) {
        brand
        price
        product_id
        product_name
    }
}

The corresponding model that got generated has pid of int type viz

public ProductDeleteByIdMutation(int pid) {
    variables = new ProductDeleteByIdMutation.Variables(pid);
  }

I wanted to understand how does mapping gets generated as in when it will be on primitive type and when of Input<Integer> type?

Is there a document where the corresponding mapping logic is highlighted or any docs that gives this information in detail? If yes please do share it.

Thanks in Advance!!

Hi :wave: Primitive types like int can never be null neither be used as type parameter so this is why Integer is used in these cases. int is still used in all other cases because it’s usually more efficient. I hope that helps?

1 Like