Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 0a085cb

Browse files
authored
Merge pull request #6 from scorebet/vkondrav/marshaller_fix
Marshaller codegen fix
2 parents 7f3e5a8 + 837db4a commit 0a085cb

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/SchemaTypeSpecBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class SchemaTypeSpecBuilder(
222222
fun responseMarshallerSpec(fieldSpecs: List<FieldSpec>): MethodSpec {
223223
val code = fieldSpecs
224224
.map { fieldSpec ->
225-
if (fieldSpec.type.isOptional()) {
225+
if (fieldSpec.type.isNullable()) {
226226
CodeBlock.builder()
227227
.addStatement("final \$T \$L = \$L", fieldSpec.type.unwrapOptionalType().withoutAnnotations(),
228228
"\$${fieldSpec.name}", fieldSpec.type.unwrapOptionalValue(fieldSpec.name))

apollo-compiler/src/test/graphql/com/example/fragments_with_type_condition_nullable/TestQuery.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,14 @@ public ResponseFieldMarshaller marshaller() {
377377
return new ResponseFieldMarshaller() {
378378
@Override
379379
public void marshal(ResponseWriter writer) {
380-
writer.writeFragment(humanDetails.marshaller());
381-
writer.writeFragment(droidDetails.marshaller());
380+
final HumanDetails $humanDetails = humanDetails;
381+
if ($humanDetails != null) {
382+
writer.writeFragment($humanDetails.marshaller());
383+
}
384+
final DroidDetails $droidDetails = droidDetails;
385+
if ($droidDetails != null) {
386+
writer.writeFragment($droidDetails.marshaller());
387+
}
382388
}
383389
};
384390
}
@@ -575,8 +581,14 @@ public ResponseFieldMarshaller marshaller() {
575581
return new ResponseFieldMarshaller() {
576582
@Override
577583
public void marshal(ResponseWriter writer) {
578-
writer.writeFragment(humanDetails.marshaller());
579-
writer.writeFragment(droidDetails.marshaller());
584+
final HumanDetails $humanDetails = humanDetails;
585+
if ($humanDetails != null) {
586+
writer.writeFragment($humanDetails.marshaller());
587+
}
588+
final DroidDetails $droidDetails = droidDetails;
589+
if ($droidDetails != null) {
590+
writer.writeFragment($droidDetails.marshaller());
591+
}
580592
}
581593
};
582594
}

apollo-compiler/src/test/graphql/com/example/union_fragment/TestQuery.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,14 @@ public ResponseFieldMarshaller marshaller() {
363363
return new ResponseFieldMarshaller() {
364364
@Override
365365
public void marshal(ResponseWriter writer) {
366-
writer.writeFragment(character.marshaller());
367-
writer.writeFragment(starship.marshaller());
366+
final Character $character = character;
367+
if ($character != null) {
368+
writer.writeFragment($character.marshaller());
369+
}
370+
final Starship $starship = starship;
371+
if ($starship != null) {
372+
writer.writeFragment($starship.marshaller());
373+
}
368374
}
369375
};
370376
}

0 commit comments

Comments
 (0)