Repository: apollographql/apollo-kotlin
Pull request #4364 (2022-09-01 09:06:04)

Java builders 2
This is a follow up from https://github.com/apollographql/apollo-kotlin/pull/4361 with some minor cleanups/tweaks

Thanks @dwbutler for tackling this!! 

netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *apollo-android-docs* processing.


|  Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 5348777cfadbe89bc477e001c30261f9ad0612d7 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/apollo-android-docs/deploys/631075ffcb525b0008077b04 |
martinbonnin: Thanks again @dwbutler 

Patch:
diff --git a/apollo-api/api/apollo-api.api b/apollo-api/api/apollo-api.api
index 993b03b199..bc43d77a06 100644
--- a/apollo-api/api/apollo-api.api
+++ b/apollo-api/api/apollo-api.api
@@ -809,8 +809,11 @@ public final class com/apollographql/apollo3/api/Operations {
 
 public abstract class com/apollographql/apollo3/api/Optional {
 	public static final field Companion Lcom/apollographql/apollo3/api/Optional$Companion;
+	public static final fun absent ()Lcom/apollographql/apollo3/api/Optional;
 	public final fun getOrNull ()Ljava/lang/Object;
 	public final fun getOrThrow ()Ljava/lang/Object;
+	public static final fun present (Ljava/lang/Object;)Lcom/apollographql/apollo3/api/Optional;
+	public static final fun presentIfNotNull (Ljava/lang/Object;)Lcom/apollographql/apollo3/api/Optional;
 }
 
 public final class com/apollographql/apollo3/api/Optional$Absent : com/apollographql/apollo3/api/Optional {
@@ -818,6 +821,8 @@ public final class com/apollographql/apollo3/api/Optional$Absent : com/apollogra
 }
 
 public final class com/apollographql/apollo3/api/Optional$Companion {
+	public final fun absent ()Lcom/apollographql/apollo3/api/Optional;
+	public final fun present (Ljava/lang/Object;)Lcom/apollographql/apollo3/api/Optional;
 	public final fun presentIfNotNull (Ljava/lang/Object;)Lcom/apollographql/apollo3/api/Optional;
 }
 
diff --git a/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/Optional.kt b/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/Optional.kt
index 3e20cd748e..cc3cd5eaa0 100644
--- a/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/Optional.kt
+++ b/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/Optional.kt
@@ -3,6 +3,7 @@ package com.apollographql.apollo3.api
 import com.apollographql.apollo3.api.Optional.Absent
 import com.apollographql.apollo3.api.Optional.Present
 import com.apollographql.apollo3.exception.MissingValueException
+import kotlin.jvm.JvmStatic
 
 /**
  * A sealed class that can either be [Present] or [Absent]
@@ -18,6 +19,13 @@ sealed class Optional<out V> {
   object Absent : Optional<Nothing>()
 
   companion object {
+    @JvmStatic
+    fun <V> absent(): Optional<V> = Absent
+
+    @JvmStatic
+    fun <V> present(value: V): Optional<V> = Present(value)
+
+    @JvmStatic
     fun <V : Any> presentIfNotNull(value: V?): Optional<V> = if (value == null) Absent else Present(value)
   }
 }
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompiler.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompiler.kt
index 7221e3fae4..37f9ca88c7 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompiler.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/ApolloCompiler.kt
@@ -207,7 +207,8 @@ object ApolloCompiler {
             generatedSchemaName = options.generatedSchemaName,
             flatten = options.flattenModels,
             scalarMapping = options.scalarMapping,
-            generateDataBuilders = options.generateDataBuilders
+            generateDataBuilders = options.generateDataBuilders,
+            generateModelBuilder = options.generateModelBuilder
         ).write(outputDir = outputDir)
       }
       else -> {
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/Options.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/Options.kt
index 2c1eb67abe..a624ffdf45 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/Options.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/Options.kt
@@ -161,6 +161,14 @@ class Options(
     val generateDataBuilders: Boolean = defaultGenerateDataBuilders,
     val moduleName: String = defaultModuleName,
 
+    /**
+     * Whether to generate builders for java models
+     *
+     * Default value: false
+     * Only valid for java models as kotlin has data classes
+     */
+    val generateModelBuilder: Boolean = defaultGenerateModelBuilder,
+
     /**
      * A list of [Regex] patterns for GraphQL enums that should be generated as Kotlin sealed classes instead of the default Kotlin enums.
      *
@@ -324,6 +332,7 @@ class Options(
     const val defaultGeneratedSchemaName = "__Schema"
     const val defaultGenerateTestBuilders = false
     const val defaultGenerateDataBuilders = false
+    const val defaultGenerateModelBuilder = false
     val defaultSealedClassesForEnumsMatching = emptyList<String>()
     const val defaultGenerateOptionalOperationVariables = true
     const val defaultUseSchemaPackageNameForFragments = false
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/ClassNames.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/ClassNames.kt
index 2c134a0738..2ce662298b 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/ClassNames.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/ClassNames.kt
@@ -1,8 +1,5 @@
 package com.apollographql.apollo3.compiler.codegen
 
-import com.apollographql.apollo3.annotations.ApolloAdaptableWith
-import com.squareup.kotlinpoet.ClassName
-
 /**
  * A list of constant [ResolverClassName] that don't use `class.name` and therefore survive proguard/R8
  */
@@ -11,7 +8,9 @@ internal object ClassNames {
   const val apolloAnnotationsPackageName = "com.apollographql.apollo3.annotations"
   const val apolloApiJsonPackageName = "$apolloApiPackageName.json"
   const val apolloApiTestPackageName = "$apolloApiPackageName.test"
+  private const val jetbrainsAnnotationsPackageName = "org.jetbrains.annotations"
 
+  val Assertions = ResolverClassName(apolloApiPackageName, "Assertions")
   val ObjectType = ResolverClassName(apolloApiPackageName, "ObjectType")
   val InterfaceType = ResolverClassName(apolloApiPackageName, "InterfaceType")
   val ObjectTypeBuilder = ResolverClassName(apolloApiPackageName, "ObjectType", "Builder")
@@ -22,6 +21,7 @@ internal object ClassNames {
   val JsonReader = ResolverClassName(apolloApiJsonPackageName, "JsonReader")
   val JsonWriter = ResolverClassName(apolloApiJsonPackageName, "JsonWriter")
   val CustomScalarAdapters = ResolverClassName(apolloApiPackageName, "CustomScalarAdapters")
+  val Input = ResolverClassName(apolloApiPackageName, "Input")
   val CustomScalarAdaptersBuilder = ResolverClassName(apolloApiPackageName, "CustomScalarAdapters", "Builder")
   val Optional = ResolverClassName(apolloApiPackageName, "Optional")
   val Absent = ResolverClassName(apolloApiPackageName, "Optional", "Absent")
@@ -58,4 +58,6 @@ internal object ClassNames {
   val MapBuilder = ResolverClassName(apolloApiTestPackageName, "MapBuilder")
   val StubbedProperty = ResolverClassName(apolloApiTestPackageName, "StubbedProperty")
   val MandatoryTypenameProperty = ResolverClassName(apolloApiTestPackageName, "MandatoryTypenameProperty")
+  val JetBrainsNullable = ResolverClassName(jetbrainsAnnotationsPackageName, "Nullable")
+  val JetBrainsNonNull = ResolverClassName(jetbrainsAnnotationsPackageName, "NotNull")
 }
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaClassNames.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaClassNames.kt
index 2c860faa9d..285bfc0355 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaClassNames.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaClassNames.kt
@@ -1,15 +1,11 @@
 package com.apollographql.apollo3.compiler.codegen.java
 
-import com.apollographql.apollo3.api.DefaultFakeResolver
 import com.apollographql.apollo3.compiler.codegen.ClassNames
 import com.apollographql.apollo3.compiler.codegen.ClassNames.apolloApiJsonPackageName
 import com.apollographql.apollo3.compiler.codegen.ClassNames.apolloApiPackageName
 import com.apollographql.apollo3.compiler.codegen.ResolverClassName
-import com.apollographql.apollo3.compiler.codegen.kotlin.KotlinSymbols
-import com.apollographql.apollo3.compiler.codegen.kotlin.toKotlinPoetClassName
 import com.squareup.javapoet.ClassName
 import com.squareup.javapoet.ParameterizedTypeName
-import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
 
 /**
  * A list of constant [ResolverClassName] that don't use `class.name` and therefore survive proguard/R8
@@ -23,6 +19,7 @@ internal object JavaClassNames {
   val JsonReader = ClassNames.JsonReader.toJavaPoetClassName()
   val JsonWriter = ClassNames.JsonWriter.toJavaPoetClassName()
   val CustomScalarAdapters = ClassNames.CustomScalarAdapters.toJavaPoetClassName()
+  val Input = ClassNames.Input.toJavaPoetClassName()
   val CustomScalarAdaptersBuilder = ClassNames.CustomScalarAdaptersBuilder.toJavaPoetClassName()
   val Optional = ClassNames.Optional.toJavaPoetClassName()
   val Absent = ClassNames.Absent.toJavaPoetClassName()
@@ -56,12 +53,14 @@ internal object JavaClassNames {
   val DefaultFakeResolver = ClassNames.DefaultFakeResolver.toJavaPoetClassName()
   val JavaObjectBuilder = ClassName.get(apolloApiPackageName, "JavaObjectBuilder")
 
+  val Builder = ClassName.get("", "Builder")
+
   /**
    * ClassNames that we don't use in Kotlin because we use extension functions instead
    */
   val CompiledNotNullType = ClassName.get(apolloApiPackageName, "CompiledNotNullType")
   val CompiledListType = ClassName.get(apolloApiPackageName, "CompiledListType")
-  val ObjectAdapter  = ClassName.get(apolloApiPackageName, "ObjectAdapter")
+  val ObjectAdapter = ClassName.get(apolloApiPackageName, "ObjectAdapter")
   val And = ClassName.get(apolloApiPackageName, "BooleanExpression", "And")
   val Or = ClassName.get(apolloApiPackageName, "BooleanExpression", "Or")
   val Not = ClassName.get(apolloApiPackageName, "BooleanExpression", "Not")
@@ -99,6 +98,7 @@ internal object JavaClassNames {
   val Override = ClassName.get("java.lang", "Override")
 
   val List: ClassName = ClassName.get("java.util", "List")
+  val ArrayList: ClassName = ClassName.get("java.util", "ArrayList")
   val Arrays = ClassName.get("java.util", "Arrays")
   val Collections = ClassName.get("java.util", "Collections")
   val IllegalStateException = ClassName.get("java.lang", "IllegalStateException")
@@ -109,4 +109,7 @@ internal object JavaClassNames {
   val ObjectBuilderKt = ClassName.get(apolloApiPackageName, "ObjectBuilderKt")
   val ObjectMap = ClassName.get(apolloApiPackageName, "ObjectMap")
 
+  val JetBrainsNullable = ClassNames.JetBrainsNullable.toJavaPoetClassName()
+  val JetBrainsNonNull = ClassNames.JetBrainsNonNull.toJavaPoetClassName()
+
 }
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaCodeGen.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaCodeGen.kt
index 87cc680a84..9aa6e022aa 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaCodeGen.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaCodeGen.kt
@@ -51,6 +51,7 @@ internal class JavaCodeGen(
     private val generateQueryDocument: Boolean,
     private val generateSchema: Boolean,
     private val generatedSchemaName: String,
+    private val generateModelBuilder: Boolean,
     /**
      * Whether to flatten the models. This decision is left to the codegen. For fragments for an example, we
      * want to flatten at depth 1 to avoid name clashes, but it's ok to flatten fragment response adapters at
@@ -79,7 +80,8 @@ internal class JavaCodeGen(
 
     val context = JavaContext(
         layout = layout,
-        resolver = JavaResolver(emptyList(), upstreamResolver, scalarMapping)
+        resolver = JavaResolver(emptyList(), upstreamResolver, scalarMapping),
+        generateModelBuilder = generateModelBuilder
     )
     val builders = mutableListOf<JavaClassBuilder>()
 
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaContext.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaContext.kt
index 1d3b9e444d..0403b10059 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaContext.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaContext.kt
@@ -3,4 +3,5 @@ package com.apollographql.apollo3.compiler.codegen.java
 internal class JavaContext(
     val layout: JavaCodegenLayout,
     val resolver: JavaResolver,
+    val generateModelBuilder: Boolean,
 )
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/InputObjectBuilder.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/InputObjectBuilder.kt
index 0455a9ebdb..4b500bdd1b 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/InputObjectBuilder.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/InputObjectBuilder.kt
@@ -5,6 +5,7 @@ import com.apollographql.apollo3.compiler.codegen.java.CodegenJavaFile
 import com.apollographql.apollo3.compiler.codegen.java.JavaClassBuilder
 import com.apollographql.apollo3.compiler.codegen.java.JavaContext
 import com.apollographql.apollo3.compiler.codegen.java.L
+import com.apollographql.apollo3.compiler.codegen.java.helpers.Builder
 import com.apollographql.apollo3.compiler.codegen.java.helpers.makeDataClassFromParameters
 import com.apollographql.apollo3.compiler.codegen.java.helpers.toNamedType
 import com.apollographql.apollo3.compiler.codegen.java.helpers.toParameterSpec
@@ -42,5 +43,29 @@ internal class InputObjectBuilder(
           .makeDataClassFromParameters(fields.map {
             it.toNamedType().toParameterSpec(context)
           })
+          .addBuilder()
           .build()
+
+  private fun TypeSpec.Builder.addBuilder(): TypeSpec.Builder {
+    if (inputObject.fields.isEmpty()) {
+      // The GraphQL spec doesn't allow an input with no fields
+      return this
+    } else {
+      val builderFields = inputObject.fields.map {
+        context.layout.propertyName(it.name) to context.resolver.resolveIrType(it.type)
+      }
+      val javaDocs = inputObject.fields
+          .filter { !it.description.isNullOrBlank() }
+          .associate { context.layout.propertyName(it.name) to it.description!! }
+      return addMethod(Builder.builderFactoryMethod())
+          .addType(
+              Builder(
+                  targetObjectClassName = ClassName.get(packageName, simpleName),
+                  fields = builderFields,
+                  fieldJavaDocs = javaDocs,
+                  context = context
+              ).build()
+          )
+    }
+  }
 }
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/OperationBuilder.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/OperationBuilder.kt
index 89fe75e469..f98f160d2b 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/OperationBuilder.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/OperationBuilder.kt
@@ -18,6 +18,7 @@ import com.apollographql.apollo3.compiler.codegen.java.JavaContext
 import com.apollographql.apollo3.compiler.codegen.java.L
 import com.apollographql.apollo3.compiler.codegen.java.S
 import com.apollographql.apollo3.compiler.codegen.java.T
+import com.apollographql.apollo3.compiler.codegen.java.helpers.Builder
 import com.apollographql.apollo3.compiler.codegen.java.helpers.makeDataClassFromParameters
 import com.apollographql.apollo3.compiler.codegen.java.helpers.maybeAddDescription
 import com.apollographql.apollo3.compiler.codegen.java.helpers.toNamedType
@@ -88,6 +89,7 @@ internal class OperationBuilder(
         .addSuperinterface(superInterfaceType())
         .maybeAddDescription(operation.description)
         .makeDataClassFromParameters(operation.variables.map { it.toNamedType().toParameterSpec(context) })
+        .addBuilder(context)
         .addMethod(operationIdMethodSpec())
         .addMethod(queryDocumentMethodSpec(generateQueryDocument))
         .addMethod(nameMethodSpec())
@@ -246,5 +248,37 @@ internal class OperationBuilder(
         context.resolver.resolveOperationSelections(operation.name)
     )
   }
-}
 
+  private fun TypeSpec.Builder.addBuilder(context: JavaContext): TypeSpec.Builder {
+    addMethod(Builder.builderFactoryMethod())
+
+    val operationClassName = ClassName.get(packageName, simpleName)
+
+    if (operation.variables.isEmpty()) {
+      return addType(
+          Builder(
+              targetObjectClassName = operationClassName,
+              fields = emptyList(),
+              fieldJavaDocs = emptyMap(),
+              context = context
+          ).build()
+      )
+    }
+
+    operation.variables
+        .map {
+          context.layout.propertyName(it.name) to context.resolver.resolveIrType(it.type)
+        }
+        .let {
+          Builder(
+              targetObjectClassName = operationClassName,
+              fields = it,
+              fieldJavaDocs = emptyMap(),
+              context = context
+          )
+        }
+        .let { addType(it.build()) }
+
+    return this
+  }
+}
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/Builder.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/Builder.kt
new file mode 100644
index 0000000000..fe1c140871
--- /dev/null
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/Builder.kt
@@ -0,0 +1,122 @@
+package com.apollographql.apollo3.compiler.codegen.java.helpers
+
+import com.apollographql.apollo3.compiler.codegen.ClassNames
+import com.apollographql.apollo3.compiler.codegen.java.JavaClassNames
+import com.apollographql.apollo3.compiler.codegen.java.JavaContext
+import com.squareup.javapoet.AnnotationSpec
+import com.squareup.javapoet.ClassName
+import com.squareup.javapoet.CodeBlock
+import com.squareup.javapoet.FieldSpec
+import com.squareup.javapoet.MethodSpec
+import com.squareup.javapoet.ParameterSpec
+import com.squareup.javapoet.TypeName
+import com.squareup.javapoet.TypeSpec
+import javax.lang.model.element.Modifier
+
+internal class Builder(
+    val targetObjectClassName: ClassName,
+    val fields: List<Pair<String, TypeName>>,
+    val fieldJavaDocs: Map<String, String>,
+    val context: JavaContext,
+) {
+  fun build(): TypeSpec {
+    return TypeSpec.classBuilder(JavaClassNames.Builder.simpleName())
+        .addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
+        .addFields(builderFields())
+        .addMethod(MethodSpec.constructorBuilder().build())
+        .addMethods(fieldSetterMethodSpecs())
+        .addMethods(inputFieldSetterMethodSpecs())
+        .addMethod(buildMethod())
+        .build()
+  }
+
+  private fun builderFields(): List<FieldSpec> {
+    return fields.map { (fieldName, fieldType) ->
+      FieldSpec.builder(fieldType, fieldName)
+          .addModifiers(Modifier.PRIVATE)
+          .build()
+    }
+  }
+
+  private fun fieldSetterMethodSpecs(): List<MethodSpec> {
+    return fields.map { (fieldName, fieldType) ->
+      val javaDoc = fieldJavaDocs[fieldName]
+      fieldSetterMethodSpec(fieldName, fieldType, javaDoc)
+    }
+  }
+
+  private fun fieldSetterMethodSpec(fieldName: String, fieldType: TypeName, javaDoc: String?): MethodSpec {
+    return MethodSpec.methodBuilder(fieldName)
+        .addModifiers(Modifier.PUBLIC)
+        .addParameter(ParameterSpec.builder(fieldType.unwrapOptionalType(), fieldName).build())
+        .apply {
+          if (!javaDoc.isNullOrBlank()) {
+            addJavadoc(CodeBlock.of("\$L\n", javaDoc))
+          }
+        }
+        .returns(JavaClassNames.Builder)
+        .addStatement("this.\$L = \$L", fieldName, fieldType.wrapOptionalValue(CodeBlock.of("\$L", fieldName)))
+        .addStatement("return this")
+        .build()
+  }
+
+  private fun inputFieldSetterMethodSpecs(): List<MethodSpec> {
+    return fields.filter { (_, fieldType) -> fieldType.isOptional(JavaClassNames.Input) }
+        .map { (fieldName, fieldType) ->
+          val javaDoc = fieldJavaDocs[fieldName]
+          inputFieldSetterMethodSpec(fieldName, fieldType, javaDoc)
+        }
+  }
+
+  private fun inputFieldSetterMethodSpec(fieldName: String, fieldType: TypeName, javaDoc: String?): MethodSpec {
+    return MethodSpec.methodBuilder("${fieldName}Input")
+        .addModifiers(Modifier.PUBLIC)
+        .addParameter(
+            ParameterSpec.builder(fieldType, fieldName)
+                .addAnnotation(AnnotationSpec.builder(JavaClassNames.JetBrainsNonNull).build())
+                .build())
+
+        .apply {
+          if (!javaDoc.isNullOrBlank()) {
+            addJavadoc(CodeBlock.of("\$L\n", javaDoc))
+          }
+        }
+        .returns(JavaClassNames.Builder)
+        .addStatement("this.\$L = \$T.checkFieldNotMissing(\$L, \$S)", fieldName, ClassNames.Assertions, fieldName, fieldName)
+        .addStatement("return this")
+        .build()
+  }
+
+  private fun buildMethod(): MethodSpec {
+    val validationCodeBuilder = fields.filter { (_, fieldType) ->
+      !fieldType.isPrimitive && fieldType.annotations.contains(AnnotationSpec.builder(JavaClassNames.JetBrainsNonNull).build())
+    }.map { (fieldName, _) ->
+      CodeBlock.of("\$T.checkFieldNotMissing(\$L, \$S);\n", ClassNames.Assertions, fieldName, fieldName)
+    }.fold(CodeBlock.builder(), CodeBlock.Builder::add)
+
+    return MethodSpec
+        .methodBuilder("build")
+        .addModifiers(Modifier.PUBLIC)
+        .returns(targetObjectClassName)
+        .addCode(validationCodeBuilder.build())
+        .addStatement(
+            "return new \$T\$L",
+            targetObjectClassName,
+            fields.joinToString(prefix = "(", separator = ", ", postfix = ")") { it.first }
+        )
+        .build()
+  }
+
+  companion object {
+    const val TO_BUILDER_METHOD_NAME = "toBuilder"
+
+    fun builderFactoryMethod(): MethodSpec {
+      return MethodSpec
+          .methodBuilder("builder")
+          .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+          .returns(JavaClassNames.Builder)
+          .addStatement("return new \$T()", JavaClassNames.Builder)
+          .build()
+    }
+  }
+}
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/TypeName.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/TypeName.kt
new file mode 100644
index 0000000000..1943321e2e
--- /dev/null
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/TypeName.kt
@@ -0,0 +1,39 @@
+package com.apollographql.apollo3.compiler.codegen.java.helpers
+
+import com.apollographql.apollo3.compiler.codegen.java.JavaClassNames
+import com.squareup.javapoet.AnnotationSpec
+import com.squareup.javapoet.ClassName
+import com.squareup.javapoet.CodeBlock
+import com.squareup.javapoet.ParameterizedTypeName
+import com.squareup.javapoet.TypeName
+
+internal fun TypeName.isOptional(expectedOptionalType: ClassName? = null): Boolean {
+  val rawType = (this as? ParameterizedTypeName)?.rawType ?: this
+  return if (expectedOptionalType == null) {
+    rawType == JavaClassNames.Optional
+  } else {
+    rawType == expectedOptionalType
+  }
+}
+
+internal fun TypeName.unwrapOptionalType(withoutAnnotations: Boolean = false): TypeName {
+  return if (isOptional()) {
+    val unwrappedTypeName = (this as ParameterizedTypeName).typeArguments.first()
+    if (unwrappedTypeName == JavaClassNames.Object) {
+      // Workaround for "annotation @org.jetbrains.annotations.Nullable not applicable in this type context"
+      unwrappedTypeName
+    } else {
+      unwrappedTypeName.annotated(AnnotationSpec.builder(JavaClassNames.JetBrainsNullable).build())
+    }
+  } else {
+    this
+  }.let { if (withoutAnnotations) it.withoutAnnotations() else it }
+}
+
+internal fun TypeName.wrapOptionalValue(value: CodeBlock): CodeBlock {
+  return if (this.isOptional() && this is ParameterizedTypeName) {
+    CodeBlock.of("\$T.presentIfNotNull(\$L)", rawType, value)
+  } else {
+    value
+  }
+}
diff --git a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/model/ModelBuilder.kt b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/model/ModelBuilder.kt
index 9bd21f0574..bc15b73b5c 100644
--- a/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/model/ModelBuilder.kt
+++ b/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/model/ModelBuilder.kt
@@ -5,20 +5,20 @@ import com.apollographql.apollo3.compiler.codegen.CodegenLayout.Companion.upperC
 import com.apollographql.apollo3.compiler.codegen.java.JavaClassNames
 import com.apollographql.apollo3.compiler.codegen.java.JavaContext
 import com.apollographql.apollo3.compiler.codegen.java.adapter.toClassName
+import com.apollographql.apollo3.compiler.codegen.java.helpers.Builder
 import com.apollographql.apollo3.compiler.codegen.java.helpers.makeDataClassFromProperties
 import com.apollographql.apollo3.compiler.codegen.java.helpers.maybeAddDeprecation
 import com.apollographql.apollo3.compiler.codegen.java.helpers.maybeAddDescription
-import com.apollographql.apollo3.compiler.codegen.kotlin.KotlinSymbols
 import com.apollographql.apollo3.compiler.decapitalizeFirstLetter
 import com.apollographql.apollo3.compiler.ir.IrAccessor
 import com.apollographql.apollo3.compiler.ir.IrFragmentAccessor
 import com.apollographql.apollo3.compiler.ir.IrModel
 import com.apollographql.apollo3.compiler.ir.IrSubtypeAccessor
 import com.squareup.javapoet.ClassName
+import com.squareup.javapoet.CodeBlock
 import com.squareup.javapoet.FieldSpec
+import com.squareup.javapoet.MethodSpec
 import com.squareup.javapoet.TypeSpec
-import com.squareup.kotlinpoet.AnnotationSpec
-import com.squareup.kotlinpoet.CodeBlock
 import javax.lang.model.element.Modifier
 
 /**
@@ -92,6 +92,13 @@ internal class ModelBuilder(
         .addTypes(nestedTypes)
         .addSuperinterfaces(superInterfaces)
         .build()
+        .let {
+          if (context.generateModelBuilder) {
+            it.addBuilder(context)
+          } else {
+            it
+          }
+        }
   }
 
 
@@ -103,4 +110,38 @@ internal class ModelBuilder(
       }
     }
   }
+
+  private fun TypeSpec.addBuilder(context: JavaContext): TypeSpec {
+    val fields = fieldSpecs.filter { !it.modifiers.contains(Modifier.STATIC) }
+        .filterNot { it.name.startsWith(prefix = "$") }
+    if (fields.isEmpty()) {
+      return this
+    } else {
+      val builderVariable = JavaClassNames.Builder.simpleName().decapitalizeFirstLetter()
+      val builderClass = ClassName.get("", JavaClassNames.Builder.simpleName())
+      val toBuilderMethod = MethodSpec.methodBuilder(Builder.TO_BUILDER_METHOD_NAME)
+          .addModifiers(Modifier.PUBLIC)
+          .returns(builderClass)
+          .addStatement("\$T \$L = new \$T()", builderClass, builderVariable, builderClass)
+          .addCode(fields
+              .map { CodeBlock.of("\$L.\$L = \$L;\n", builderVariable, context.layout.propertyName(it.name), context.layout.propertyName(it.name)) }
+              .fold(CodeBlock.builder()) { builder, code -> builder.add(code) }
+              .build()
+          )
+          .addStatement("return \$L", builderVariable)
+          .build()
+
+      return toBuilder()
+          .addMethod(toBuilderMethod)
+          .addMethod(Builder.builderFactoryMethod())
+          .addType(
+              Builder(
+                  targetObjectClassName = ClassName.get("", name),
+                  fields = fields.map { context.layout.propertyName(it.name) to it.type },
+                  fieldJavaDocs = emptyMap(),
+                  context = context
+              ).build()
+          ).build()
+    }
+  }
 }
diff --git a/apollo-gradle-plugin-external/api/apollo-gradle-plugin-external.api b/apollo-gradle-plugin-external/api/apollo-gradle-plugin-external.api
index 1a1435be48..a48aff0b0b 100644
--- a/apollo-gradle-plugin-external/api/apollo-gradle-plugin-external.api
+++ b/apollo-gradle-plugin-external/api/apollo-gradle-plugin-external.api
@@ -76,6 +76,7 @@ public abstract interface class com/apollographql/apollo3/gradle/api/Service {
 	public abstract fun getGenerateDataBuilders ()Lorg/gradle/api/provider/Property;
 	public abstract fun getGenerateFragmentImplementations ()Lorg/gradle/api/provider/Property;
 	public abstract fun getGenerateKotlinModels ()Lorg/gradle/api/provider/Property;
+	public abstract fun getGenerateModelBuilder ()Lorg/gradle/api/provider/Property;
 	public abstract fun getGenerateOperationOutput ()Lorg/gradle/api/provider/Property;
 	public abstract fun getGenerateOptionalOperationVariables ()Lorg/gradle/api/provider/Property;
 	public abstract fun getGenerateQueryDocument ()Lorg/gradle/api/provider/Property;
diff --git a/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt b/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt
index 4304b95be8..4fcd1bff99 100644
--- a/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt
+++ b/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt
@@ -445,6 +445,14 @@ interface Service {
   @ApolloExperimental
   val generateDataBuilders: Property<Boolean>
 
+  /**
+   * Whether to generate response model builders for Java.
+   *
+   * Default: false
+   */
+  @ApolloExperimental
+  val generateModelBuilder: Property<Boolean>
+
   /**
    * What codegen to use. One of "operationBased", "responseBased" or "compat"
    *
diff --git a/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateSourcesTask.kt b/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateSourcesTask.kt
index aea41db05e..b760795318 100644
--- a/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateSourcesTask.kt
+++ b/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/ApolloGenerateSourcesTask.kt
@@ -21,6 +21,7 @@ import com.apollographql.apollo3.compiler.Options.Companion.defaultGenerateAsInt
 import com.apollographql.apollo3.compiler.Options.Companion.defaultGenerateDataBuilders
 import com.apollographql.apollo3.compiler.Options.Companion.defaultGenerateFilterNotNull
 import com.apollographql.apollo3.compiler.Options.Companion.defaultGenerateFragmentImplementations
+import com.apollographql.apollo3.compiler.Options.Companion.defaultGenerateModelBuilder
 import com.apollographql.apollo3.compiler.Options.Companion.defaultGenerateOptionalOperationVariables
 import com.apollographql.apollo3.compiler.Options.Companion.defaultGenerateQueryDocument
 import com.apollographql.apollo3.compiler.Options.Companion.defaultGenerateResponseFields
@@ -120,6 +121,10 @@ abstract class ApolloGenerateSourcesTask : DefaultTask() {
   @get:Optional
   abstract val languageVersion: Property<String>
 
+  @get:Input
+  @get:Optional
+  abstract val generateModelBuilder: Property<Boolean>
+
   @get:Input
   @get:Optional
   abstract val generateQueryDocument: Property<Boolean>
@@ -292,6 +297,7 @@ abstract class ApolloGenerateSourcesTask : DefaultTask() {
         generateAsInternal = generateAsInternal.getOrElse(defaultGenerateAsInternal),
         generateFilterNotNull = generateFilterNotNull.getOrElse(defaultGenerateFilterNotNull),
         generateFragmentImplementations = generateFragmentImplementations.getOrElse(defaultGenerateFragmentImplementations),
+        generateModelBuilder = generateModelBuilder.getOrElse(defaultGenerateModelBuilder),
         generateQueryDocument = generateQueryDocument.getOrElse(defaultGenerateQueryDocument),
         generateSchema = generateSchema.getOrElse(defaultGenerateSchema),
         generatedSchemaName = generatedSchemaName.getOrElse(defaultGeneratedSchemaName),
diff --git a/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt b/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt
index fe872730d8..737bebf8ae 100644
--- a/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt
+++ b/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/internal/DefaultApolloExtension.kt
@@ -91,7 +91,7 @@ abstract class DefaultApolloExtension(
       task.group = TASK_GROUP
       task.projectRootDir = project.rootDir.absolutePath
     }
-    
+
     /**
      * A simple task to be used from the command line to ease schema conversion
      */
@@ -560,6 +560,7 @@ abstract class DefaultApolloExtension(
       task.generateQueryDocument.set(service.generateQueryDocument)
       task.generateSchema.set(service.generateSchema)
       task.generatedSchemaName.set(service.generatedSchemaName)
+      task.generateModelBuilder.set(service.generateModelBuilder)
       task.codegenModels.set(service.codegenModels)
       task.addTypename.set(service.addTypename)
       task.flattenModels.set(service.flattenModels)


Test patch:
diff --git a/apollo-api/src/commonTest/kotlin/test/OptionalTest.kt b/apollo-api/src/commonTest/kotlin/test/OptionalTest.kt
index e4e8ecbe9f..433efcc9fd 100644
--- a/apollo-api/src/commonTest/kotlin/test/OptionalTest.kt
+++ b/apollo-api/src/commonTest/kotlin/test/OptionalTest.kt
@@ -2,12 +2,19 @@ package test
 
 import com.apollographql.apollo3.api.Optional
 import kotlin.test.Test
+import kotlin.test.assertFails
 import kotlin.test.assertIs
 
 class OptionalTest {
+  @Test
+  fun presentTest() {
+    assertIs<Optional.Present<*>>(Optional.present("some value"))
+    assertIs<Optional.Present<*>>(Optional.present(null))
+  }
+
   @Test
   fun presentIfNotNullTest() {
     assertIs<Optional.Present<*>>(Optional.presentIfNotNull("some value"))
     assertIs<Optional.Absent>(Optional.presentIfNotNull(null))
   }
-}
\ No newline at end of file
+}
diff --git a/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ColorInput.java.expected b/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ColorInput.java.expected
index d3dbca359c..5d485a4b19 100644
--- a/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ColorInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ColorInput.java.expected
@@ -11,6 +11,7 @@ import java.lang.Integer;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * The input object sent when passing in a color
@@ -90,4 +91,67 @@ public class ColorInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<Integer> red;
+
+    private Optional<Double> green;
+
+    private Optional<Double> blue;
+
+    private Optional<Episode> enumWithDefaultValue;
+
+    private Optional<ReviewRefInput> reviewRefInput;
+
+    Builder() {
+    }
+
+    /**
+     * Red color
+     */
+    public Builder red(@Nullable Integer red) {
+      this.red = Optional.presentIfNotNull(red);
+      return this;
+    }
+
+    /**
+     * Green color
+     */
+    public Builder green(@Nullable Double green) {
+      this.green = Optional.presentIfNotNull(green);
+      return this;
+    }
+
+    /**
+     * Blue color
+     */
+    public Builder blue(@Nullable Double blue) {
+      this.blue = Optional.presentIfNotNull(blue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder enumWithDefaultValue(@Nullable Episode enumWithDefaultValue) {
+      this.enumWithDefaultValue = Optional.presentIfNotNull(enumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * Circle ref to review input
+     */
+    public Builder reviewRefInput(@Nullable ReviewRefInput reviewRefInput) {
+      this.reviewRefInput = Optional.presentIfNotNull(reviewRefInput);
+      return this;
+    }
+
+    public ColorInput build() {
+      return new ColorInput(red, green, blue, enumWithDefaultValue, reviewRefInput);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ReviewInput.java.expected b/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ReviewInput.java.expected
index 74461a50ce..8ac7642be5 100644
--- a/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ReviewInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ReviewInput.java.expected
@@ -12,6 +12,7 @@ import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
 import java.util.List;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * The input object sent when someone is creating a new review
@@ -220,4 +221,239 @@ public class ReviewInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Integer stars;
+
+    private Optional<Integer> nullableIntFieldWithDefaultValue;
+
+    private Optional<String> commentary;
+
+    private ColorInput favoriteColor;
+
+    private Optional<Episode> enumWithDefaultValue;
+
+    private Optional<Episode> nonNullableEnumWithDefaultValue;
+
+    private Optional<Episode> nullableEnum;
+
+    private Optional<List<Object>> listOfCustomScalar;
+
+    private Optional<Object> customScalar;
+
+    private Optional<List<Episode>> listOfEnums;
+
+    private Optional<List<Integer>> listOfInt;
+
+    private Optional<List<String>> listOfString;
+
+    private List<String> listOfStringNonOptional;
+
+    private Optional<List<ColorInput>> listOfInputTypes;
+
+    private Optional<Boolean> booleanWithDefaultValue;
+
+    private Optional<Boolean> booleanNonOptional;
+
+    private Optional<List<List<String>>> listOfListOfString;
+
+    private Optional<List<List<Episode>>> listOfListOfEnum;
+
+    private Optional<List<List<Object>>> listOfListOfCustom;
+
+    private Optional<List<List<ColorInput>>> listOfListOfObject;
+
+    private Optional<String> CapitalizedField;
+
+    private Optional<Integer> CapitalizedInt;
+
+    Builder() {
+    }
+
+    /**
+     * 0-5 stars
+     */
+    public Builder stars(Integer stars) {
+      this.stars = stars;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nullableIntFieldWithDefaultValue(
+        @Nullable Integer nullableIntFieldWithDefaultValue) {
+      this.nullableIntFieldWithDefaultValue = Optional.presentIfNotNull(nullableIntFieldWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * Comment about the movie, optional
+     */
+    public Builder commentary(@Nullable String commentary) {
+      this.commentary = Optional.presentIfNotNull(commentary);
+      return this;
+    }
+
+    /**
+     * Favorite color, optional
+     */
+    public Builder favoriteColor(ColorInput favoriteColor) {
+      this.favoriteColor = favoriteColor;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder enumWithDefaultValue(@Nullable Episode enumWithDefaultValue) {
+      this.enumWithDefaultValue = Optional.presentIfNotNull(enumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nonNullableEnumWithDefaultValue(
+        @Nullable Episode nonNullableEnumWithDefaultValue) {
+      this.nonNullableEnumWithDefaultValue = Optional.presentIfNotNull(nonNullableEnumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nullableEnum(@Nullable Episode nullableEnum) {
+      this.nullableEnum = Optional.presentIfNotNull(nullableEnum);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfCustomScalar(@Nullable List<Object> listOfCustomScalar) {
+      this.listOfCustomScalar = Optional.presentIfNotNull(listOfCustomScalar);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder customScalar(Object customScalar) {
+      this.customScalar = Optional.presentIfNotNull(customScalar);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfEnums(@Nullable List<Episode> listOfEnums) {
+      this.listOfEnums = Optional.presentIfNotNull(listOfEnums);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfInt(@Nullable List<Integer> listOfInt) {
+      this.listOfInt = Optional.presentIfNotNull(listOfInt);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfString(@Nullable List<String> listOfString) {
+      this.listOfString = Optional.presentIfNotNull(listOfString);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfStringNonOptional(List<String> listOfStringNonOptional) {
+      this.listOfStringNonOptional = listOfStringNonOptional;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfInputTypes(@Nullable List<ColorInput> listOfInputTypes) {
+      this.listOfInputTypes = Optional.presentIfNotNull(listOfInputTypes);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder booleanWithDefaultValue(@Nullable Boolean booleanWithDefaultValue) {
+      this.booleanWithDefaultValue = Optional.presentIfNotNull(booleanWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder booleanNonOptional(@Nullable Boolean booleanNonOptional) {
+      this.booleanNonOptional = Optional.presentIfNotNull(booleanNonOptional);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfString(@Nullable List<List<String>> listOfListOfString) {
+      this.listOfListOfString = Optional.presentIfNotNull(listOfListOfString);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfEnum(@Nullable List<List<Episode>> listOfListOfEnum) {
+      this.listOfListOfEnum = Optional.presentIfNotNull(listOfListOfEnum);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfCustom(@Nullable List<List<Object>> listOfListOfCustom) {
+      this.listOfListOfCustom = Optional.presentIfNotNull(listOfListOfCustom);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfObject(@Nullable List<List<ColorInput>> listOfListOfObject) {
+      this.listOfListOfObject = Optional.presentIfNotNull(listOfListOfObject);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder CapitalizedField(@Nullable String CapitalizedField) {
+      this.CapitalizedField = Optional.presentIfNotNull(CapitalizedField);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder CapitalizedInt(@Nullable Integer CapitalizedInt) {
+      this.CapitalizedInt = Optional.presentIfNotNull(CapitalizedInt);
+      return this;
+    }
+
+    public ReviewInput build() {
+      return new ReviewInput(stars, nullableIntFieldWithDefaultValue, commentary, favoriteColor, enumWithDefaultValue, nonNullableEnumWithDefaultValue, nullableEnum, listOfCustomScalar, customScalar, listOfEnums, listOfInt, listOfString, listOfStringNonOptional, listOfInputTypes, booleanWithDefaultValue, booleanNonOptional, listOfListOfString, listOfListOfEnum, listOfListOfCustom, listOfListOfObject, CapitalizedField, CapitalizedInt);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ReviewRefInput.java.expected b/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ReviewRefInput.java.expected
index 11408ff9bc..442e73baa7 100644
--- a/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ReviewRefInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/__schema/java/operationBased/__schema/type/ReviewRefInput.java.expected
@@ -9,6 +9,7 @@ import com.apollographql.apollo3.api.Optional;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Circle ref to review input
@@ -59,4 +60,24 @@ public class ReviewRefInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<ReviewInput> reviewInput;
+
+    Builder() {
+    }
+
+    public Builder reviewInput(@Nullable ReviewInput reviewInput) {
+      this.reviewInput = Optional.presentIfNotNull(reviewInput);
+      return this;
+    }
+
+    public ReviewRefInput build() {
+      return new ReviewRefInput(reviewInput);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/antlr_tokens/java/operationBased/antlr_tokens/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/antlr_tokens/java/operationBased/antlr_tokens/TestQuery.java.expected
index d049dd0af6..a3378acf15 100644
--- a/apollo-compiler/src/test/graphql/com/example/antlr_tokens/java/operationBased/antlr_tokens/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/antlr_tokens/java/operationBased/antlr_tokens/TestQuery.java.expected
@@ -19,6 +19,7 @@ import java.io.IOException;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 public class TestQuery implements Query<TestQuery.Data> {
   public static final String OPERATION_ID = "197e186cfb461d1c38c0be4da7b182eff42e304043973b994c8c2de3535daea6";
@@ -85,6 +86,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -121,6 +126,22 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Optional<String> operation;
+
+    Builder() {
+    }
+
+    public Builder operation(@Nullable String operation) {
+      this.operation = Optional.presentIfNotNull(operation);
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(operation);
+    }
+  }
+
   public static class Data implements Query.Data {
     public TypeWithGraphQLKeywords typeWithGraphQLKeywords;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/arguments_hardcoded/java/operationBased/arguments_hardcoded/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/arguments_hardcoded/java/operationBased/arguments_hardcoded/TestQuery.java.expected
index 0213b6ba04..4f61ed3fc8 100644
--- a/apollo-compiler/src/test/graphql/com/example/arguments_hardcoded/java/operationBased/arguments_hardcoded/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/arguments_hardcoded/java/operationBased/arguments_hardcoded/TestQuery.java.expected
@@ -79,6 +79,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -115,6 +119,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public List<Review> reviews;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/capitalized_fields/java/operationBased/capitalized_fields/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/capitalized_fields/java/operationBased/capitalized_fields/TestQuery.java.expected
index 39a0ca6ab2..50f3130a6b 100644
--- a/apollo-compiler/src/test/graphql/com/example/capitalized_fields/java/operationBased/capitalized_fields/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/capitalized_fields/java/operationBased/capitalized_fields/TestQuery.java.expected
@@ -81,6 +81,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -117,6 +121,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Horse Horse;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/java/operationBased/case_sensitive_enum/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/java/operationBased/case_sensitive_enum/TestQuery.java.expected
index 801c865471..75acb65abc 100644
--- a/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/java/operationBased/case_sensitive_enum/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/java/operationBased/case_sensitive_enum/TestQuery.java.expected
@@ -74,6 +74,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -110,6 +114,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Enum enum_;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/custom_scalar_type/java/operationBased/custom_scalar_type/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/custom_scalar_type/java/operationBased/custom_scalar_type/TestQuery.java.expected
index 3f25e1ebc8..c5046617fe 100644
--- a/apollo-compiler/src/test/graphql/com/example/custom_scalar_type/java/operationBased/custom_scalar_type/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/custom_scalar_type/java/operationBased/custom_scalar_type/TestQuery.java.expected
@@ -84,6 +84,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -120,6 +124,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/deprecated_merged_field/java/operationBased/deprecated_merged_field/CatQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/deprecated_merged_field/java/operationBased/deprecated_merged_field/CatQuery.java.expected
index e88d2350c3..7bd0926daf 100644
--- a/apollo-compiler/src/test/graphql/com/example/deprecated_merged_field/java/operationBased/deprecated_merged_field/CatQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/deprecated_merged_field/java/operationBased/deprecated_merged_field/CatQuery.java.expected
@@ -87,6 +87,10 @@ public class CatQuery implements Query<CatQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -123,6 +127,15 @@ public class CatQuery implements Query<CatQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public CatQuery build() {
+      return new CatQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Cat cat;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/deprecation/java/operationBased/deprecation/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/deprecation/java/operationBased/deprecation/TestQuery.java.expected
index f8c26259ac..ebd9ec4040 100644
--- a/apollo-compiler/src/test/graphql/com/example/deprecation/java/operationBased/deprecation/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/deprecation/java/operationBased/deprecation/TestQuery.java.expected
@@ -22,6 +22,7 @@ import java.lang.Deprecated;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 public class TestQuery implements Query<TestQuery.Data> {
   public static final String OPERATION_ID = "6a8dd101c1681dc829d72040868fdf394c52bacb692da3549bc73e9504013470";
@@ -88,6 +89,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -124,6 +129,22 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Optional<Episode> episode;
+
+    Builder() {
+    }
+
+    public Builder episode(@Nullable Episode episode) {
+      this.episode = Optional.presentIfNotNull(episode);
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(episode);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/TestQuery.java.expected
index f349deb697..017d291811 100644
--- a/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/TestQuery.java.expected
@@ -74,6 +74,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -110,6 +114,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Gravity gravity;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/java/operationBased/enums_as_sealed/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/java/operationBased/enums_as_sealed/TestQuery.java.expected
index f7cd192df7..b07c7cc0c5 100644
--- a/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/java/operationBased/enums_as_sealed/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/java/operationBased/enums_as_sealed/TestQuery.java.expected
@@ -74,6 +74,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -110,6 +114,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Enum enum_;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/field_with_include_directive/java/operationBased/field_with_include_directive/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/field_with_include_directive/java/operationBased/field_with_include_directive/TestQuery.java.expected
index 28e9194ecc..fc7d84d6f8 100644
--- a/apollo-compiler/src/test/graphql/com/example/field_with_include_directive/java/operationBased/field_with_include_directive/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/field_with_include_directive/java/operationBased/field_with_include_directive/TestQuery.java.expected
@@ -94,6 +94,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -130,6 +134,29 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Boolean includeName;
+
+    private Boolean skipFriends;
+
+    Builder() {
+    }
+
+    public Builder includeName(Boolean includeName) {
+      this.includeName = includeName;
+      return this;
+    }
+
+    public Builder skipFriends(Boolean skipFriends) {
+      this.skipFriends = skipFriends;
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(includeName, skipFriends);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/java/operationBased/fieldset_with_multiple_super/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/java/operationBased/fieldset_with_multiple_super/TestQuery.java.expected
index ef85922071..3f9711d6f9 100644
--- a/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/java/operationBased/fieldset_with_multiple_super/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fieldset_with_multiple_super/java/operationBased/fieldset_with_multiple_super/TestQuery.java.expected
@@ -89,6 +89,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -125,6 +129,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public C c;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_spread_with_include_directive/java/operationBased/fragment_spread_with_include_directive/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/fragment_spread_with_include_directive/java/operationBased/fragment_spread_with_include_directive/TestQuery.java.expected
index 78d76c3dee..c23b937eca 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragment_spread_with_include_directive/java/operationBased/fragment_spread_with_include_directive/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragment_spread_with_include_directive/java/operationBased/fragment_spread_with_include_directive/TestQuery.java.expected
@@ -103,6 +103,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -139,6 +143,29 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Boolean withDetails;
+
+    private Boolean skipHumanDetails;
+
+    Builder() {
+    }
+
+    public Builder withDetails(Boolean withDetails) {
+      this.withDetails = withDetails;
+      return this;
+    }
+
+    public Builder skipHumanDetails(Boolean skipHumanDetails) {
+      this.skipHumanDetails = skipHumanDetails;
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(withDetails, skipHumanDetails);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_spread_with_nested_fields/java/operationBased/fragment_spread_with_nested_fields/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/fragment_spread_with_nested_fields/java/operationBased/fragment_spread_with_nested_fields/TestQuery.java.expected
index 48c2283db3..0fdcf771d1 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragment_spread_with_nested_fields/java/operationBased/fragment_spread_with_nested_fields/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragment_spread_with_nested_fields/java/operationBased/fragment_spread_with_nested_fields/TestQuery.java.expected
@@ -89,6 +89,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -125,6 +129,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_used_twice/java/operationBased/fragment_used_twice/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/fragment_used_twice/java/operationBased/fragment_used_twice/TestQuery.java.expected
index 1d40a77402..fc5e18dba4 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragment_used_twice/java/operationBased/fragment_used_twice/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragment_used_twice/java/operationBased/fragment_used_twice/TestQuery.java.expected
@@ -96,6 +96,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -132,6 +136,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/TestQuery.java.expected
index 4d3c9b8f1c..db3bceba93 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/TestQuery.java.expected
@@ -108,6 +108,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -144,6 +148,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
@@ -190,6 +203,32 @@ public class TestQuery implements Query<TestQuery.Data> {
       }
       return $toString;
     }
+
+    public Builder toBuilder() {
+      Builder builder = new Builder();
+      builder.hero = hero;
+      return builder;
+    }
+
+    public static Builder builder() {
+      return new Builder();
+    }
+
+    public static final class Builder {
+      private Hero hero;
+
+      Builder() {
+      }
+
+      public Builder hero(Hero hero) {
+        this.hero = hero;
+        return this;
+      }
+
+      public Data build() {
+        return new Data(hero);
+      }
+    }
   }
 
   public static class Hero {
@@ -268,5 +307,55 @@ public class TestQuery implements Query<TestQuery.Data> {
       }
       return $toString;
     }
+
+    public Builder toBuilder() {
+      Builder builder = new Builder();
+      builder.__typename = __typename;
+      builder.name = name;
+      builder.appearsIn = appearsIn;
+      builder.heroDetails = heroDetails;
+      return builder;
+    }
+
+    public static Builder builder() {
+      return new Builder();
+    }
+
+    public static final class Builder {
+      private String __typename;
+
+      private String name;
+
+      private List<Episode> appearsIn;
+
+      private HeroDetails heroDetails;
+
+      Builder() {
+      }
+
+      public Builder __typename(String __typename) {
+        this.__typename = __typename;
+        return this;
+      }
+
+      public Builder name(String name) {
+        this.name = name;
+        return this;
+      }
+
+      public Builder appearsIn(List<Episode> appearsIn) {
+        this.appearsIn = appearsIn;
+        return this;
+      }
+
+      public Builder heroDetails(HeroDetails heroDetails) {
+        this.heroDetails = heroDetails;
+        return this;
+      }
+
+      public Hero build() {
+        return new Hero(__typename, name, appearsIn, heroDetails);
+      }
+    }
   }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/DroidDetails.java.expected b/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/DroidDetails.java.expected
index 6f6da1d4d4..03abd14800 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/DroidDetails.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/DroidDetails.java.expected
@@ -69,4 +69,38 @@ public class DroidDetails implements Fragment.Data {
     }
     return $toString;
   }
+
+  public Builder toBuilder() {
+    Builder builder = new Builder();
+    builder.name = name;
+    builder.primaryFunction = primaryFunction;
+    return builder;
+  }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private String name;
+
+    private String primaryFunction;
+
+    Builder() {
+    }
+
+    public Builder name(String name) {
+      this.name = name;
+      return this;
+    }
+
+    public Builder primaryFunction(String primaryFunction) {
+      this.primaryFunction = primaryFunction;
+      return this;
+    }
+
+    public DroidDetails build() {
+      return new DroidDetails(name, primaryFunction);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/HeroDetails.java.expected b/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/HeroDetails.java.expected
index 3085e41388..489bbfcb5f 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/HeroDetails.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/HeroDetails.java.expected
@@ -100,6 +100,20 @@ public class HeroDetails implements Fragment.Data {
     return $toString;
   }
 
+  public Builder toBuilder() {
+    Builder builder = new Builder();
+    builder.__typename = __typename;
+    builder.name = name;
+    builder.friendsConnection = friendsConnection;
+    builder.onDroid = onDroid;
+    builder.humanDetails = humanDetails;
+    return builder;
+  }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
   public static class FriendsConnection {
     /**
      * The total number of friends
@@ -159,6 +173,40 @@ public class HeroDetails implements Fragment.Data {
       }
       return $toString;
     }
+
+    public Builder toBuilder() {
+      Builder builder = new Builder();
+      builder.totalCount = totalCount;
+      builder.edges = edges;
+      return builder;
+    }
+
+    public static Builder builder() {
+      return new Builder();
+    }
+
+    public static final class Builder {
+      private Integer totalCount;
+
+      private List<Edge> edges;
+
+      Builder() {
+      }
+
+      public Builder totalCount(Integer totalCount) {
+        this.totalCount = totalCount;
+        return this;
+      }
+
+      public Builder edges(List<Edge> edges) {
+        this.edges = edges;
+        return this;
+      }
+
+      public FriendsConnection build() {
+        return new FriendsConnection(totalCount, edges);
+      }
+    }
   }
 
   public static class OnDroid {
@@ -217,6 +265,40 @@ public class HeroDetails implements Fragment.Data {
       }
       return $toString;
     }
+
+    public Builder toBuilder() {
+      Builder builder = new Builder();
+      builder.__typename = __typename;
+      builder.droidDetails = droidDetails;
+      return builder;
+    }
+
+    public static Builder builder() {
+      return new Builder();
+    }
+
+    public static final class Builder {
+      private String __typename;
+
+      private DroidDetails droidDetails;
+
+      Builder() {
+      }
+
+      public Builder __typename(String __typename) {
+        this.__typename = __typename;
+        return this;
+      }
+
+      public Builder droidDetails(DroidDetails droidDetails) {
+        this.droidDetails = droidDetails;
+        return this;
+      }
+
+      public OnDroid build() {
+        return new OnDroid(__typename, droidDetails);
+      }
+    }
   }
 
   public static class Edge {
@@ -268,6 +350,32 @@ public class HeroDetails implements Fragment.Data {
       }
       return $toString;
     }
+
+    public Builder toBuilder() {
+      Builder builder = new Builder();
+      builder.node = node;
+      return builder;
+    }
+
+    public static Builder builder() {
+      return new Builder();
+    }
+
+    public static final class Builder {
+      private Node node;
+
+      Builder() {
+      }
+
+      public Builder node(Node node) {
+        this.node = node;
+        return this;
+      }
+
+      public Edge build() {
+        return new Edge(node);
+      }
+    }
   }
 
   public static class Node {
@@ -319,5 +427,75 @@ public class HeroDetails implements Fragment.Data {
       }
       return $toString;
     }
+
+    public Builder toBuilder() {
+      Builder builder = new Builder();
+      builder.name = name;
+      return builder;
+    }
+
+    public static Builder builder() {
+      return new Builder();
+    }
+
+    public static final class Builder {
+      private String name;
+
+      Builder() {
+      }
+
+      public Builder name(String name) {
+        this.name = name;
+        return this;
+      }
+
+      public Node build() {
+        return new Node(name);
+      }
+    }
+  }
+
+  public static final class Builder {
+    private String __typename;
+
+    private String name;
+
+    private FriendsConnection friendsConnection;
+
+    private OnDroid onDroid;
+
+    private HumanDetails humanDetails;
+
+    Builder() {
+    }
+
+    public Builder __typename(String __typename) {
+      this.__typename = __typename;
+      return this;
+    }
+
+    public Builder name(String name) {
+      this.name = name;
+      return this;
+    }
+
+    public Builder friendsConnection(FriendsConnection friendsConnection) {
+      this.friendsConnection = friendsConnection;
+      return this;
+    }
+
+    public Builder onDroid(OnDroid onDroid) {
+      this.onDroid = onDroid;
+      return this;
+    }
+
+    public Builder humanDetails(HumanDetails humanDetails) {
+      this.humanDetails = humanDetails;
+      return this;
+    }
+
+    public HeroDetails build() {
+      return new HeroDetails(__typename, name, friendsConnection, onDroid, humanDetails);
+    }
   }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/HumanDetails.java.expected b/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/HumanDetails.java.expected
index 1995474871..5aa7117a05 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/HumanDetails.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/fragment/HumanDetails.java.expected
@@ -59,4 +59,30 @@ public class HumanDetails implements Fragment.Data {
     }
     return $toString;
   }
+
+  public Builder toBuilder() {
+    Builder builder = new Builder();
+    builder.name = name;
+    return builder;
+  }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private String name;
+
+    Builder() {
+    }
+
+    public Builder name(String name) {
+      this.name = name;
+      return this;
+    }
+
+    public HumanDetails build() {
+      return new HumanDetails(name);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/java/operationBased/fragment_with_multiple_fieldsets/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/java/operationBased/fragment_with_multiple_fieldsets/TestQuery.java.expected
index 1e60e5476e..04acbb4e7a 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/java/operationBased/fragment_with_multiple_fieldsets/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragment_with_multiple_fieldsets/java/operationBased/fragment_with_multiple_fieldsets/TestQuery.java.expected
@@ -84,6 +84,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -120,6 +124,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public I i;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_same_type_condition/java/operationBased/fragments_same_type_condition/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_same_type_condition/java/operationBased/fragments_same_type_condition/TestQuery.java.expected
index ac8b2a915d..f6ca5f143b 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_same_type_condition/java/operationBased/fragments_same_type_condition/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_same_type_condition/java/operationBased/fragments_same_type_condition/TestQuery.java.expected
@@ -87,6 +87,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -123,6 +127,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDefer.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDefer.java.expected
index 7aaae05a22..5406027c21 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDefer.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDefer.java.expected
@@ -81,6 +81,10 @@ public class InlineMultipleWithDefer implements Query<InlineMultipleWithDefer.Da
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -117,6 +121,15 @@ public class InlineMultipleWithDefer implements Query<InlineMultipleWithDefer.Da
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public InlineMultipleWithDefer build() {
+      return new InlineMultipleWithDefer();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDeferAndInclude.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDeferAndInclude.java.expected
index deca3a7a67..4238aa12e5 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDeferAndInclude.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDeferAndInclude.java.expected
@@ -123,6 +123,10 @@ public class InlineMultipleWithDeferAndInclude implements Query<InlineMultipleWi
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -159,6 +163,43 @@ public class InlineMultipleWithDeferAndInclude implements Query<InlineMultipleWi
     .build();
   }
 
+  public static final class Builder {
+    private Boolean cond1;
+
+    private Boolean cond2;
+
+    private Boolean cond3;
+
+    private Boolean cond4;
+
+    Builder() {
+    }
+
+    public Builder cond1(Boolean cond1) {
+      this.cond1 = cond1;
+      return this;
+    }
+
+    public Builder cond2(Boolean cond2) {
+      this.cond2 = cond2;
+      return this;
+    }
+
+    public Builder cond3(Boolean cond3) {
+      this.cond3 = cond3;
+      return this;
+    }
+
+    public Builder cond4(Boolean cond4) {
+      this.cond4 = cond4;
+      return this;
+    }
+
+    public InlineMultipleWithDeferAndInclude build() {
+      return new InlineMultipleWithDeferAndInclude(cond1, cond2, cond3, cond4);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDeferWithIf.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDeferWithIf.java.expected
index 76748030c9..91e38d8745 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDeferWithIf.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineMultipleWithDeferWithIf.java.expected
@@ -92,6 +92,10 @@ public class InlineMultipleWithDeferWithIf implements Query<InlineMultipleWithDe
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -128,6 +132,22 @@ public class InlineMultipleWithDeferWithIf implements Query<InlineMultipleWithDe
     .build();
   }
 
+  public static final class Builder {
+    private Boolean cond;
+
+    Builder() {
+    }
+
+    public Builder cond(Boolean cond) {
+      this.cond = cond;
+      return this;
+    }
+
+    public InlineMultipleWithDeferWithIf build() {
+      return new InlineMultipleWithDeferWithIf(cond);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineSingleWithDefer.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineSingleWithDefer.java.expected
index 59ebfd4837..c250a12f76 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineSingleWithDefer.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/InlineSingleWithDefer.java.expected
@@ -78,6 +78,10 @@ public class InlineSingleWithDefer implements Query<InlineSingleWithDefer.Data>
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -114,6 +118,15 @@ public class InlineSingleWithDefer implements Query<InlineSingleWithDefer.Data>
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public InlineSingleWithDefer build() {
+      return new InlineSingleWithDefer();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDefer.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDefer.java.expected
index efa69b0ab6..04e43b1d85 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDefer.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDefer.java.expected
@@ -82,6 +82,10 @@ public class SpreadMultipleWithDefer implements Query<SpreadMultipleWithDefer.Da
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -118,6 +122,15 @@ public class SpreadMultipleWithDefer implements Query<SpreadMultipleWithDefer.Da
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public SpreadMultipleWithDefer build() {
+      return new SpreadMultipleWithDefer();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDeferAndInclude.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDeferAndInclude.java.expected
index 5c49d67940..c0ed6fb2b2 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDeferAndInclude.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDeferAndInclude.java.expected
@@ -116,6 +116,10 @@ public class SpreadMultipleWithDeferAndInclude implements Query<SpreadMultipleWi
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -152,6 +156,43 @@ public class SpreadMultipleWithDeferAndInclude implements Query<SpreadMultipleWi
     .build();
   }
 
+  public static final class Builder {
+    private Boolean cond1;
+
+    private Boolean cond2;
+
+    private Boolean cond3;
+
+    private Boolean cond4;
+
+    Builder() {
+    }
+
+    public Builder cond1(Boolean cond1) {
+      this.cond1 = cond1;
+      return this;
+    }
+
+    public Builder cond2(Boolean cond2) {
+      this.cond2 = cond2;
+      return this;
+    }
+
+    public Builder cond3(Boolean cond3) {
+      this.cond3 = cond3;
+      return this;
+    }
+
+    public Builder cond4(Boolean cond4) {
+      this.cond4 = cond4;
+      return this;
+    }
+
+    public SpreadMultipleWithDeferAndInclude build() {
+      return new SpreadMultipleWithDeferAndInclude(cond1, cond2, cond3, cond4);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDeferWithIf.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDeferWithIf.java.expected
index c410e366e3..01a8d0d1d8 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDeferWithIf.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadMultipleWithDeferWithIf.java.expected
@@ -101,6 +101,10 @@ public class SpreadMultipleWithDeferWithIf implements Query<SpreadMultipleWithDe
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -137,6 +141,22 @@ public class SpreadMultipleWithDeferWithIf implements Query<SpreadMultipleWithDe
     .build();
   }
 
+  public static final class Builder {
+    private Boolean cond;
+
+    Builder() {
+    }
+
+    public Builder cond(Boolean cond) {
+      this.cond = cond;
+      return this;
+    }
+
+    public SpreadMultipleWithDeferWithIf build() {
+      return new SpreadMultipleWithDeferWithIf(cond);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadSingleWithDefer.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadSingleWithDefer.java.expected
index eea1e28ee9..41b8ac425a 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadSingleWithDefer.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_defer_and_include_directives/java/operationBased/fragments_with_defer_and_include_directives/SpreadSingleWithDefer.java.expected
@@ -81,6 +81,10 @@ public class SpreadSingleWithDefer implements Query<SpreadSingleWithDefer.Data>
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -117,6 +121,15 @@ public class SpreadSingleWithDefer implements Query<SpreadSingleWithDefer.Data>
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public SpreadSingleWithDefer build() {
+      return new SpreadSingleWithDefer();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/fragments_with_type_condition/java/operationBased/fragments_with_type_condition/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/fragments_with_type_condition/java/operationBased/fragments_with_type_condition/TestQuery.java.expected
index 06872c4e66..7d9f07beec 100644
--- a/apollo-compiler/src/test/graphql/com/example/fragments_with_type_condition/java/operationBased/fragments_with_type_condition/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/fragments_with_type_condition/java/operationBased/fragments_with_type_condition/TestQuery.java.expected
@@ -94,6 +94,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -130,6 +134,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public R2 r2;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/hero_details/java/operationBased/hero_details/HeroDetails.java.expected b/apollo-compiler/src/test/graphql/com/example/hero_details/java/operationBased/hero_details/HeroDetails.java.expected
index c835d33d35..804ea1ba23 100644
--- a/apollo-compiler/src/test/graphql/com/example/hero_details/java/operationBased/hero_details/HeroDetails.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/hero_details/java/operationBased/hero_details/HeroDetails.java.expected
@@ -87,6 +87,10 @@ public class HeroDetails implements Query<HeroDetails.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -123,6 +127,15 @@ public class HeroDetails implements Query<HeroDetails.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public HeroDetails build() {
+      return new HeroDetails();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/hero_details_semantic_naming/java/operationBased/hero_details_semantic_naming/HeroDetailsQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/hero_details_semantic_naming/java/operationBased/hero_details_semantic_naming/HeroDetailsQuery.java.expected
index de030b6492..1952e63082 100644
--- a/apollo-compiler/src/test/graphql/com/example/hero_details_semantic_naming/java/operationBased/hero_details_semantic_naming/HeroDetailsQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/hero_details_semantic_naming/java/operationBased/hero_details_semantic_naming/HeroDetailsQuery.java.expected
@@ -85,6 +85,10 @@ public class HeroDetailsQuery implements Query<HeroDetailsQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -121,6 +125,15 @@ public class HeroDetailsQuery implements Query<HeroDetailsQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public HeroDetailsQuery build() {
+      return new HeroDetailsQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/hero_name/java/operationBased/hero_name/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/hero_name/java/operationBased/hero_name/TestQuery.java.expected
index 564f345bb6..0726eba87d 100644
--- a/apollo-compiler/src/test/graphql/com/example/hero_name/java/operationBased/hero_name/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/hero_name/java/operationBased/hero_name/TestQuery.java.expected
@@ -80,6 +80,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -116,6 +120,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/java/operationBased/hero_name_query_long_name/TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName.java.expected b/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/java/operationBased/hero_name_query_long_name/TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName.java.expected
index 938ea63003..446a5207de 100644
--- a/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/java/operationBased/hero_name_query_long_name/TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/java/operationBased/hero_name_query_long_name/TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName.java.expected
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 public class TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName implements Query<TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName.Data> {
   public static final String OPERATION_ID = "164dc148c38451cf968e075d4fd3114b0e03f4e5d8e126be67cf7156ef4cda9c";
@@ -85,6 +86,10 @@ public class TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVer
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -121,6 +126,24 @@ public class TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVer
     .build();
   }
 
+  public static final class Builder {
+    private Optional<Episode> episodeAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName;
+
+    Builder() {
+    }
+
+    public Builder episodeAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName(
+        @Nullable Episode episodeAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName) {
+      this.episodeAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName = Optional.presentIfNotNull(episodeAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName);
+      return this;
+    }
+
+    public TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName build(
+        ) {
+      return new TestQueryWithAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName(episodeAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryAVeryLongName);
+    }
+  }
+
   public static class Data implements Query.Data {
     public HeroAVeryAVeryAVeryAVeryAVeryAVeryAV heroAVeryAVeryAVeryAVeryAVeryAVeryAV;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/hero_with_review/java/operationBased/hero_with_review/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/hero_with_review/java/operationBased/hero_with_review/TestQuery.java.expected
index 0ce90868cc..f65efc09b7 100644
--- a/apollo-compiler/src/test/graphql/com/example/hero_with_review/java/operationBased/hero_with_review/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/hero_with_review/java/operationBased/hero_with_review/TestQuery.java.expected
@@ -95,6 +95,10 @@ public class TestQuery implements Mutation<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -131,6 +135,22 @@ public class TestQuery implements Mutation<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Episode ep;
+
+    Builder() {
+    }
+
+    public Builder ep(Episode ep) {
+      this.ep = ep;
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(ep);
+    }
+  }
+
   public static class Data implements Mutation.Data {
     public CreateReview createReview;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/java/operationBased/inline_fragment_for_non_optional_field/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/java/operationBased/inline_fragment_for_non_optional_field/TestQuery.java.expected
index d0d79a9ff7..7f4d9b5be1 100644
--- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/java/operationBased/inline_fragment_for_non_optional_field/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_for_non_optional_field/java/operationBased/inline_fragment_for_non_optional_field/TestQuery.java.expected
@@ -80,6 +80,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -116,6 +120,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public NonOptionalHero nonOptionalHero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/java/operationBased/inline_fragment_inside_inline_fragment/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/java/operationBased/inline_fragment_inside_inline_fragment/TestQuery.java.expected
index 83374ad352..0fbf6a3617 100644
--- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/java/operationBased/inline_fragment_inside_inline_fragment/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_inside_inline_fragment/java/operationBased/inline_fragment_inside_inline_fragment/TestQuery.java.expected
@@ -86,6 +86,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -122,6 +126,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public List<Search> search;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/java/operationBased/inline_fragment_intersection/TestOperation.java.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/java/operationBased/inline_fragment_intersection/TestOperation.java.expected
index 7f9edfd6e4..48061e3fce 100644
--- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/java/operationBased/inline_fragment_intersection/TestOperation.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/java/operationBased/inline_fragment_intersection/TestOperation.java.expected
@@ -114,6 +114,10 @@ public class TestOperation implements Query<TestOperation.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -150,6 +154,15 @@ public class TestOperation implements Query<TestOperation.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestOperation build() {
+      return new TestOperation();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Random random;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_merge_fields/java/operationBased/inline_fragment_merge_fields/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_merge_fields/java/operationBased/inline_fragment_merge_fields/TestQuery.java.expected
index be3f828a1b..d010756bf8 100644
--- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_merge_fields/java/operationBased/inline_fragment_merge_fields/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_merge_fields/java/operationBased/inline_fragment_merge_fields/TestQuery.java.expected
@@ -95,6 +95,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -131,6 +135,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_simple/java/operationBased/inline_fragment_simple/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_simple/java/operationBased/inline_fragment_simple/TestQuery.java.expected
index 134bc5bd62..ff875777e6 100644
--- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_simple/java/operationBased/inline_fragment_simple/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_simple/java/operationBased/inline_fragment_simple/TestQuery.java.expected
@@ -79,6 +79,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -115,6 +119,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/java/operationBased/inline_fragment_type_coercion/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/java/operationBased/inline_fragment_type_coercion/TestQuery.java.expected
index 792bcb21bd..3f843b0287 100644
--- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/java/operationBased/inline_fragment_type_coercion/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_type_coercion/java/operationBased/inline_fragment_type_coercion/TestQuery.java.expected
@@ -79,6 +79,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -115,6 +119,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     /**
      * For testing fragment type coercion
diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/java/operationBased/inline_fragment_with_include_directive/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/java/operationBased/inline_fragment_with_include_directive/TestQuery.java.expected
index 6bd8a1908b..34794896ba 100644
--- a/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/java/operationBased/inline_fragment_with_include_directive/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/inline_fragment_with_include_directive/java/operationBased/inline_fragment_with_include_directive/TestQuery.java.expected
@@ -102,6 +102,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -138,6 +142,29 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Boolean withDetails;
+
+    private Boolean skipHumanDetails;
+
+    Builder() {
+    }
+
+    public Builder withDetails(Boolean withDetails) {
+      this.withDetails = withDetails;
+      return this;
+    }
+
+    public Builder skipHumanDetails(Boolean skipHumanDetails) {
+      this.skipHumanDetails = skipHumanDetails;
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(withDetails, skipHumanDetails);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/java/operationBased/inline_fragments_with_friends/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/java/operationBased/inline_fragments_with_friends/TestQuery.java.expected
index 4ccc79fefb..8b139dd32c 100644
--- a/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/java/operationBased/inline_fragments_with_friends/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/java/operationBased/inline_fragments_with_friends/TestQuery.java.expected
@@ -91,6 +91,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -127,6 +131,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/TestQuery.java.expected
index 602624cd58..37249e7d1c 100644
--- a/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/TestQuery.java.expected
@@ -93,6 +93,10 @@ public class TestQuery implements Mutation<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -129,6 +133,29 @@ public class TestQuery implements Mutation<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Episode ep;
+
+    private ReviewInput review;
+
+    Builder() {
+    }
+
+    public Builder ep(Episode ep) {
+      this.ep = ep;
+      return this;
+    }
+
+    public Builder review(ReviewInput review) {
+      this.review = review;
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(ep, review);
+    }
+  }
+
   public static class Data implements Mutation.Data {
     public CreateReview createReview;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ColorInput.java.expected b/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ColorInput.java.expected
index 322fd2e889..7113b5b591 100644
--- a/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ColorInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ColorInput.java.expected
@@ -11,6 +11,7 @@ import java.lang.Integer;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * The input object sent when passing in a color
@@ -90,4 +91,67 @@ public class ColorInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<Integer> red;
+
+    private Optional<Double> green;
+
+    private Optional<Double> blue;
+
+    private Optional<Episode> enumWithDefaultValue;
+
+    private Optional<ReviewRefInput> reviewRefInput;
+
+    Builder() {
+    }
+
+    /**
+     * Red color
+     */
+    public Builder red(@Nullable Integer red) {
+      this.red = Optional.presentIfNotNull(red);
+      return this;
+    }
+
+    /**
+     * Green color
+     */
+    public Builder green(@Nullable Double green) {
+      this.green = Optional.presentIfNotNull(green);
+      return this;
+    }
+
+    /**
+     * Blue color
+     */
+    public Builder blue(@Nullable Double blue) {
+      this.blue = Optional.presentIfNotNull(blue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder enumWithDefaultValue(@Nullable Episode enumWithDefaultValue) {
+      this.enumWithDefaultValue = Optional.presentIfNotNull(enumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * Circle ref to review input
+     */
+    public Builder reviewRefInput(@Nullable ReviewRefInput reviewRefInput) {
+      this.reviewRefInput = Optional.presentIfNotNull(reviewRefInput);
+      return this;
+    }
+
+    public ColorInput build() {
+      return new ColorInput(red, green, blue, enumWithDefaultValue, reviewRefInput);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ReviewInput.java.expected b/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ReviewInput.java.expected
index 8f61372809..9b482cc20f 100644
--- a/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ReviewInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ReviewInput.java.expected
@@ -13,6 +13,7 @@ import java.lang.Override;
 import java.lang.String;
 import java.util.Date;
 import java.util.List;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * The input object sent when someone is creating a new review
@@ -220,4 +221,239 @@ public class ReviewInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Integer stars;
+
+    private Optional<Integer> nullableIntFieldWithDefaultValue;
+
+    private Optional<String> commentary;
+
+    private ColorInput favoriteColor;
+
+    private Optional<Episode> enumWithDefaultValue;
+
+    private Optional<Episode> nonNullableEnumWithDefaultValue;
+
+    private Optional<Episode> nullableEnum;
+
+    private Optional<List<Date>> listOfCustomScalar;
+
+    private Optional<Date> customScalar;
+
+    private Optional<List<Episode>> listOfEnums;
+
+    private Optional<List<Integer>> listOfInt;
+
+    private Optional<List<String>> listOfString;
+
+    private List<String> listOfStringNonOptional;
+
+    private Optional<List<ColorInput>> listOfInputTypes;
+
+    private Optional<Boolean> booleanWithDefaultValue;
+
+    private Optional<Boolean> booleanNonOptional;
+
+    private Optional<List<List<String>>> listOfListOfString;
+
+    private Optional<List<List<Episode>>> listOfListOfEnum;
+
+    private Optional<List<List<Date>>> listOfListOfCustom;
+
+    private Optional<List<List<ColorInput>>> listOfListOfObject;
+
+    private Optional<String> CapitalizedField;
+
+    private Optional<Integer> CapitalizedInt;
+
+    Builder() {
+    }
+
+    /**
+     * 0-5 stars
+     */
+    public Builder stars(Integer stars) {
+      this.stars = stars;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nullableIntFieldWithDefaultValue(
+        @Nullable Integer nullableIntFieldWithDefaultValue) {
+      this.nullableIntFieldWithDefaultValue = Optional.presentIfNotNull(nullableIntFieldWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * Comment about the movie, optional
+     */
+    public Builder commentary(@Nullable String commentary) {
+      this.commentary = Optional.presentIfNotNull(commentary);
+      return this;
+    }
+
+    /**
+     * Favorite color, optional
+     */
+    public Builder favoriteColor(ColorInput favoriteColor) {
+      this.favoriteColor = favoriteColor;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder enumWithDefaultValue(@Nullable Episode enumWithDefaultValue) {
+      this.enumWithDefaultValue = Optional.presentIfNotNull(enumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nonNullableEnumWithDefaultValue(
+        @Nullable Episode nonNullableEnumWithDefaultValue) {
+      this.nonNullableEnumWithDefaultValue = Optional.presentIfNotNull(nonNullableEnumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nullableEnum(@Nullable Episode nullableEnum) {
+      this.nullableEnum = Optional.presentIfNotNull(nullableEnum);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfCustomScalar(@Nullable List<Date> listOfCustomScalar) {
+      this.listOfCustomScalar = Optional.presentIfNotNull(listOfCustomScalar);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder customScalar(@Nullable Date customScalar) {
+      this.customScalar = Optional.presentIfNotNull(customScalar);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfEnums(@Nullable List<Episode> listOfEnums) {
+      this.listOfEnums = Optional.presentIfNotNull(listOfEnums);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfInt(@Nullable List<Integer> listOfInt) {
+      this.listOfInt = Optional.presentIfNotNull(listOfInt);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfString(@Nullable List<String> listOfString) {
+      this.listOfString = Optional.presentIfNotNull(listOfString);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfStringNonOptional(List<String> listOfStringNonOptional) {
+      this.listOfStringNonOptional = listOfStringNonOptional;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfInputTypes(@Nullable List<ColorInput> listOfInputTypes) {
+      this.listOfInputTypes = Optional.presentIfNotNull(listOfInputTypes);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder booleanWithDefaultValue(@Nullable Boolean booleanWithDefaultValue) {
+      this.booleanWithDefaultValue = Optional.presentIfNotNull(booleanWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder booleanNonOptional(@Nullable Boolean booleanNonOptional) {
+      this.booleanNonOptional = Optional.presentIfNotNull(booleanNonOptional);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfString(@Nullable List<List<String>> listOfListOfString) {
+      this.listOfListOfString = Optional.presentIfNotNull(listOfListOfString);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfEnum(@Nullable List<List<Episode>> listOfListOfEnum) {
+      this.listOfListOfEnum = Optional.presentIfNotNull(listOfListOfEnum);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfCustom(@Nullable List<List<Date>> listOfListOfCustom) {
+      this.listOfListOfCustom = Optional.presentIfNotNull(listOfListOfCustom);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfObject(@Nullable List<List<ColorInput>> listOfListOfObject) {
+      this.listOfListOfObject = Optional.presentIfNotNull(listOfListOfObject);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder CapitalizedField(@Nullable String CapitalizedField) {
+      this.CapitalizedField = Optional.presentIfNotNull(CapitalizedField);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder CapitalizedInt(@Nullable Integer CapitalizedInt) {
+      this.CapitalizedInt = Optional.presentIfNotNull(CapitalizedInt);
+      return this;
+    }
+
+    public ReviewInput build() {
+      return new ReviewInput(stars, nullableIntFieldWithDefaultValue, commentary, favoriteColor, enumWithDefaultValue, nonNullableEnumWithDefaultValue, nullableEnum, listOfCustomScalar, customScalar, listOfEnums, listOfInt, listOfString, listOfStringNonOptional, listOfInputTypes, booleanWithDefaultValue, booleanNonOptional, listOfListOfString, listOfListOfEnum, listOfListOfCustom, listOfListOfObject, CapitalizedField, CapitalizedInt);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ReviewRefInput.java.expected b/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ReviewRefInput.java.expected
index 3301e915ac..60f04a508d 100644
--- a/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ReviewRefInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ReviewRefInput.java.expected
@@ -9,6 +9,7 @@ import com.apollographql.apollo3.api.Optional;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Circle ref to review input
@@ -59,4 +60,24 @@ public class ReviewRefInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<ReviewInput> reviewInput;
+
+    Builder() {
+    }
+
+    public Builder reviewInput(@Nullable ReviewInput reviewInput) {
+      this.reviewInput = Optional.presentIfNotNull(reviewInput);
+      return this;
+    }
+
+    public ReviewRefInput build() {
+      return new ReviewRefInput(reviewInput);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/java/operationBased/input_object_variable_and_argument/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/java/operationBased/input_object_variable_and_argument/TestQuery.java.expected
index fbfdc63bc9..a62f292bcb 100644
--- a/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/java/operationBased/input_object_variable_and_argument/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/java/operationBased/input_object_variable_and_argument/TestQuery.java.expected
@@ -22,6 +22,7 @@ import java.lang.Integer;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 public class TestQuery implements Query<TestQuery.Data> {
   public static final String OPERATION_ID = "5de0170d60b7008300fa40599880d0b70e67a326a7b1fe27b8fa87aba7e5d36f";
@@ -112,6 +113,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -148,6 +153,36 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Optional<Episode> episode;
+
+    private Integer stars;
+
+    private Double greenValue;
+
+    Builder() {
+    }
+
+    public Builder episode(@Nullable Episode episode) {
+      this.episode = Optional.presentIfNotNull(episode);
+      return this;
+    }
+
+    public Builder stars(Integer stars) {
+      this.stars = stars;
+      return this;
+    }
+
+    public Builder greenValue(Double greenValue) {
+      this.greenValue = greenValue;
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(episode, stars, greenValue);
+    }
+  }
+
   public static class Data implements Query.Data {
     public HeroWithReview heroWithReview;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/interface_always_nested/java/operationBased/interface_always_nested/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/interface_always_nested/java/operationBased/interface_always_nested/TestQuery.java.expected
index e2b8b85664..93d1a532e1 100644
--- a/apollo-compiler/src/test/graphql/com/example/interface_always_nested/java/operationBased/interface_always_nested/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/interface_always_nested/java/operationBased/interface_always_nested/TestQuery.java.expected
@@ -82,6 +82,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -118,6 +122,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Root root;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/interface_on_interface/java/operationBased/interface_on_interface/GetHuman.java.expected b/apollo-compiler/src/test/graphql/com/example/interface_on_interface/java/operationBased/interface_on_interface/GetHuman.java.expected
index 9f34587ced..3759352a59 100644
--- a/apollo-compiler/src/test/graphql/com/example/interface_on_interface/java/operationBased/interface_on_interface/GetHuman.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/interface_on_interface/java/operationBased/interface_on_interface/GetHuman.java.expected
@@ -84,6 +84,10 @@ public class GetHuman implements Query<GetHuman.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -120,6 +124,15 @@ public class GetHuman implements Query<GetHuman.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public GetHuman build() {
+      return new GetHuman();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Human human;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/introspection_query/java/operationBased/introspection_query/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/introspection_query/java/operationBased/introspection_query/TestQuery.java.expected
index 29f39f9e44..59f19a7541 100644
--- a/apollo-compiler/src/test/graphql/com/example/introspection_query/java/operationBased/introspection_query/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/introspection_query/java/operationBased/introspection_query/TestQuery.java.expected
@@ -84,6 +84,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -120,6 +124,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public __Schema __schema;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/java8annotation/java/operationBased/java8annotation/LoginBarber.java.expected b/apollo-compiler/src/test/graphql/com/example/java8annotation/java/operationBased/java8annotation/LoginBarber.java.expected
index 7ef2cc4e70..b5d57fe32e 100644
--- a/apollo-compiler/src/test/graphql/com/example/java8annotation/java/operationBased/java8annotation/LoginBarber.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/java8annotation/java/operationBased/java8annotation/LoginBarber.java.expected
@@ -82,6 +82,10 @@ public class LoginBarber implements Mutation<LoginBarber.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -118,6 +122,22 @@ public class LoginBarber implements Mutation<LoginBarber.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private com.example.java8annotation.type.Login input;
+
+    Builder() {
+    }
+
+    public Builder input(com.example.java8annotation.type.Login input) {
+      this.input = input;
+      return this;
+    }
+
+    public LoginBarber build() {
+      return new LoginBarber(input);
+    }
+  }
+
   public static class Data implements Mutation.Data {
     public Login login;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/java8annotation/java/operationBased/java8annotation/type/Login.java.expected b/apollo-compiler/src/test/graphql/com/example/java8annotation/java/operationBased/java8annotation/type/Login.java.expected
index 6368e4550a..217907e3c5 100644
--- a/apollo-compiler/src/test/graphql/com/example/java8annotation/java/operationBased/java8annotation/type/Login.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/java8annotation/java/operationBased/java8annotation/type/Login.java.expected
@@ -55,4 +55,24 @@ public class Login {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private String email;
+
+    Builder() {
+    }
+
+    public Builder email(String email) {
+      this.email = email;
+      return this;
+    }
+
+    public Login build() {
+      return new Login(email);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/measurements b/apollo-compiler/src/test/graphql/com/example/measurements
index 86f64abfee..b393148873 100644
--- a/apollo-compiler/src/test/graphql/com/example/measurements
+++ b/apollo-compiler/src/test/graphql/com/example/measurements
@@ -2,232 +2,232 @@
 // If you updated the codegen and test fixtures, you should commit this file too.
 
 Test:                                                                                      Total LOC:
-aggregate-all                                                                                  195000
+aggregate-all                                                                                  198020
 aggregate-kotlin-responseBased                                                                  50302
-aggregate-kotlin-operationBased                                                                 35446
-aggregate-kotlin-compat                                                                         36831
-aggregate-java-operationBased                                                                   72421
+aggregate-kotlin-operationBased                                                                 35445
+aggregate-kotlin-compat                                                                         36830
+aggregate-java-operationBased                                                                   75443
 
-java-operationBased-fragments_with_defer_and_include_directives                                  5392
-kotlin-compat-fragments_with_defer_and_include_directives                                        3613
-kotlin-operationBased-fragments_with_defer_and_include_directives                                3420
+java-operationBased-fragments_with_defer_and_include_directives                                  5566
+kotlin-compat-fragments_with_defer_and_include_directives                                        3612
+kotlin-operationBased-fragments_with_defer_and_include_directives                                3419
 kotlin-responseBased-fragment_with_inline_fragment                                               2378
-java-operationBased-fragment_with_inline_fragment                                                1845
-java-operationBased-nested_named_fragments                                                       1844
-java-operationBased-union_inline_fragments                                                       1617
-java-operationBased-unique_type_name                                                             1598
+java-operationBased-fragment_with_inline_fragment                                                2172
+java-operationBased-nested_named_fragments                                                       1857
+java-operationBased-mutation_create_review                                                       1795
+java-operationBased-__schema                                                                     1703
+java-operationBased-union_inline_fragments                                                       1630
+java-operationBased-unique_type_name                                                             1611
+java-operationBased-input_object_type                                                            1606
+java-operationBased-inline_fragment_intersection                                                 1598
+java-operationBased-mutation_create_review_semantic_naming                                       1591
 kotlin-responseBased-nested_named_fragments                                                      1591
-java-operationBased-inline_fragment_intersection                                                 1585
-java-operationBased-root_query_fragment_with_nested_fragments                                    1548
+java-operationBased-root_query_fragment_with_nested_fragments                                    1561
 kotlin-compat-fragment_with_inline_fragment                                                      1486
-java-operationBased-mutation_create_review                                                       1447
-java-operationBased-named_fragment_delegate                                                      1445
-java-operationBased-__schema                                                                     1382
+java-operationBased-named_fragment_delegate                                                      1458
+java-operationBased-named_fragment_with_variables                                                1387
 kotlin-responseBased-named_fragment_delegate                                                     1339
-java-operationBased-named_fragment_with_variables                                                1325
 kotlin-responseBased-unique_type_name                                                            1323
 kotlin-compat-nested_named_fragments                                                             1310
-java-operationBased-nested_conditional_inline                                                    1283
-java-operationBased-fragment_used_twice                                                          1258
-java-operationBased-input_object_type                                                            1258
+java-operationBased-nested_conditional_inline                                                    1304
+java-operationBased-fragment_used_twice                                                          1271
+java-operationBased-multiple_fragments                                                           1260
+java-operationBased-nested_field_with_multiple_fieldsets                                         1254
 kotlin-operationBased-fragment_with_inline_fragment                                              1249
-java-operationBased-multiple_fragments                                                           1247
-java-operationBased-mutation_create_review_semantic_naming                                       1243
-java-operationBased-nested_field_with_multiple_fieldsets                                         1241
 kotlin-responseBased-root_query_fragment_with_nested_fragments                                   1230
 kotlin-operationBased-nested_named_fragments                                                     1225
-java-operationBased-two_heroes_with_friends                                                      1198
-java-operationBased-inline_fragment_merge_fields                                                 1195
+java-operationBased-two_heroes_with_friends                                                      1211
+java-operationBased-inline_fragment_merge_fields                                                 1208
 kotlin-responseBased-inline_fragment_intersection                                                1187
 kotlin-compat-inline_fragment_intersection                                                       1174
-java-operationBased-named_fragment_inside_inline_fragment                                        1144
-java-operationBased-fragments_with_type_condition                                                1139
+java-operationBased-named_fragment_inside_inline_fragment                                        1157
+java-operationBased-fragments_with_type_condition                                                1152
+java-operationBased-target_name                                                                  1142
 kotlin-compat-unique_type_name                                                                   1123
 kotlin-operationBased-inline_fragment_intersection                                               1111
 kotlin-operationBased-union_inline_fragments                                                     1111
 kotlin-responseBased-fragment_used_twice                                                         1108
 kotlin-responseBased-__schema                                                                    1107
 kotlin-responseBased-union_inline_fragments                                                      1100
-java-operationBased-target_name                                                                  1086
+java-operationBased-root_query_inline_fragment                                                   1092
 kotlin-operationBased-unique_type_name                                                           1080
-java-operationBased-root_query_inline_fragment                                                   1079
 kotlin-compat-root_query_fragment_with_nested_fragments                                          1073
 kotlin-compat-union_inline_fragments                                                             1069
 kotlin-responseBased-fragments_with_type_condition                                               1061
-java-operationBased-simple_fragment_with_inline_fragments                                        1031
+java-operationBased-simple_fragment_with_inline_fragments                                        1044
+java-operationBased-fragment_spread_with_include_directive                                       1035
+java-operationBased-inline_fragments_with_friends                                                1033
+java-operationBased-fragment_spread_with_nested_fields                                           1028
 kotlin-responseBased-multiple_fragments                                                          1028
 kotlin-responseBased-mutation_create_review                                                      1026
-java-operationBased-inline_fragments_with_friends                                                1020
 kotlin-operationBased-root_query_fragment_with_nested_fragments                                  1019
 kotlin-responseBased-simple_fragment_with_inline_fragments                                       1019
-java-operationBased-fragment_spread_with_nested_fields                                           1015
-java-operationBased-fragment_spread_with_include_directive                                       1008
 kotlin-responseBased-nested_conditional_inline                                                   1008
 kotlin-compat-named_fragment_delegate                                                            1007
 kotlin-responseBased-named_fragment_with_variables                                                999
+java-operationBased-simple_fragment                                                               996
 kotlin-operationBased-named_fragment_delegate                                                     983
-java-operationBased-simple_fragment                                                               983
 kotlin-compat-fragment_used_twice                                                                 956
 kotlin-compat-nested_conditional_inline                                                           948
-java-operationBased-fragments_same_type_condition                                                 933
-java-operationBased-simple_union                                                                  933
+java-operationBased-fragments_same_type_condition                                                 946
+java-operationBased-simple_union                                                                  946
+java-operationBased-deprecated_merged_field                                                       926
 kotlin-compat-named_fragment_with_variables                                                       919
-java-operationBased-deprecated_merged_field                                                       913
-java-operationBased-hero_details                                                                  905
-java-operationBased-not_all_combinations_are_needed                                               903
-java-operationBased-fieldset_with_multiple_super                                                  887
-java-operationBased-simple_inline_fragment                                                        887
+java-operationBased-hero_details                                                                  918
+java-operationBased-not_all_combinations_are_needed                                               916
+java-operationBased-inline_fragment_with_include_directive                                        905
+java-operationBased-fieldset_with_multiple_super                                                  900
+java-operationBased-simple_inline_fragment                                                        900
 kotlin-compat-multiple_fragments                                                                  883
 kotlin-responseBased-input_object_type                                                            882
 kotlin-operationBased-nested_conditional_inline                                                   882
-java-operationBased-inline_fragment_with_include_directive                                        878
 kotlin-responseBased-mutation_create_review_semantic_naming                                       866
 kotlin-compat-fragments_with_type_condition                                                       864
+java-operationBased-test_inline                                                                   864
 kotlin-operationBased-fragment_used_twice                                                         861
+java-operationBased-union_fragment                                                                861
 kotlin-operationBased-named_fragment_with_variables                                               858
 kotlin-responseBased-fragment_spread_with_nested_fields                                           854
-java-operationBased-test_inline                                                                   851
-java-operationBased-union_fragment                                                                848
-java-operationBased-inline_fragment_inside_inline_fragment                                        840
+java-operationBased-inline_fragment_inside_inline_fragment                                        853
 kotlin-responseBased-simple_fragment                                                              823
 kotlin-operationBased-multiple_fragments                                                          820
+java-operationBased-named_fragment_without_implementation                                         819
 kotlin-responseBased-nested_field_with_multiple_fieldsets                                         819
-java-operationBased-named_fragment_without_implementation                                         806
 kotlin-operationBased-fragments_with_type_condition                                               803
 kotlin-operationBased-nested_field_with_multiple_fieldsets                                        800
+java-operationBased-fragment_with_multiple_fieldsets                                              784
 kotlin-operationBased-inline_fragment_merge_fields                                                784
+java-operationBased-hero_details_semantic_naming                                                  782
 kotlin-responseBased-two_heroes_with_friends                                                      781
-java-operationBased-fragment_with_multiple_fieldsets                                              771
-java-operationBased-hero_details_semantic_naming                                                  769
 kotlin-operationBased-named_fragment_inside_inline_fragment                                       767
+java-operationBased-path_vs_flat_accessors                                                        761
 kotlin-compat-simple_fragment_with_inline_fragments                                               756
 kotlin-responseBased-inline_fragments_with_friends                                                755
 kotlin-responseBased-target_name                                                                  755
 kotlin-compat-named_fragment_inside_inline_fragment                                               753
 kotlin-operationBased-root_query_inline_fragment                                                  752
 kotlin-responseBased-deprecated_merged_field                                                      748
-java-operationBased-path_vs_flat_accessors                                                        748
 kotlin-compat-simple_fragment                                                                     747
 kotlin-responseBased-named_fragment_inside_inline_fragment                                        746
 kotlin-compat-inline_fragments_with_friends                                                       741
+java-operationBased-reserved_keywords                                                             740
 kotlin-compat-nested_field_with_multiple_fieldsets                                                739
 kotlin-compat-target_name                                                                         738
+java-operationBased-typename_always_first                                                         737
 kotlin-responseBased-simple_union                                                                 734
 kotlin-operationBased-target_name                                                                 731
-java-operationBased-reserved_keywords                                                             727
 kotlin-responseBased-root_query_inline_fragment                                                   726
 kotlin-compat-fragment_spread_with_include_directive                                              725
-java-operationBased-typename_always_first                                                         724
+java-operationBased-introspection_query                                                           715
+java-operationBased-interface_on_interface                                                        713
 kotlin-compat-fragment_spread_with_nested_fields                                                  709
 kotlin-operationBased-inline_fragments_with_friends                                               708
 kotlin-responseBased-fragments_same_type_condition                                                707
-java-operationBased-introspection_query                                                           702
-java-operationBased-interface_on_interface                                                        700
+java-operationBased-input_object_variable_and_argument                                            705
 kotlin-compat-root_query_inline_fragment                                                          700
+java-operationBased-root_query_fragment                                                           697
 kotlin-operationBased-simple_fragment_with_inline_fragments                                       695
 kotlin-operationBased-fragment_spread_with_include_directive                                      694
 kotlin-operationBased-simple_fragment                                                             685
-java-operationBased-root_query_fragment                                                           684
 kotlin-operationBased-fragment_spread_with_nested_fields                                          682
 kotlin-compat-fragments_same_type_condition                                                       673
-java-operationBased-input_object_variable_and_argument                                            670
+java-operationBased-monomorphic                                                                   670
 kotlin-compat-simple_union                                                                        670
+java-operationBased-interface_always_nested                                                       668
+java-operationBased-deprecation                                                                   667
 kotlin-compat-deprecated_merged_field                                                             662
-java-operationBased-monomorphic                                                                   657
 kotlin-compat-inline_fragment_with_include_directive                                              656
-java-operationBased-interface_always_nested                                                       655
 kotlin-compat-union_fragment                                                                      654
 kotlin-compat-not_all_combinations_are_needed                                                     653
+java-operationBased-capitalized_fields                                                            649
 kotlin-compat-inline_fragment_inside_inline_fragment                                              647
-java-operationBased-deprecation                                                                   646
+java-operationBased-recursive_selection                                                           646
+java-operationBased-hero_with_review                                                              645
 kotlin-operationBased-fragments_same_type_condition                                               642
 kotlin-operationBased-simple_union                                                                639
-java-operationBased-capitalized_fields                                                            636
 kotlin-responseBased-union_fragment                                                               636
 kotlin-responseBased-test_inline                                                                  634
-java-operationBased-recursive_selection                                                           633
 kotlin-compat-fieldset_with_multiple_super                                                        632
 kotlin-responseBased-fragment_with_multiple_fieldsets                                             629
+java-operationBased-field_with_include_directive                                                  628
+java-operationBased-hero_name_query_long_name                                                     628
 kotlin-compat-named_fragment_without_implementation                                               626
-java-operationBased-hero_with_review                                                              625
 kotlin-responseBased-named_fragment_without_implementation                                        622
+java-operationBased-variable_default_value                                                        620
 kotlin-operationBased-deprecated_merged_field                                                     619
 kotlin-responseBased-hero_details                                                                 615
 kotlin-operationBased-inline_fragment_inside_inline_fragment                                      615
 kotlin-operationBased-not_all_combinations_are_needed                                             615
+java-operationBased-custom_scalar_type                                                            614
 kotlin-operationBased-union_fragment                                                              612
+java-operationBased-hero_name                                                                     609
 kotlin-responseBased-inline_fragment_merge_fields                                                 609
 kotlin-compat-inline_fragment_merge_fields                                                        607
-java-operationBased-hero_name_query_long_name                                                     605
 kotlin-operationBased-inline_fragment_with_include_directive                                      605
 kotlin-operationBased-fieldset_with_multiple_super                                                604
 kotlin-responseBased-inline_fragment_inside_inline_fragment                                       602
-java-operationBased-custom_scalar_type                                                            601
-java-operationBased-field_with_include_directive                                                  601
-java-operationBased-variable_default_value                                                        599
 kotlin-operationBased-simple_inline_fragment                                                      598
-java-operationBased-hero_name                                                                     596
+java-operationBased-java8annotation                                                               595
 kotlin-operationBased-named_fragment_without_implementation                                       595
+java-operationBased-optional                                                                      588
 kotlin-compat-test_inline                                                                         588
 kotlin-responseBased-simple_inline_fragment                                                       586
 kotlin-responseBased-fieldset_with_multiple_super                                                 585
 kotlin-responseBased-not_all_combinations_are_needed                                              585
-java-operationBased-optional                                                                      575
+java-operationBased-inline_fragment_for_non_optional_field                                        578
+java-operationBased-inline_fragment_type_coercion                                                 572
 kotlin-compat-simple_inline_fragment                                                              568
-java-operationBased-inline_fragment_for_non_optional_field                                        565
+java-operationBased-two_heroes_unique                                                             567
 kotlin-operationBased-test_inline                                                                 565
 kotlin-responseBased-reserved_keywords                                                            563
 kotlin-compat-fragment_with_multiple_fieldsets                                                    561
-java-operationBased-inline_fragment_type_coercion                                                 559
-java-operationBased-java8annotation                                                               555
-java-operationBased-two_heroes_unique                                                             554
+java-operationBased-inline_fragment_simple                                                        556
 kotlin-compat-reserved_keywords                                                                   546
-java-operationBased-inline_fragment_simple                                                        543
 kotlin-operationBased-reserved_keywords                                                           539
 kotlin-responseBased-path_vs_flat_accessors                                                       536
 kotlin-responseBased-hero_details_semantic_naming                                                 529
+java-operationBased-starships                                                                     528
 kotlin-compat-path_vs_flat_accessors                                                              525
 kotlin-operationBased-fragment_with_multiple_fieldsets                                            524
 kotlin-responseBased-input_object_variable_and_argument                                           519
 kotlin-responseBased-root_query_fragment                                                          519
+java-operationBased-antlr_tokens                                                                  518
 kotlin-responseBased-typename_always_first                                                        516
 kotlin-responseBased-interface_on_interface                                                       513
+java-operationBased-subscriptions                                                                 512
 kotlin-operationBased-path_vs_flat_accessors                                                      511
 kotlin-operationBased-typename_always_first                                                       509
 kotlin-compat-typename_always_first                                                               509
-java-operationBased-starships                                                                     508
 kotlin-compat-root_query_fragment                                                                 501
-java-operationBased-antlr_tokens                                                                  497
 kotlin-compat-interface_on_interface                                                              497
-java-operationBased-subscriptions                                                                 492
 kotlin-responseBased-hero_name                                                                    490
 kotlin-operationBased-interface_on_interface                                                      490
+java-operationBased-arguments_hardcoded                                                           483
 kotlin-responseBased-hero_with_review                                                             483
 kotlin-responseBased-deprecation                                                                  481
 kotlin-responseBased-interface_always_nested                                                      481
 kotlin-responseBased-hero_name_query_long_name                                                    480
 kotlin-responseBased-custom_scalar_type                                                           474
 kotlin-compat-interface_always_nested                                                             472
-java-operationBased-arguments_hardcoded                                                           470
 kotlin-operationBased-root_query_fragment                                                         470
 kotlin-compat-hero_name                                                                           464
+java-operationBased-merged_include                                                                461
 kotlin-compat-monomorphic                                                                         461
+java-operationBased-operation_id_generator                                                        461
 kotlin-operationBased-interface_always_nested                                                     458
+java-operationBased-enum_field                                                                    456
 kotlin-operationBased-monomorphic                                                                 454
 kotlin-responseBased-introspection_query                                                          453
+java-operationBased-enums_as_sealed                                                               450
 kotlin-responseBased-monomorphic                                                                  450
-java-operationBased-merged_include                                                                448
-java-operationBased-operation_id_generator                                                        448
+java-operationBased-case_sensitive_enum                                                           447
 kotlin-responseBased-inline_fragment_for_non_optional_field                                       447
-java-operationBased-enum_field                                                                    443
 kotlin-responseBased-variable_default_value                                                       443
-java-operationBased-enums_as_sealed                                                               437
+java-operationBased-nonnull                                                                       442
 kotlin-operationBased-hero_name                                                                   436
 kotlin-operationBased-capitalized_fields                                                          435
-java-operationBased-case_sensitive_enum                                                           434
 kotlin-responseBased-field_with_include_directive                                                 431
 kotlin-responseBased-optional                                                                     431
-java-operationBased-nonnull                                                                       429
 kotlin-responseBased-inline_fragment_type_coercion                                                428
 kotlin-compat-inline_fragment_for_non_optional_field                                              424
 kotlin-responseBased-recursive_selection                                                          422
diff --git a/apollo-compiler/src/test/graphql/com/example/merged_include/java/operationBased/merged_include/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/merged_include/java/operationBased/merged_include/TestQuery.java.expected
index bc1d12baaa..2daf8ede21 100644
--- a/apollo-compiler/src/test/graphql/com/example/merged_include/java/operationBased/merged_include/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/merged_include/java/operationBased/merged_include/TestQuery.java.expected
@@ -78,6 +78,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -114,6 +118,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/monomorphic/java/operationBased/monomorphic/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/monomorphic/java/operationBased/monomorphic/TestQuery.java.expected
index a1ff74ed96..d9bfacc8ab 100644
--- a/apollo-compiler/src/test/graphql/com/example/monomorphic/java/operationBased/monomorphic/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/monomorphic/java/operationBased/monomorphic/TestQuery.java.expected
@@ -81,6 +81,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -117,6 +121,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Cat cat;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/multiple_fragments/java/operationBased/multiple_fragments/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/multiple_fragments/java/operationBased/multiple_fragments/TestQuery.java.expected
index 9025234517..fb2bc54fbc 100644
--- a/apollo-compiler/src/test/graphql/com/example/multiple_fragments/java/operationBased/multiple_fragments/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/multiple_fragments/java/operationBased/multiple_fragments/TestQuery.java.expected
@@ -93,6 +93,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -129,6 +133,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public A a;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/CreateReviewForEpisode.java.expected b/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/CreateReviewForEpisode.java.expected
index 7bdbe5faa9..a0ff2b4868 100644
--- a/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/CreateReviewForEpisode.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/CreateReviewForEpisode.java.expected
@@ -101,6 +101,10 @@ public class CreateReviewForEpisode implements Mutation<CreateReviewForEpisode.D
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -137,6 +141,29 @@ public class CreateReviewForEpisode implements Mutation<CreateReviewForEpisode.D
     .build();
   }
 
+  public static final class Builder {
+    private Episode ep;
+
+    private ReviewInput review;
+
+    Builder() {
+    }
+
+    public Builder ep(Episode ep) {
+      this.ep = ep;
+      return this;
+    }
+
+    public Builder review(ReviewInput review) {
+      this.review = review;
+      return this;
+    }
+
+    public CreateReviewForEpisode build() {
+      return new CreateReviewForEpisode(ep, review);
+    }
+  }
+
   public static class Data implements Mutation.Data {
     public CreateReview createReview;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ColorInput.java.expected b/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ColorInput.java.expected
index 2f34942987..400dd74a80 100644
--- a/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ColorInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ColorInput.java.expected
@@ -11,6 +11,7 @@ import java.lang.Integer;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * The input object sent when passing in a color
@@ -90,4 +91,67 @@ public class ColorInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<Integer> red;
+
+    private Optional<Double> green;
+
+    private Optional<Double> blue;
+
+    private Optional<Episode> enumWithDefaultValue;
+
+    private Optional<ReviewRefInput> reviewRefInput;
+
+    Builder() {
+    }
+
+    /**
+     * Red color
+     */
+    public Builder red(@Nullable Integer red) {
+      this.red = Optional.presentIfNotNull(red);
+      return this;
+    }
+
+    /**
+     * Green color
+     */
+    public Builder green(@Nullable Double green) {
+      this.green = Optional.presentIfNotNull(green);
+      return this;
+    }
+
+    /**
+     * Blue color
+     */
+    public Builder blue(@Nullable Double blue) {
+      this.blue = Optional.presentIfNotNull(blue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder enumWithDefaultValue(@Nullable Episode enumWithDefaultValue) {
+      this.enumWithDefaultValue = Optional.presentIfNotNull(enumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * Circle ref to review input
+     */
+    public Builder reviewRefInput(@Nullable ReviewRefInput reviewRefInput) {
+      this.reviewRefInput = Optional.presentIfNotNull(reviewRefInput);
+      return this;
+    }
+
+    public ColorInput build() {
+      return new ColorInput(red, green, blue, enumWithDefaultValue, reviewRefInput);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ReviewInput.java.expected b/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ReviewInput.java.expected
index 75023e0620..413e1ec2a9 100644
--- a/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ReviewInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ReviewInput.java.expected
@@ -13,6 +13,7 @@ import java.lang.Override;
 import java.lang.String;
 import java.util.Date;
 import java.util.List;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * The input object sent when someone is creating a new review
@@ -220,4 +221,239 @@ public class ReviewInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Integer stars;
+
+    private Optional<Integer> nullableIntFieldWithDefaultValue;
+
+    private Optional<String> commentary;
+
+    private ColorInput favoriteColor;
+
+    private Optional<Episode> enumWithDefaultValue;
+
+    private Optional<Episode> nonNullableEnumWithDefaultValue;
+
+    private Optional<Episode> nullableEnum;
+
+    private Optional<List<Date>> listOfCustomScalar;
+
+    private Optional<Date> customScalar;
+
+    private Optional<List<Episode>> listOfEnums;
+
+    private Optional<List<Integer>> listOfInt;
+
+    private Optional<List<String>> listOfString;
+
+    private List<String> listOfStringNonOptional;
+
+    private Optional<List<ColorInput>> listOfInputTypes;
+
+    private Optional<Boolean> booleanWithDefaultValue;
+
+    private Optional<Boolean> booleanNonOptional;
+
+    private Optional<List<List<String>>> listOfListOfString;
+
+    private Optional<List<List<Episode>>> listOfListOfEnum;
+
+    private Optional<List<List<Date>>> listOfListOfCustom;
+
+    private Optional<List<List<ColorInput>>> listOfListOfObject;
+
+    private Optional<String> CapitalizedField;
+
+    private Optional<Integer> CapitalizedInt;
+
+    Builder() {
+    }
+
+    /**
+     * 0-5 stars
+     */
+    public Builder stars(Integer stars) {
+      this.stars = stars;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nullableIntFieldWithDefaultValue(
+        @Nullable Integer nullableIntFieldWithDefaultValue) {
+      this.nullableIntFieldWithDefaultValue = Optional.presentIfNotNull(nullableIntFieldWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * Comment about the movie, optional
+     */
+    public Builder commentary(@Nullable String commentary) {
+      this.commentary = Optional.presentIfNotNull(commentary);
+      return this;
+    }
+
+    /**
+     * Favorite color, optional
+     */
+    public Builder favoriteColor(ColorInput favoriteColor) {
+      this.favoriteColor = favoriteColor;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder enumWithDefaultValue(@Nullable Episode enumWithDefaultValue) {
+      this.enumWithDefaultValue = Optional.presentIfNotNull(enumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nonNullableEnumWithDefaultValue(
+        @Nullable Episode nonNullableEnumWithDefaultValue) {
+      this.nonNullableEnumWithDefaultValue = Optional.presentIfNotNull(nonNullableEnumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nullableEnum(@Nullable Episode nullableEnum) {
+      this.nullableEnum = Optional.presentIfNotNull(nullableEnum);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfCustomScalar(@Nullable List<Date> listOfCustomScalar) {
+      this.listOfCustomScalar = Optional.presentIfNotNull(listOfCustomScalar);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder customScalar(@Nullable Date customScalar) {
+      this.customScalar = Optional.presentIfNotNull(customScalar);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfEnums(@Nullable List<Episode> listOfEnums) {
+      this.listOfEnums = Optional.presentIfNotNull(listOfEnums);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfInt(@Nullable List<Integer> listOfInt) {
+      this.listOfInt = Optional.presentIfNotNull(listOfInt);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfString(@Nullable List<String> listOfString) {
+      this.listOfString = Optional.presentIfNotNull(listOfString);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfStringNonOptional(List<String> listOfStringNonOptional) {
+      this.listOfStringNonOptional = listOfStringNonOptional;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfInputTypes(@Nullable List<ColorInput> listOfInputTypes) {
+      this.listOfInputTypes = Optional.presentIfNotNull(listOfInputTypes);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder booleanWithDefaultValue(@Nullable Boolean booleanWithDefaultValue) {
+      this.booleanWithDefaultValue = Optional.presentIfNotNull(booleanWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder booleanNonOptional(@Nullable Boolean booleanNonOptional) {
+      this.booleanNonOptional = Optional.presentIfNotNull(booleanNonOptional);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfString(@Nullable List<List<String>> listOfListOfString) {
+      this.listOfListOfString = Optional.presentIfNotNull(listOfListOfString);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfEnum(@Nullable List<List<Episode>> listOfListOfEnum) {
+      this.listOfListOfEnum = Optional.presentIfNotNull(listOfListOfEnum);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfCustom(@Nullable List<List<Date>> listOfListOfCustom) {
+      this.listOfListOfCustom = Optional.presentIfNotNull(listOfListOfCustom);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfObject(@Nullable List<List<ColorInput>> listOfListOfObject) {
+      this.listOfListOfObject = Optional.presentIfNotNull(listOfListOfObject);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder CapitalizedField(@Nullable String CapitalizedField) {
+      this.CapitalizedField = Optional.presentIfNotNull(CapitalizedField);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder CapitalizedInt(@Nullable Integer CapitalizedInt) {
+      this.CapitalizedInt = Optional.presentIfNotNull(CapitalizedInt);
+      return this;
+    }
+
+    public ReviewInput build() {
+      return new ReviewInput(stars, nullableIntFieldWithDefaultValue, commentary, favoriteColor, enumWithDefaultValue, nonNullableEnumWithDefaultValue, nullableEnum, listOfCustomScalar, customScalar, listOfEnums, listOfInt, listOfString, listOfStringNonOptional, listOfInputTypes, booleanWithDefaultValue, booleanNonOptional, listOfListOfString, listOfListOfEnum, listOfListOfCustom, listOfListOfObject, CapitalizedField, CapitalizedInt);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ReviewRefInput.java.expected b/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ReviewRefInput.java.expected
index b138b529db..b2613b5f87 100644
--- a/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ReviewRefInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ReviewRefInput.java.expected
@@ -9,6 +9,7 @@ import com.apollographql.apollo3.api.Optional;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Circle ref to review input
@@ -59,4 +60,24 @@ public class ReviewRefInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<ReviewInput> reviewInput;
+
+    Builder() {
+    }
+
+    public Builder reviewInput(@Nullable ReviewInput reviewInput) {
+      this.reviewInput = Optional.presentIfNotNull(reviewInput);
+      return this;
+    }
+
+    public ReviewRefInput build() {
+      return new ReviewRefInput(reviewInput);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/CreateReviewForEpisodeMutation.java.expected b/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/CreateReviewForEpisodeMutation.java.expected
index a131ed67f9..ab0bf678ff 100644
--- a/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/CreateReviewForEpisodeMutation.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/CreateReviewForEpisodeMutation.java.expected
@@ -93,6 +93,10 @@ public class CreateReviewForEpisodeMutation implements Mutation<CreateReviewForE
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -129,6 +133,29 @@ public class CreateReviewForEpisodeMutation implements Mutation<CreateReviewForE
     .build();
   }
 
+  public static final class Builder {
+    private Episode ep;
+
+    private ReviewInput review;
+
+    Builder() {
+    }
+
+    public Builder ep(Episode ep) {
+      this.ep = ep;
+      return this;
+    }
+
+    public Builder review(ReviewInput review) {
+      this.review = review;
+      return this;
+    }
+
+    public CreateReviewForEpisodeMutation build() {
+      return new CreateReviewForEpisodeMutation(ep, review);
+    }
+  }
+
   public static class Data implements Mutation.Data {
     public CreateReview createReview;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ColorInput.java.expected b/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ColorInput.java.expected
index 61c8a801df..a095f440f9 100644
--- a/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ColorInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ColorInput.java.expected
@@ -11,6 +11,7 @@ import java.lang.Integer;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * The input object sent when passing in a color
@@ -90,4 +91,67 @@ public class ColorInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<Integer> red;
+
+    private Optional<Double> green;
+
+    private Optional<Double> blue;
+
+    private Optional<Episode> enumWithDefaultValue;
+
+    private Optional<ReviewRefInput> reviewRefInput;
+
+    Builder() {
+    }
+
+    /**
+     * Red color
+     */
+    public Builder red(@Nullable Integer red) {
+      this.red = Optional.presentIfNotNull(red);
+      return this;
+    }
+
+    /**
+     * Green color
+     */
+    public Builder green(@Nullable Double green) {
+      this.green = Optional.presentIfNotNull(green);
+      return this;
+    }
+
+    /**
+     * Blue color
+     */
+    public Builder blue(@Nullable Double blue) {
+      this.blue = Optional.presentIfNotNull(blue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder enumWithDefaultValue(@Nullable Episode enumWithDefaultValue) {
+      this.enumWithDefaultValue = Optional.presentIfNotNull(enumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * Circle ref to review input
+     */
+    public Builder reviewRefInput(@Nullable ReviewRefInput reviewRefInput) {
+      this.reviewRefInput = Optional.presentIfNotNull(reviewRefInput);
+      return this;
+    }
+
+    public ColorInput build() {
+      return new ColorInput(red, green, blue, enumWithDefaultValue, reviewRefInput);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ReviewInput.java.expected b/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ReviewInput.java.expected
index 252f96aa81..e4143bda22 100644
--- a/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ReviewInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ReviewInput.java.expected
@@ -12,6 +12,7 @@ import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
 import java.util.List;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * The input object sent when someone is creating a new review
@@ -220,4 +221,239 @@ public class ReviewInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Integer stars;
+
+    private Optional<Integer> nullableIntFieldWithDefaultValue;
+
+    private Optional<String> commentary;
+
+    private ColorInput favoriteColor;
+
+    private Optional<Episode> enumWithDefaultValue;
+
+    private Optional<Episode> nonNullableEnumWithDefaultValue;
+
+    private Optional<Episode> nullableEnum;
+
+    private Optional<List<Object>> listOfCustomScalar;
+
+    private Optional<Object> customScalar;
+
+    private Optional<List<Episode>> listOfEnums;
+
+    private Optional<List<Integer>> listOfInt;
+
+    private Optional<List<String>> listOfString;
+
+    private List<String> listOfStringNonOptional;
+
+    private Optional<List<ColorInput>> listOfInputTypes;
+
+    private Optional<Boolean> booleanWithDefaultValue;
+
+    private Optional<Boolean> booleanNonOptional;
+
+    private Optional<List<List<String>>> listOfListOfString;
+
+    private Optional<List<List<Episode>>> listOfListOfEnum;
+
+    private Optional<List<List<Object>>> listOfListOfCustom;
+
+    private Optional<List<List<ColorInput>>> listOfListOfObject;
+
+    private Optional<String> CapitalizedField;
+
+    private Optional<Integer> CapitalizedInt;
+
+    Builder() {
+    }
+
+    /**
+     * 0-5 stars
+     */
+    public Builder stars(Integer stars) {
+      this.stars = stars;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nullableIntFieldWithDefaultValue(
+        @Nullable Integer nullableIntFieldWithDefaultValue) {
+      this.nullableIntFieldWithDefaultValue = Optional.presentIfNotNull(nullableIntFieldWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * Comment about the movie, optional
+     */
+    public Builder commentary(@Nullable String commentary) {
+      this.commentary = Optional.presentIfNotNull(commentary);
+      return this;
+    }
+
+    /**
+     * Favorite color, optional
+     */
+    public Builder favoriteColor(ColorInput favoriteColor) {
+      this.favoriteColor = favoriteColor;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder enumWithDefaultValue(@Nullable Episode enumWithDefaultValue) {
+      this.enumWithDefaultValue = Optional.presentIfNotNull(enumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nonNullableEnumWithDefaultValue(
+        @Nullable Episode nonNullableEnumWithDefaultValue) {
+      this.nonNullableEnumWithDefaultValue = Optional.presentIfNotNull(nonNullableEnumWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder nullableEnum(@Nullable Episode nullableEnum) {
+      this.nullableEnum = Optional.presentIfNotNull(nullableEnum);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfCustomScalar(@Nullable List<Object> listOfCustomScalar) {
+      this.listOfCustomScalar = Optional.presentIfNotNull(listOfCustomScalar);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder customScalar(Object customScalar) {
+      this.customScalar = Optional.presentIfNotNull(customScalar);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfEnums(@Nullable List<Episode> listOfEnums) {
+      this.listOfEnums = Optional.presentIfNotNull(listOfEnums);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfInt(@Nullable List<Integer> listOfInt) {
+      this.listOfInt = Optional.presentIfNotNull(listOfInt);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfString(@Nullable List<String> listOfString) {
+      this.listOfString = Optional.presentIfNotNull(listOfString);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfStringNonOptional(List<String> listOfStringNonOptional) {
+      this.listOfStringNonOptional = listOfStringNonOptional;
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfInputTypes(@Nullable List<ColorInput> listOfInputTypes) {
+      this.listOfInputTypes = Optional.presentIfNotNull(listOfInputTypes);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder booleanWithDefaultValue(@Nullable Boolean booleanWithDefaultValue) {
+      this.booleanWithDefaultValue = Optional.presentIfNotNull(booleanWithDefaultValue);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder booleanNonOptional(@Nullable Boolean booleanNonOptional) {
+      this.booleanNonOptional = Optional.presentIfNotNull(booleanNonOptional);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfString(@Nullable List<List<String>> listOfListOfString) {
+      this.listOfListOfString = Optional.presentIfNotNull(listOfListOfString);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfEnum(@Nullable List<List<Episode>> listOfListOfEnum) {
+      this.listOfListOfEnum = Optional.presentIfNotNull(listOfListOfEnum);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfCustom(@Nullable List<List<Object>> listOfListOfCustom) {
+      this.listOfListOfCustom = Optional.presentIfNotNull(listOfListOfCustom);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder listOfListOfObject(@Nullable List<List<ColorInput>> listOfListOfObject) {
+      this.listOfListOfObject = Optional.presentIfNotNull(listOfListOfObject);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder CapitalizedField(@Nullable String CapitalizedField) {
+      this.CapitalizedField = Optional.presentIfNotNull(CapitalizedField);
+      return this;
+    }
+
+    /**
+     * for test purpose only
+     */
+    public Builder CapitalizedInt(@Nullable Integer CapitalizedInt) {
+      this.CapitalizedInt = Optional.presentIfNotNull(CapitalizedInt);
+      return this;
+    }
+
+    public ReviewInput build() {
+      return new ReviewInput(stars, nullableIntFieldWithDefaultValue, commentary, favoriteColor, enumWithDefaultValue, nonNullableEnumWithDefaultValue, nullableEnum, listOfCustomScalar, customScalar, listOfEnums, listOfInt, listOfString, listOfStringNonOptional, listOfInputTypes, booleanWithDefaultValue, booleanNonOptional, listOfListOfString, listOfListOfEnum, listOfListOfCustom, listOfListOfObject, CapitalizedField, CapitalizedInt);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ReviewRefInput.java.expected b/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ReviewRefInput.java.expected
index 460cc60f1c..42afef085a 100644
--- a/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ReviewRefInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ReviewRefInput.java.expected
@@ -9,6 +9,7 @@ import com.apollographql.apollo3.api.Optional;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Circle ref to review input
@@ -59,4 +60,24 @@ public class ReviewRefInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<ReviewInput> reviewInput;
+
+    Builder() {
+    }
+
+    public Builder reviewInput(@Nullable ReviewInput reviewInput) {
+      this.reviewInput = Optional.presentIfNotNull(reviewInput);
+      return this;
+    }
+
+    public ReviewRefInput build() {
+      return new ReviewRefInput(reviewInput);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/named_fragment_delegate/java/operationBased/named_fragment_delegate/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/named_fragment_delegate/java/operationBased/named_fragment_delegate/TestQuery.java.expected
index bce6987031..9294ac8bff 100644
--- a/apollo-compiler/src/test/graphql/com/example/named_fragment_delegate/java/operationBased/named_fragment_delegate/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/named_fragment_delegate/java/operationBased/named_fragment_delegate/TestQuery.java.expected
@@ -99,6 +99,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -135,6 +139,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/java/operationBased/named_fragment_inside_inline_fragment/GetHero.java.expected b/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/java/operationBased/named_fragment_inside_inline_fragment/GetHero.java.expected
index 2d55fdd137..68547ebc36 100644
--- a/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/java/operationBased/named_fragment_inside_inline_fragment/GetHero.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/java/operationBased/named_fragment_inside_inline_fragment/GetHero.java.expected
@@ -90,6 +90,10 @@ public class GetHero implements Query<GetHero.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -126,6 +130,15 @@ public class GetHero implements Query<GetHero.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public GetHero build() {
+      return new GetHero();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/named_fragment_with_variables/java/operationBased/named_fragment_with_variables/GetUser.java.expected b/apollo-compiler/src/test/graphql/com/example/named_fragment_with_variables/java/operationBased/named_fragment_with_variables/GetUser.java.expected
index 945f7a0794..bfb144cdab 100644
--- a/apollo-compiler/src/test/graphql/com/example/named_fragment_with_variables/java/operationBased/named_fragment_with_variables/GetUser.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/named_fragment_with_variables/java/operationBased/named_fragment_with_variables/GetUser.java.expected
@@ -114,6 +114,10 @@ public class GetUser implements Query<GetUser.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -150,6 +154,36 @@ public class GetUser implements Query<GetUser.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private String organizationId;
+
+    private UserQuery query;
+
+    private Integer size;
+
+    Builder() {
+    }
+
+    public Builder organizationId(String organizationId) {
+      this.organizationId = organizationId;
+      return this;
+    }
+
+    public Builder query(UserQuery query) {
+      this.query = query;
+      return this;
+    }
+
+    public Builder size(Integer size) {
+      this.size = size;
+      return this;
+    }
+
+    public GetUser build() {
+      return new GetUser(organizationId, query, size);
+    }
+  }
+
   public static class Data implements Query.Data {
     public String __typename;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/named_fragment_with_variables/java/operationBased/named_fragment_with_variables/type/UserQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/named_fragment_with_variables/java/operationBased/named_fragment_with_variables/type/UserQuery.java.expected
index 4490145e76..d47412249f 100644
--- a/apollo-compiler/src/test/graphql/com/example/named_fragment_with_variables/java/operationBased/named_fragment_with_variables/type/UserQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/named_fragment_with_variables/java/operationBased/named_fragment_with_variables/type/UserQuery.java.expected
@@ -10,6 +10,7 @@ import java.lang.Boolean;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 public class UserQuery {
   public final String name;
@@ -64,4 +65,31 @@ public class UserQuery {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private String name;
+
+    private Optional<Boolean> isAdmin;
+
+    Builder() {
+    }
+
+    public Builder name(String name) {
+      this.name = name;
+      return this;
+    }
+
+    public Builder isAdmin(@Nullable Boolean isAdmin) {
+      this.isAdmin = Optional.presentIfNotNull(isAdmin);
+      return this;
+    }
+
+    public UserQuery build() {
+      return new UserQuery(name, isAdmin);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/named_fragment_without_implementation/java/operationBased/named_fragment_without_implementation/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/named_fragment_without_implementation/java/operationBased/named_fragment_without_implementation/TestQuery.java.expected
index 39567b708b..f917262ca4 100644
--- a/apollo-compiler/src/test/graphql/com/example/named_fragment_without_implementation/java/operationBased/named_fragment_without_implementation/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/named_fragment_without_implementation/java/operationBased/named_fragment_without_implementation/TestQuery.java.expected
@@ -88,6 +88,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -124,6 +128,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/java/operationBased/nested_conditional_inline/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/java/operationBased/nested_conditional_inline/TestQuery.java.expected
index b32f3986de..91d6cbb2b6 100644
--- a/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/java/operationBased/nested_conditional_inline/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/java/operationBased/nested_conditional_inline/TestQuery.java.expected
@@ -22,6 +22,7 @@ import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
 import java.util.List;
+import org.jetbrains.annotations.Nullable;
 
 public class TestQuery implements Query<TestQuery.Data> {
   public static final String OPERATION_ID = "a9f066a7d1092096ab154f16f32114a4bd71e959b789f37879249cdf6309ea86";
@@ -105,6 +106,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -141,6 +146,22 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Optional<Episode> episode;
+
+    Builder() {
+    }
+
+    public Builder episode(@Nullable Episode episode) {
+      this.episode = Optional.presentIfNotNull(episode);
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(episode);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/java/operationBased/nested_field_with_multiple_fieldsets/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/java/operationBased/nested_field_with_multiple_fieldsets/TestQuery.java.expected
index 6f25c75683..bdaf20ef60 100644
--- a/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/java/operationBased/nested_field_with_multiple_fieldsets/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/nested_field_with_multiple_fieldsets/java/operationBased/nested_field_with_multiple_fieldsets/TestQuery.java.expected
@@ -97,6 +97,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -133,6 +137,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Iface1 iface1;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/nested_named_fragments/java/operationBased/nested_named_fragments/AllStarships.java.expected b/apollo-compiler/src/test/graphql/com/example/nested_named_fragments/java/operationBased/nested_named_fragments/AllStarships.java.expected
index 63235396da..d844a22c81 100644
--- a/apollo-compiler/src/test/graphql/com/example/nested_named_fragments/java/operationBased/nested_named_fragments/AllStarships.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/nested_named_fragments/java/operationBased/nested_named_fragments/AllStarships.java.expected
@@ -108,6 +108,10 @@ public class AllStarships implements Query<AllStarships.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -144,6 +148,15 @@ public class AllStarships implements Query<AllStarships.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public AllStarships build() {
+      return new AllStarships();
+    }
+  }
+
   public static class Data implements Query.Data {
     public AllStarships1 allStarships;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/nonnull/java/operationBased/nonnull/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/nonnull/java/operationBased/nonnull/TestQuery.java.expected
index 94e6e86f39..3511bba698 100644
--- a/apollo-compiler/src/test/graphql/com/example/nonnull/java/operationBased/nonnull/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/nonnull/java/operationBased/nonnull/TestQuery.java.expected
@@ -75,6 +75,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -111,6 +115,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/not_all_combinations_are_needed/java/operationBased/not_all_combinations_are_needed/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/not_all_combinations_are_needed/java/operationBased/not_all_combinations_are_needed/TestQuery.java.expected
index c34229eb4a..a854ee965f 100644
--- a/apollo-compiler/src/test/graphql/com/example/not_all_combinations_are_needed/java/operationBased/not_all_combinations_are_needed/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/not_all_combinations_are_needed/java/operationBased/not_all_combinations_are_needed/TestQuery.java.expected
@@ -88,6 +88,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -124,6 +128,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Root root;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/operation_id_generator/java/operationBased/operation_id_generator/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/operation_id_generator/java/operationBased/operation_id_generator/TestQuery.java.expected
index 16664b9643..fbf17cb63d 100644
--- a/apollo-compiler/src/test/graphql/com/example/operation_id_generator/java/operationBased/operation_id_generator/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/operation_id_generator/java/operationBased/operation_id_generator/TestQuery.java.expected
@@ -76,6 +76,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -112,6 +116,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/optional/java/operationBased/optional/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/optional/java/operationBased/optional/TestQuery.java.expected
index 41ac40254a..4c7d85e636 100644
--- a/apollo-compiler/src/test/graphql/com/example/optional/java/operationBased/optional/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/optional/java/operationBased/optional/TestQuery.java.expected
@@ -78,6 +78,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -114,6 +118,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/java/operationBased/path_vs_flat_accessors/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/java/operationBased/path_vs_flat_accessors/TestQuery.java.expected
index 797d3d2e1a..7dfa39c4ce 100644
--- a/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/java/operationBased/path_vs_flat_accessors/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/path_vs_flat_accessors/java/operationBased/path_vs_flat_accessors/TestQuery.java.expected
@@ -84,6 +84,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -120,6 +124,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Root root;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/recursive_selection/java/operationBased/recursive_selection/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/recursive_selection/java/operationBased/recursive_selection/TestQuery.java.expected
index f7c5ece2f3..5dea3af780 100644
--- a/apollo-compiler/src/test/graphql/com/example/recursive_selection/java/operationBased/recursive_selection/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/recursive_selection/java/operationBased/recursive_selection/TestQuery.java.expected
@@ -82,6 +82,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -118,6 +122,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Tree tree;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/reserved_keywords/java/operationBased/reserved_keywords/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/reserved_keywords/java/operationBased/reserved_keywords/TestQuery.java.expected
index 83f88be912..6efb88a41a 100644
--- a/apollo-compiler/src/test/graphql/com/example/reserved_keywords/java/operationBased/reserved_keywords/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/reserved_keywords/java/operationBased/reserved_keywords/TestQuery.java.expected
@@ -82,6 +82,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -118,6 +122,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Yield yield;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/root_query_fragment/java/operationBased/root_query_fragment/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/root_query_fragment/java/operationBased/root_query_fragment/TestQuery.java.expected
index 35069f6a08..2f1370d301 100644
--- a/apollo-compiler/src/test/graphql/com/example/root_query_fragment/java/operationBased/root_query_fragment/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/root_query_fragment/java/operationBased/root_query_fragment/TestQuery.java.expected
@@ -82,6 +82,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -118,6 +122,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public String __typename;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/root_query_fragment_with_nested_fragments/java/operationBased/root_query_fragment_with_nested_fragments/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/root_query_fragment_with_nested_fragments/java/operationBased/root_query_fragment_with_nested_fragments/TestQuery.java.expected
index 0c38016a81..3017beb6a1 100644
--- a/apollo-compiler/src/test/graphql/com/example/root_query_fragment_with_nested_fragments/java/operationBased/root_query_fragment_with_nested_fragments/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/root_query_fragment_with_nested_fragments/java/operationBased/root_query_fragment_with_nested_fragments/TestQuery.java.expected
@@ -103,6 +103,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -139,6 +143,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public String __typename;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/java/operationBased/root_query_inline_fragment/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/java/operationBased/root_query_inline_fragment/TestQuery.java.expected
index c0e25bece1..136765684a 100644
--- a/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/java/operationBased/root_query_inline_fragment/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/java/operationBased/root_query_inline_fragment/TestQuery.java.expected
@@ -94,6 +94,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -130,6 +134,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public String __typename;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/simple_fragment/java/operationBased/simple_fragment/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/simple_fragment/java/operationBased/simple_fragment/TestQuery.java.expected
index 68bbef6292..36e11c5f49 100644
--- a/apollo-compiler/src/test/graphql/com/example/simple_fragment/java/operationBased/simple_fragment/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/simple_fragment/java/operationBased/simple_fragment/TestQuery.java.expected
@@ -93,6 +93,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -129,6 +133,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/java/operationBased/simple_fragment_with_inline_fragments/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/java/operationBased/simple_fragment_with_inline_fragments/TestQuery.java.expected
index fabe9d1742..214aef7d2f 100644
--- a/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/java/operationBased/simple_fragment_with_inline_fragments/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/simple_fragment_with_inline_fragments/java/operationBased/simple_fragment_with_inline_fragments/TestQuery.java.expected
@@ -91,6 +91,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -127,6 +131,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/java/operationBased/simple_inline_fragment/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/java/operationBased/simple_inline_fragment/TestQuery.java.expected
index 6a79485375..1956d9d83a 100644
--- a/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/java/operationBased/simple_inline_fragment/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/simple_inline_fragment/java/operationBased/simple_inline_fragment/TestQuery.java.expected
@@ -89,6 +89,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -125,6 +129,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/simple_union/java/operationBased/simple_union/AnimalQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/simple_union/java/operationBased/simple_union/AnimalQuery.java.expected
index a06e4f084a..b8b552b51b 100644
--- a/apollo-compiler/src/test/graphql/com/example/simple_union/java/operationBased/simple_union/AnimalQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/simple_union/java/operationBased/simple_union/AnimalQuery.java.expected
@@ -87,6 +87,10 @@ public class AnimalQuery implements Query<AnimalQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -123,6 +127,15 @@ public class AnimalQuery implements Query<AnimalQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public AnimalQuery build() {
+      return new AnimalQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Animal animal;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/starships/java/operationBased/starships/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/starships/java/operationBased/starships/TestQuery.java.expected
index c062b45973..378e6a122c 100644
--- a/apollo-compiler/src/test/graphql/com/example/starships/java/operationBased/starships/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/starships/java/operationBased/starships/TestQuery.java.expected
@@ -86,6 +86,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -122,6 +126,22 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private String id;
+
+    Builder() {
+    }
+
+    public Builder id(String id) {
+      this.id = id;
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(id);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Starship starship;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/subscriptions/java/operationBased/subscriptions/TestSubscription.java.expected b/apollo-compiler/src/test/graphql/com/example/subscriptions/java/operationBased/subscriptions/TestSubscription.java.expected
index 753c265f8c..26a02a8ac2 100644
--- a/apollo-compiler/src/test/graphql/com/example/subscriptions/java/operationBased/subscriptions/TestSubscription.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/subscriptions/java/operationBased/subscriptions/TestSubscription.java.expected
@@ -84,6 +84,10 @@ public class TestSubscription implements Subscription<TestSubscription.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -120,6 +124,22 @@ public class TestSubscription implements Subscription<TestSubscription.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private String repo;
+
+    Builder() {
+    }
+
+    public Builder repo(String repo) {
+      this.repo = repo;
+      return this;
+    }
+
+    public TestSubscription build() {
+      return new TestSubscription(repo);
+    }
+  }
+
   public static class Data implements Subscription.Data {
     /**
      * Subscription fires on every comment added
diff --git a/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/TestQuery.java.expected
index 101b9234ff..dc4e3de832 100644
--- a/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/TestQuery.java.expected
@@ -20,6 +20,7 @@ import com.example.target_name.type.renamedInput;
 import java.io.IOException;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 public class TestQuery implements Query<TestQuery.Data> {
   public static final String OPERATION_ID = "42f2acf77ef3db730fa970cbbba1ca04133fcea023d8355d4eb0c27ebe51e30f";
@@ -110,6 +111,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -146,6 +151,36 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Optional<renamedInput> input;
+
+    private Optional<java.lang.Object> scalar;
+
+    private Optional<renamedEnum> enum_;
+
+    Builder() {
+    }
+
+    public Builder input(@Nullable renamedInput input) {
+      this.input = Optional.presentIfNotNull(input);
+      return this;
+    }
+
+    public Builder scalar(java.lang.Object scalar) {
+      this.scalar = Optional.presentIfNotNull(scalar);
+      return this;
+    }
+
+    public Builder enum_(@Nullable renamedEnum enum_) {
+      this.enum_ = Optional.presentIfNotNull(enum_);
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(input, scalar, enum_);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Object object;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/type/renamedInput.java.expected b/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/type/renamedInput.java.expected
index ce661d2e67..38e981b745 100644
--- a/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/type/renamedInput.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/type/renamedInput.java.expected
@@ -9,6 +9,7 @@ import com.apollographql.apollo3.api.Optional;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 public class renamedInput {
   public final Optional<String> field;
@@ -56,4 +57,24 @@ public class renamedInput {
     }
     return $toString;
   }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static final class Builder {
+    private Optional<String> field;
+
+    Builder() {
+    }
+
+    public Builder field(@Nullable String field) {
+      this.field = Optional.presentIfNotNull(field);
+      return this;
+    }
+
+    public renamedInput build() {
+      return new renamedInput(field);
+    }
+  }
 }
diff --git a/apollo-compiler/src/test/graphql/com/example/test_inline/java/operationBased/test_inline/GetPage.java.expected b/apollo-compiler/src/test/graphql/com/example/test_inline/java/operationBased/test_inline/GetPage.java.expected
index 033dacd4a5..4a399dba5b 100644
--- a/apollo-compiler/src/test/graphql/com/example/test_inline/java/operationBased/test_inline/GetPage.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/test_inline/java/operationBased/test_inline/GetPage.java.expected
@@ -87,6 +87,10 @@ public class GetPage implements Query<GetPage.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -123,6 +127,15 @@ public class GetPage implements Query<GetPage.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public GetPage build() {
+      return new GetPage();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Collection collection;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/two_heroes_unique/java/operationBased/two_heroes_unique/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/two_heroes_unique/java/operationBased/two_heroes_unique/TestQuery.java.expected
index c8a7e4220e..3f05e163c9 100644
--- a/apollo-compiler/src/test/graphql/com/example/two_heroes_unique/java/operationBased/two_heroes_unique/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/two_heroes_unique/java/operationBased/two_heroes_unique/TestQuery.java.expected
@@ -79,6 +79,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -115,6 +119,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public R2 r2;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/two_heroes_with_friends/java/operationBased/two_heroes_with_friends/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/two_heroes_with_friends/java/operationBased/two_heroes_with_friends/TestQuery.java.expected
index f4be73f78a..fb0f5befae 100644
--- a/apollo-compiler/src/test/graphql/com/example/two_heroes_with_friends/java/operationBased/two_heroes_with_friends/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/two_heroes_with_friends/java/operationBased/two_heroes_with_friends/TestQuery.java.expected
@@ -97,6 +97,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -133,6 +137,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public R2 r2;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/typename_always_first/java/operationBased/typename_always_first/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/typename_always_first/java/operationBased/typename_always_first/TestQuery.java.expected
index bae57af79f..538b18d0b9 100644
--- a/apollo-compiler/src/test/graphql/com/example/typename_always_first/java/operationBased/typename_always_first/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/typename_always_first/java/operationBased/typename_always_first/TestQuery.java.expected
@@ -86,6 +86,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -122,6 +126,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/union_fragment/java/operationBased/union_fragment/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/union_fragment/java/operationBased/union_fragment/TestQuery.java.expected
index 5d83cdf8c2..1f6b6e95de 100644
--- a/apollo-compiler/src/test/graphql/com/example/union_fragment/java/operationBased/union_fragment/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/union_fragment/java/operationBased/union_fragment/TestQuery.java.expected
@@ -85,6 +85,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -121,6 +125,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public List<Search> search;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/java/operationBased/union_inline_fragments/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/java/operationBased/union_inline_fragments/TestQuery.java.expected
index 81fac7f451..110a81a806 100644
--- a/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/java/operationBased/union_inline_fragments/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/java/operationBased/union_inline_fragments/TestQuery.java.expected
@@ -105,6 +105,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -141,6 +145,15 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public TestQuery build() {
+      return new TestQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public List<Search> search;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/unique_type_name/java/operationBased/unique_type_name/HeroDetailQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/unique_type_name/java/operationBased/unique_type_name/HeroDetailQuery.java.expected
index 11b6baeb1d..14e3133393 100644
--- a/apollo-compiler/src/test/graphql/com/example/unique_type_name/java/operationBased/unique_type_name/HeroDetailQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/unique_type_name/java/operationBased/unique_type_name/HeroDetailQuery.java.expected
@@ -105,6 +105,10 @@ public class HeroDetailQuery implements Query<HeroDetailQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -141,6 +145,15 @@ public class HeroDetailQuery implements Query<HeroDetailQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    Builder() {
+    }
+
+    public HeroDetailQuery build() {
+      return new HeroDetailQuery();
+    }
+  }
+
   public static class Data implements Query.Data {
     public HeroDetailQuery1 heroDetailQuery;
 
diff --git a/apollo-compiler/src/test/graphql/com/example/variable_default_value/java/operationBased/variable_default_value/TestQuery.java.expected b/apollo-compiler/src/test/graphql/com/example/variable_default_value/java/operationBased/variable_default_value/TestQuery.java.expected
index 738dbfe8a9..96fa74836b 100644
--- a/apollo-compiler/src/test/graphql/com/example/variable_default_value/java/operationBased/variable_default_value/TestQuery.java.expected
+++ b/apollo-compiler/src/test/graphql/com/example/variable_default_value/java/operationBased/variable_default_value/TestQuery.java.expected
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.lang.Object;
 import java.lang.Override;
 import java.lang.String;
+import org.jetbrains.annotations.Nullable;
 
 public class TestQuery implements Query<TestQuery.Data> {
   public static final String OPERATION_ID = "7bba59b12a0090dd1fbc4c409ea7e72bd6885a6b31d442bfeb86f4a67e5b62d9";
@@ -84,6 +85,10 @@ public class TestQuery implements Query<TestQuery.Data> {
     return $toString;
   }
 
+  public static Builder builder() {
+    return new Builder();
+  }
+
   @Override
   public String id() {
     return OPERATION_ID;
@@ -120,6 +125,22 @@ public class TestQuery implements Query<TestQuery.Data> {
     .build();
   }
 
+  public static final class Builder {
+    private Optional<Episode> episode;
+
+    Builder() {
+    }
+
+    public Builder episode(@Nullable Episode episode) {
+      this.episode = Optional.presentIfNotNull(episode);
+      return this;
+    }
+
+    public TestQuery build() {
+      return new TestQuery(episode);
+    }
+  }
+
   public static class Data implements Query.Data {
     public Hero hero;
 
diff --git a/apollo-compiler/src/test/kotlin/com/apollographql/apollo3/compiler/CodegenTest.kt b/apollo-compiler/src/test/kotlin/com/apollographql/apollo3/compiler/CodegenTest.kt
index fffbd8248b..611cf6338d 100644
--- a/apollo-compiler/src/test/kotlin/com/apollographql/apollo3/compiler/CodegenTest.kt
+++ b/apollo-compiler/src/test/kotlin/com/apollographql/apollo3/compiler/CodegenTest.kt
@@ -308,6 +308,11 @@ class CodegenTest {
         else -> emptyList()
       }
 
+      val generateModelBuilder = when (folder.name) {
+        "fragment_with_inline_fragment" -> true
+        else -> false
+      }
+
       val generateSchema = folder.name == "__schema"
 
       val schemaFile = folder.listFiles()!!.find { it.isFile && (it.name == "schema.sdl" || it.name == "schema.json" || it.name == "schema.graphqls") }
@@ -362,6 +367,7 @@ class CodegenTest {
           generateAsInternal = generateAsInternal,
           generateFilterNotNull = true,
           generateFragmentImplementations = generateFragmentImplementations,
+          generateModelBuilder = generateModelBuilder,
           generateSchema = generateSchema,
           moduleName = folder.name,
           targetLanguage = targetLanguage,
diff --git a/tests/java-tests/build.gradle.kts b/tests/java-tests/build.gradle.kts
index e761d2da7c..4a4a922f66 100644
--- a/tests/java-tests/build.gradle.kts
+++ b/tests/java-tests/build.gradle.kts
@@ -17,4 +17,5 @@ dependencies {
 
 apollo {
   packageName.set("javatest")
+  generateModelBuilder.set(true)
 }
diff --git a/tests/java-tests/src/test/java/test/ClientTest.java b/tests/java-tests/src/test/java/test/ClientTest.java
index 2763196901..5031f897bc 100644
--- a/tests/java-tests/src/test/java/test/ClientTest.java
+++ b/tests/java-tests/src/test/java/test/ClientTest.java
@@ -68,18 +68,18 @@ public class ClientTest {
   public void simple() {
     mockServer.enqueue(new MockResponse.Builder().body("{\"data\": {\"random\": 42}}").build());
     ApolloResponse<GetRandomQuery.Data> queryResponse = Rx2Apollo.single(
-        apolloClient.query(new GetRandomQuery())
+        apolloClient.query(GetRandomQuery.builder().build())
     ).blockingGet();
     Truth.assertThat(queryResponse.dataAssertNoErrors().random).isEqualTo(42);
 
     mockServer.enqueue(new MockResponse.Builder().body("{\"data\": {\"createAnimal\": {\"__typename\": \"Cat\", \"species\": \"cat\", \"habitat\": {\"temperature\": 10.5}}}}").build());
     ApolloResponse<CreateCatMutation.Data> mutationResponse = Rx2Apollo.single(
-        apolloClient.mutation(new CreateCatMutation())
+        apolloClient.mutation(CreateCatMutation.builder().build())
     ).blockingGet();
     Truth.assertThat(mutationResponse.dataAssertNoErrors().createAnimal.catFragment.species).isEqualTo("cat");
 
     Disposable disposable = Rx2Apollo.flowable(
-        apolloClient.subscription(new AnimalCreatedSubscription())
+        apolloClient.subscription(AnimalCreatedSubscription.builder().build())
     ).subscribe(result -> {
       String species = result.dataAssertNoErrors().animalCreated.catFragment.species;
     });
@@ -99,7 +99,7 @@ public class ClientTest {
     BatchingHttpInterceptor.configureApolloClientBuilder(apolloClientBuilder, false);
     apolloClient = apolloClientBuilder.build();
 
-    ApolloCall<GetRandomQuery.Data> call = apolloClient.query(new GetRandomQuery());
+    ApolloCall<GetRandomQuery.Data> call = apolloClient.query(GetRandomQuery.builder().build());
     BatchingHttpInterceptor.configureApolloCall(call, true);
     ApolloResponse<GetRandomQuery.Data> result = Rx2Apollo.single(call).blockingGet();
   }
diff --git a/tests/java-tests/src/test/java/test/OperationTest.java b/tests/java-tests/src/test/java/test/OperationTest.java
index 3641f3c68a..38c49c3f36 100644
--- a/tests/java-tests/src/test/java/test/OperationTest.java
+++ b/tests/java-tests/src/test/java/test/OperationTest.java
@@ -1,7 +1,6 @@
 package test;
 
 import com.apollographql.apollo3.api.CustomScalarAdapters;
-import com.apollographql.apollo3.api.Operations;
 import com.apollographql.apollo3.api.json.BufferedSinkJsonWriter;
 import com.google.common.truth.Truth;
 import javatest.GetRandomQuery;
@@ -13,9 +12,9 @@ import java.io.IOException;
 public class OperationTest {
   @Test
   public void canUseDefaultFunctions() throws IOException {
-    GetRandomQuery query = new GetRandomQuery();
+    GetRandomQuery query = GetRandomQuery.builder().build();
 
-    GetRandomQuery.Data data = new GetRandomQuery.Data(42);
+    GetRandomQuery.Data data = GetRandomQuery.Data.builder().random(42).build();
 
     Buffer buffer = new Buffer();
     query.adapter().toJson(new BufferedSinkJsonWriter(buffer), CustomScalarAdapters.Empty, data);
@@ -27,4 +26,4 @@ public class OperationTest {
             .replace(" ", "")
     ).isEqualTo("{\"random\":42}");
   }
-}
\ No newline at end of file
+}