-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't fail with enums in directive parameters. #674
Conversation
# type with directive using enum value | ||
type User { | ||
name: String, | ||
friends: [User] @relationship(type: "FRIEND_WITH", direction: OUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enumeration declaration of OUT
should be provided, which is very important for Scala. It will have one more import statement. Enumeration not imported is not available. in scala.
Then, class will be:
import package.model._
import OUTENUM._
import scala.collection.JavaConverters._
/**
* type with directive using enum value
*/
@javax.annotation.Generated(
value = Array("com.kobylynskyi.graphql.codegen.GraphQLCodegen"),
date = "2020-12-31T23:59:59-0500"
)
case class User(
name: String,
@com.example.Relationship(type = "FRIEND_WITH", direction = OUT)
friends: scala.Seq[User]
) {
}
@@ -129,6 +129,9 @@ private String mapEnum(MappingContext mappingContext, EnumValue value, Type<?> g | |||
if (graphQLType instanceof NonNullType) { | |||
return mapEnum(mappingContext, value, ((NonNullType) graphQLType).getType()); | |||
} | |||
if (graphQLType == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that such null-checks should be done before if (graphQLType instanceof NonNullType)
and f (graphQLType instanceof TypeName)
, so can you please move this verification to the top of the method?
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thanks for your swift feedback. I wonder if it makes sense to support Scala in the scope of this PR. As far as I interpret the code around the |
@meistermeier, thanks for your contributions. I think that it would be good to make end-to-end changes in a single PR in order to keep track what was made and what's still pending (Java, Scala, Kotlin) |
There is no problem with this PR change. I just want us to try our best to make the content of the test file tend to be correct for future reference. |
Was investigating the needed changes (for Scala) and found out that it is not only that the annotation needs to be sth. like an Unrelated but since I was on the Scala imports: I removed duplicates from the imports for Enums in the template. (8d63027) |
Thanks, the implementation looks good to me, just like the existing one. However, we may need to use btw, please add one testcase for it , It's good for the future to reconstruct it.. |
@jxnu-liguobin could you please review? Thanks |
I just think PR lacks some test case. Although logically there is no problem. If you are in a hurry, you can merge. |
I can add the test case for the import fix later this week. Was a little bit distracted by daily work ;) |
Sorry I'm not sure what you mean. 😅
|
There is right now the somehow wrong |
Because enumeration |
Yes, I understand this but the problem is with
the import will not get triggered in the Scala world. Nowhere to be precise but Java does not complain about this. Even adding a
won't help because the meta-information are not telling me anything about types in the annotation. Thus my initial question was if I should remove the assumptions in the Scala test code completely. |
The problem here may be that Because enumeration in annotation is not in <#if fields?has_content>
<#if enumImportItSelfInScala?has_content>
<#list fields as field>
<#list enumImportItSelfInScala as enum>
<#if MapperUtil.isScalaCollection(field.type)>
<#if enum == MapperUtil.getGenericParameter(field.type)>
import ${enum}._
</#if>
<#else >
<#if enum == field.type>
import ${enum}._
</#if>
</#if>
</#list>
</#list>
</#if>
</#if> And it's not easy to handle. If processing is forced to be added to the template, the parameter of the annotation should use |
This comment has been minimized.
This comment has been minimized.
@jxnu-liguobin @meistermeier is this ready to be merged to develop and eventually be released as part of the next release (5.3.0)? |
Yes |
@kobylynskyi @jxnu-liguobin @meistermeier enums are not working for Kotlin. Is it supported or planned to be supported? |
@tejas-sastry Please show the failed code and schema. |
@jxnu-liguobin Sorry. should have given this before asking if it was supported. schema:
Plugin config:
Generated class:
Error: My expectation is that the |
@tejas-sastry Thank you for your report. This is indeed a problem. In kotlin, customTypesMapping only handles primitive types. I have opened a new issue for it andthis is a legacy issue left over from the first support for kotlin |
Description
Support mapping of enum values in directive parameters.
This does currently fail and I think that this little bit extra for the
null
-handling can improve the situation.I am pretty new to the whole GraphQL world and do not know if this makes sense at all.
Since I haven't found a similar test scenario for Kotlin, I skipped this part for this PR and just focused on Scala and Java.
Related to #673
Changes were made to: