Skip to content

Commit

Permalink
Generate Jackson annotations for interfaces #1033 #1034
Browse files Browse the repository at this point in the history
  • Loading branch information
esfomeado authored Feb 21, 2023
1 parent 76e0471 commit b6dfc63
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import graphql.language.Argument;
import graphql.language.Directive;
import graphql.language.InputValueDefinition;
import graphql.language.InterfaceTypeDefinition;
import graphql.language.ListType;
import graphql.language.NamedNode;
import graphql.language.NonNullType;
Expand Down Expand Up @@ -204,7 +205,7 @@ public List<String> getAnnotationsForDirective(MappingContext mappingContext,
public List<String> getJacksonTypeIdAnnotations(MappingContext mappingContext, NamedNode<?> def) {
List<String> defaults = new ArrayList<>();
if (Boolean.TRUE.equals(mappingContext.getGenerateJacksonTypeIdResolver())
&& def instanceof UnionTypeDefinition) {
&& (def instanceof UnionTypeDefinition || def instanceof InterfaceTypeDefinition)) {
defaults.add("com.fasterxml.jackson.annotation.JsonTypeInfo(use = " +
"com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, property = \"__typename\")");
String modelPackageName = DataModelMapper.getModelPackageName(mappingContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.kobylynskyi.graphql.codegen.TestUtils.assertFileContainsElements;
import static com.kobylynskyi.graphql.codegen.TestUtils.assertSameTrimmedContent;
import static com.kobylynskyi.graphql.codegen.TestUtils.getFileByName;
import static java.lang.System.lineSeparator;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
Expand Down Expand Up @@ -141,11 +142,10 @@ void generate_NoPackage() throws Exception {
generate("src/test/resources/schemas/test.graphqls");

File[] files = Objects.requireNonNull(outputBuildDir.listFiles());
assertFileContainsElements(files, "Event.java", System.lineSeparator() +
"/**" + System.lineSeparator() +
" * An event that describes a thing that happens" + System
.lineSeparator() +
" */" + System.lineSeparator());
assertFileContainsElements(files, "Event.java", lineSeparator() +
"/**" + lineSeparator() +
" * An event that describes a thing that happens" + lineSeparator() +
" */" + lineSeparator());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package com.kobylynskyi.graphql.unionresolver;
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, property = "__typename")
@com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver(com.kobylynskyi.graphql.unionresolver.GraphqlJacksonTypeIdResolver.class)
public interface ResultObject {

java.util.List<? extends UnionToResolve> getList();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
value = "com.kobylynskyi.graphql.codegen.GraphQLCodegen",
date = "2020-12-31T23:59:59-0500"
)
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, property = "__typename")
@com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver(GraphqlJacksonTypeIdResolver.class)
public interface MyResultObjectSuffix {

java.util.List<? extends MyUnionToResolveSuffix> getList();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package com.kobylynskyi.graphql.unionresolver
value = ["com.kobylynskyi.graphql.codegen.GraphQLCodegen"],
date = "2020-12-31T23:59:59-0500"
)
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, property = "__typename")
@com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver(com.kobylynskyi.graphql.unionresolver.GraphqlJacksonTypeIdResolver::class)
interface ResultObject {

val list: List<out UnionToResolve>?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
value = ["com.kobylynskyi.graphql.codegen.GraphQLCodegen"],
date = "2020-12-31T23:59:59-0500"
)
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, property = "__typename")
@com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver(GraphqlJacksonTypeIdResolver::class)
interface MyResultObjectSuffix {

val list: List<out MyUnionToResolveSuffix>?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package com.kobylynskyi.graphql.unionresolver
value = Array("com.kobylynskyi.graphql.codegen.GraphQLCodegen"),
date = "2020-12-31T23:59:59-0500"
)
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, property = "__typename")
@com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver(classOf[com.kobylynskyi.graphql.unionresolver.GraphqlJacksonTypeIdResolver])
trait ResultObject {

val list: scala.Seq[_ <: UnionToResolve]

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
value = Array("com.kobylynskyi.graphql.codegen.GraphQLCodegen"),
date = "2020-12-31T23:59:59-0500"
)
@com.fasterxml.jackson.annotation.JsonTypeInfo(use = com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME, property = "__typename")
@com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver(classOf[GraphqlJacksonTypeIdResolver])
trait MyResultObjectSuffix {

val list: scala.Seq[_ <: MyUnionToResolveSuffix]

}
}

0 comments on commit b6dfc63

Please sign in to comment.