Apollo-android: Query/Mutation generation

Created on 1 Jul 2020  路  5Comments  路  Source: apollographql/apollo-android

Previously we used to call the query in the following way

val requestbuilder = ProductDetailsMutation.builder().Identifier(id)
        listingId?.let {
            requestbuilder.listingId(it)
        }
        val requestMutation = requestbuilder.build()

now after moving a model generation to Kotlin. The builder is not present.

 if(listingId == null){
          ProductDetailsMutation(Identifier=id)
}else{
         ProductDetailsMutation(Identifier=id,listingId= value)
}

if we have more conditions then it will become more complex
Any alternative to this?

Question

All 5 comments

You should be able to do something like this:

ProductDetailsMutation(
                     Identifier=id,
                     listingId= Input.optional(listingId)
)

what if I want to do something like
if (productCount > 0) { mutationBuilder = productMutationBuilder.productCount(1) }

if not then dont send

That would be something like:

ProductDetailsMutation(
                     Identifier = id,
                     listingId = if (productCount > 0) Input.optional(productCount) else Input.absent()
)

have following Inputype

data class RangeValueInput(
  val lt: Input<String> = Input.absent(),
  val gt: Input<String> = Input.absent(),
  val lte: Input<String> = Input.absent(),
  val gte: Input<String> = Input.absent(),
  val eq: Input<String> = Input.absent()
) : InputType {
  override fun marshaller(): InputFieldMarshaller = InputFieldMarshaller.invoke { writer ->
    if ([email protected]) {
      writer.writeString("lt", [email protected])
    }
    if ([email protected]) {
      writer.writeString("gt", [email protected])
    }

  }
}

how do i genrate RangeValueInput

On older version used to do
return RangeValueInput.builder().gte("20").build();

You can do something like:

return RangeValueInput(gte = Input.optional("20"))
Was this page helpful?
0 / 5 - 0 ratings