graphql-java-codegen: it will conflict when custom model named the same as java.lang.*
Issue Description
- I want to know how to use custom scalar parsing when parsing JSON without using spring IOC
- i use graphql interface hava failed:
Cannot construct instance of `io.github.dreamylost.model.Character` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (PushbackInputStream); line: 1, column: 17] (through reference chain: io.github.dreamylost.model.HeroQueryResponse["data"]->java.util.LinkedHashMap["hero"])
i use java main method, instance of spring bean,so i create a RestTemplate with new to execute request this is my client example:
@Override
public Character hero(Episode episode) throws Exception {
HeroQueryRequest heroQueryRequest = new HeroQueryRequest();
heroQueryRequest.setEpisode(episode);
CharacterResponseProjection characterResponseProjection = new CharacterResponseProjection();
characterResponseProjection.id().name().onDroid(new DroidResponseProjection().id().name());
GraphQLRequest graphQLRequest = new GraphQLRequest(heroQueryRequest, characterResponseProjection);
//will error, I'm not familiar with this, so i create a issue
HeroQueryResponse result = Config.restTemplate.exchange(URI.create(Config.productUrl), HttpMethod.POST, Config.httpEntity(graphQLRequest), HeroQueryResponse.class).getBody();
assert result != null;
return result.hero();
}
Steps to Reproduce
List in detail the exact steps to reproduce the unexpected behavior.
Expected Result
Explain in detail what behavior you expected to happen.
Actual Result
Explain in detail what behavior actually happened.
Your Environment and Setup
- graphql-java-codegen: E.g.: 2.2.1
- Build tool: E.g.: SBT
- Java tool: E.g.: Java 8u241
- Mapping Config: E.g.:
import java.util
name := "sbt-codegen-exmaple"
version := "1.0.0-SNAPSHOT"
organization := "io.github.dreamylost"
enablePlugins(GraphQLCodegenPlugin)
libraryDependencies ++= GraphQLCodegen ++ Seq(
"org.springframework" % "spring-web" % "5.2.7.RELEASE"
) ++ Seq(
"org.apache.logging.log4j" %% "log4j-api-scala" % "11.0",
"org.apache.logging.log4j" % "log4j-api" % "2.8.2",
"org.apache.logging.log4j" % "log4j-core" % "2.8.2",
"org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.8.2")
graphqlSchemaPaths := Array("src/main/resources/schema.graphqls")
modelPackageName := Some("io.github.dreamylost.model")
apiPackageName := Some("io.github.dreamylost.api")
generateClient := Some(true)
generateApis := Some(true)
customTypesMapping := {
val mapping = new util.HashMap[String, String]
mapping.put("Email", "io.github.dreamylost.scalar.EmailScalar")
mapping
}
Additional context
this is draft impl and example for sbt : https://github.com/jxnu-liguobin/graphql-java-codegen/tree/master/plugins/sbt/graphql-java-codegen-sbt-plugin , but i don’t know about GraphQLCodegenConfiguration and if i impl GraphQLCodegenConfiguration, can not use settingKey in override method in sbt, so i do not impl it.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (11 by maintainers)
Oh, you are right! So there are two issues:
typename()is added only to unions as of now. It should be possible to specify it for interfaces too.customAnnotationsMappingis only supported for field-level and not class-level.I will implement both of these issues on Friday/Saturday and you should get the build over the weekend. Plus I will document the approach of writing the serializer.
Thanks again for finding this!
but i can not find typename() in CharacterResponseProjection, need some setting?
thanks, i have did it,
so request is successfully, but response error when deserializer