Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ protected void initCustomTypeMappings(Collection<ExtendedScalarTypeDefinition> s
super.initCustomTypeMappings(scalarTypeDefinitions);
mappingConfig.putCustomTypeMappingIfAbsent("ID", String.class.getSimpleName());
mappingConfig.putCustomTypeMappingIfAbsent("String", String.class.getSimpleName());
mappingConfig.putCustomTypeMappingIfAbsent("Int", "Option[Int]");
mappingConfig.putCustomTypeMappingIfAbsent("Int", "scala.Option[Int]");
mappingConfig.putCustomTypeMappingIfAbsent("Int!", "Int");
mappingConfig.putCustomTypeMappingIfAbsent("Float",
Utils.wrapString(Double.class.getSimpleName(), "Option[", "]"));
Utils.wrapString(Double.class.getSimpleName(), "scala.Option[", "]"));
mappingConfig.putCustomTypeMappingIfAbsent("Float!", Double.class.getSimpleName());
mappingConfig.putCustomTypeMappingIfAbsent("Boolean",
Utils.wrapString(Boolean.class.getSimpleName(), "Option[", "]"));
Utils.wrapString(Boolean.class.getSimpleName(), "scala.Option[", "]"));
mappingConfig.putCustomTypeMappingIfAbsent("Boolean!", Boolean.class.getSimpleName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
public class ScalaGraphQLTypeMapper implements GraphQLTypeMapper {

private static final String SCALA_UTIL_LIST = "Seq";
private static final String SCALA_UTIL_OPTIONAL = "Option";
private static final String SCALA_UTIL_LIST = "scala.Seq";
private static final String SCALA_UTIL_OPTIONAL = "scala.Option";
private static final Set<String> SCALA_PRIMITIVE_TYPES = new HashSet<>(asList(
"Byte", "Short", "Int", "Long", "Float", "Double", "Char", "Boolean"));

Expand All @@ -41,6 +41,10 @@ public static boolean isScalaCollection(String scalaType) {
return scalaType.startsWith(SCALA_UTIL_LIST + "[") && scalaType.endsWith("]");
}

public static String getGenericParameter(String scalaType) {
return scalaType.substring(SCALA_UTIL_LIST.length() + 1, scalaType.length() - 1);
}

@Override
public String wrapIntoList(MappingContext mappingContext, String type, boolean mandatory) {
return getGenericsString(mappingContext, SCALA_UTIL_LIST, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ public class ScalaValueFormatter implements ValueFormatter {

@Override
public String getEmptyListValue() {
return "Seq.empty";
return "scala.Seq.empty";
}

@Override
public StringJoiner getListJoiner() {
return new StringJoiner(", ", "Seq(", ")");
return new StringJoiner(", ", "scala.Seq(", ")");
}

@Override
public StringJoiner getArrayJoiner() {
return new StringJoiner(", ", "Array(", ")");
return new StringJoiner(", ", "scala.Array(", ")");
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<#assign MapperUtil=statics["com.kobylynskyi.graphql.codegen.scala.ScalaGraphQLTypeMapper"]>
<#if package?has_content>
package ${package}

Expand All @@ -11,8 +12,8 @@ import ${import}._
<#if enumImportItSelfInScala?has_content>
<#list fields as field>
<#list enumImportItSelfInScala as enum>
<#if field.type?contains("Seq[")>
<#if enum == field.type?replace("Seq[", "")?replace("]", "")>
<#if MapperUtil.isScalaCollection(field.type)>
<#if enum == MapperUtil.getGenericParameter(field.type)>
import ${enum}._
</#if>
<#else >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ${import}._
<#list operation.parameters as param>
<#list enumImportItSelfInScala as enum>
<#if MapperUtil.isScalaCollection(param.type)>
<#if enum == param.type?replace("Seq[", "")?replace("]", "")>
<#if enum == MapperUtil.getGenericParameter(param.type)>
<#if !waitImports?seq_contains(enum)>
<#assign waitImports = waitImports + [enum] />
</#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.collection.JavaConverters._
<#list fields as field>
<#list enumImportItSelfInScala as enum>
<#if MapperUtil.isScalaCollection(field.type)>
<#if enum == field.type?replace("Seq[", "")?replace("]", "")>
<#if enum == MapperUtil.getGenericParameter(field.type)>
import ${enum}._
</#if>
<#else >
Expand Down Expand Up @@ -54,9 +54,9 @@ case class ${className}(
</#if>
) extends GraphQLParametrizedInput {

override def toString(): String = {<#--There is no Option[Seq[T]]-->
override def toString(): String = {<#--There is no Option[Seq[T]], Format is not supported in the generated code, so it is very difficult to write template for this format.-->
<#if fields?has_content>
Seq(<#list fields as field><#assign getMethod = ".get"><#assign asJava = ".asJava">
scala.Seq(<#list fields as field><#assign getMethod = ".get"><#assign asJava = ".asJava">
<#if MapperUtil.isScalaPrimitive(field.type)>"${field.originalName}: " + GraphQLRequestSerializer.getEntry(${field.name})<#if field_has_next>,</#if><#elseif MapperUtil.isScalaOption(field.type)>if (${field.name}.isDefined) "${field.originalName}: " + GraphQLRequestSerializer.getEntry(${field.name}${getMethod}) else ""<#if field_has_next>,</#if><#else>if (${field.name} != null)<#if MapperUtil.isScalaCollection(field.type)> "${field.originalName}: " + GraphQLRequestSerializer.getEntry(${field.name}${asJava}) else ""<#if field_has_next>,</#if><#else> "${field.originalName}: " + GraphQLRequestSerializer.getEntry(${field.name}) else ""<#if field_has_next>,</#if></#if></#if></#list>
).filter(_ != "").mkString("(", ",", ")")
<#else>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package ${package}
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest
import java.util.{ LinkedHashMap => JLinkedHashMap }
import java.util.{ Map => JMap }
import java.util.{ Map => JMap, Set => JSet }
<#if toString || equalsAndHashCode>
import java.util.Objects
</#if>
Expand All @@ -17,7 +17,7 @@ import scala.collection.JavaConverters._
<#list fields as field>
<#list enumImportItSelfInScala as enum>
<#if MapperUtil.isScalaCollection(field.type)>
<#if enum == field.type?replace("Seq[", "")?replace("]", "")>
<#if enum == MapperUtil.getGenericParameter(field.type)>
import ${enum}._
</#if>
<#else >
Expand Down Expand Up @@ -85,7 +85,7 @@ class ${className}(alias: String) extends GraphQLOperationRequest {

override def getInput(): JMap[String, java.lang.Object] = input

override def getUseObjectMapperForInputSerialization(): java.util.Set[String] = useObjectMapperForInputSerialization.asJava
override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava
<#if equalsAndHashCode>

override def equals(obj: Any): Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import scala.collection.JavaConverters._
<#list fields as field>
<#list enumImportItSelfInScala as enum>
<#if MapperUtil.isScalaCollection(field.type)>
<#if enum == field.type?replace("Seq[", "")?replace("]", "")>
<#if enum == MapperUtil.getGenericParameter(field.type)>
import ${enum}._
</#if>
<#else >
Expand Down Expand Up @@ -88,7 +88,7 @@ import ${enum}._
<#if toString>
override def toString(): String = {
<#if fields?has_content><#-- When you modify it, copy it out and make sure it is one line after modification, There is no Option[Seq[T]]. -->
Seq(<#list fields as field><#assign getMethod = ""><#assign asJava = ""><#if MapperUtil.isScalaOption(field.type)><#assign getMethod = ".get"></#if><#if MapperUtil.isScalaCollection(field.type)><#assign asJava = ".asJava"></#if>
scala.Seq(<#list fields as field><#assign getMethod = ""><#assign asJava = ""><#if MapperUtil.isScalaOption(field.type)><#assign getMethod = ".get"></#if><#if MapperUtil.isScalaCollection(field.type)><#assign asJava = ".asJava"></#if>
<#if MapperUtil.isScalaPrimitive(field.type)><#if toStringForRequest>"${field.originalName}: " + GraphQLRequestSerializer.getEntry(${field.name}<#if field.serializeUsingObjectMapper>, true</#if>)<#else>"${field.originalName}: " + ${field.name}</#if><#else><#if MapperUtil.isScalaOption(field.type)>if (${field.name}.isDefined) <#else>if (${field.name} != null) </#if><#if toStringForRequest>"${field.originalName}: " + GraphQLRequestSerializer.getEntry(${field.name}${getMethod}${asJava}<#if field.serializeUsingObjectMapper>, true</#if>)<#else><#if field.type == "String"> "${field.originalName}: \"${field.name}\"" <#else> "${field.originalName}: ${field.name}"</#if></#if> else ""</#if><#if field_has_next>,</#if></#list>
).filter(_ != "").mkString("{", ",", "}")
<#else><#--Keep it on one line to make sure the code style remains the same-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import scala.collection.JavaConverters._
case class AddLabelsToLabelableInput(
clientMutationId: String,
@javax.validation.constraints.NotNull
labelIds: Seq[String],
labelIds: scala.Seq[String],
@javax.validation.constraints.NotNull
labelableId: String
) {

override def toString(): String = {
Seq(
scala.Seq(
if (clientMutationId != null) "clientMutationId: " + GraphQLRequestSerializer.getEntry(clientMutationId) else "",
if (labelIds != null) "labelIds: " + GraphQLRequestSerializer.getEntry(labelIds.asJava) else "",
if (labelableId != null) "labelableId: " + GraphQLRequestSerializer.getEntry(labelableId) else ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.graphql
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest
import java.util.{ LinkedHashMap => JLinkedHashMap }
import java.util.{ Map => JMap }
import java.util.{ Map => JMap, Set => JSet }
import java.util.Objects
import scala.collection.mutable
import scala.collection.JavaConverters._
Expand All @@ -29,7 +29,7 @@ class AddLabelsToLabelableMutationRequest(alias: String) extends GraphQLOperatio

override def getInput(): JMap[String, java.lang.Object] = input

override def getUseObjectMapperForInputSerialization(): java.util.Set[String] = useObjectMapperForInputSerialization.asJava
override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava

override def equals(obj: Any): Boolean = {
if (this == obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ case class AddLabelsToLabelablePayload(
) {

override def toString(): String = {
Seq(
scala.Seq(
if (clientMutationId != null) "clientMutationId: " + GraphQLRequestSerializer.getEntry(clientMutationId) else "",
if (labelable != null) "labelable: " + GraphQLRequestSerializer.getEntry(labelable) else ""
).filter(_ != "").mkString("{", ",", "}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ package com.github.graphql
trait CodesOfConductQueryResolver {

@throws[Exception]
def codesOfConduct(): Seq[CodeOfConduct]
def codesOfConduct(): scala.Seq[CodeOfConduct]

}
2 changes: 1 addition & 1 deletion src/test/resources/expected-classes/scala/Commit.scala.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ case class Commit(
) extends Closer with IssueTimelineItem with PullRequestTimelineItem with Subscribable with Node with GitObject with UniformResourceLocatable {

override def toString(): String = {
Seq(
scala.Seq(
if (abbreviatedOid != null) "abbreviatedOid: " + GraphQLRequestSerializer.getEntry(abbreviatedOid) else "",
"additions: " + GraphQLRequestSerializer.getEntry(additions),
if (associatedPullRequests != null) "associatedPullRequests: " + GraphQLRequestSerializer.getEntry(associatedPullRequests) else "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ case class Commit(
) extends Closer with IssueTimelineItem with PullRequestTimelineItem with Subscribable with Node with GitObject with UniformResourceLocatable {

override def toString(): String = {
Seq(
scala.Seq(
if (abbreviatedOid != null) "abbreviatedOid: " + GraphQLRequestSerializer.getEntry(abbreviatedOid) else "",
"additions: " + GraphQLRequestSerializer.getEntry(additions),
if (associatedPullRequests != null) "associatedPullRequests: " + GraphQLRequestSerializer.getEntry(associatedPullRequests) else "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ case class Commit(
) extends Closer with IssueTimelineItem with PullRequestTimelineItem with Subscribable with Node with GitObject with UniformResourceLocatable {

override def toString(): String = {
Seq(
scala.Seq(
if (abbreviatedOid != null) "abbreviatedOid: " + GraphQLRequestSerializer.getEntry(abbreviatedOid) else "",
"additions: " + GraphQLRequestSerializer.getEntry(additions),
if (associatedPullRequests != null) "associatedPullRequests: " + GraphQLRequestSerializer.getEntry(associatedPullRequests) else "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Commit(
) extends Closer with IssueTimelineItem with PullRequestTimelineItem with Subscribable with Node with GitObject with UniformResourceLocatable {

override def toString(): String = {
Seq(
scala.Seq(
if (abbreviatedOid != null) "abbreviatedOid: " + GraphQLRequestSerializer.getEntry(abbreviatedOid) else "",
"additions: " + GraphQLRequestSerializer.getEntry(additions),
if (associatedPullRequests != null) "associatedPullRequests: " + GraphQLRequestSerializer.getEntry(associatedPullRequests) else "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ case class Commit(
) extends Closer with IssueTimelineItem with PullRequestTimelineItem with Subscribable with Node with GitObject with UniformResourceLocatable {

override def toString(): String = {
Seq(
scala.Seq(
if (abbreviatedOid != null) "abbreviatedOid: " + GraphQLRequestSerializer.getEntry(abbreviatedOid) else "",
"additions: " + GraphQLRequestSerializer.getEntry(additions),
if (associatedPullRequests != null) "associatedPullRequests: " + GraphQLRequestSerializer.getEntry(associatedPullRequests) else "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ case class Commit(
) extends Closer with IssueTimelineItem with PullRequestTimelineItem with Subscribable with Node with GitObject with UniformResourceLocatable {

override def toString(): String = {
Seq(
scala.Seq(
if (abbreviatedOid != null) "abbreviatedOid: " + GraphQLRequestSerializer.getEntry(abbreviatedOid) else "",
if (additions != null) "additions: " + GraphQLRequestSerializer.getEntry(additions) else "",
if (associatedPullRequests != null) "associatedPullRequests: " + GraphQLRequestSerializer.getEntry(associatedPullRequests) else "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case class GithubAcceptTopicSuggestionInputTO(
) {

override def toString(): String = {
Seq(
scala.Seq(
if (clientMutationId != null) "clientMutationId: " + GraphQLRequestSerializer.getEntry(clientMutationId) else "",
if (name != null) "name: " + GraphQLRequestSerializer.getEntry(name) else "",
if (repositoryId != null) "repositoryId: " + GraphQLRequestSerializer.getEntry(repositoryId) else ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ case class GithubCommitTO(
) extends GithubCloserTO with GithubIssueTimelineItemTO with GithubPullRequestTimelineItemTO with GithubGitObjectTO with GithubNodeTO with GithubSubscribableTO with GithubUniformResourceLocatableTO {

override def toString(): String = {
Seq(
scala.Seq(
if (abbreviatedOid != null) "abbreviatedOid: " + GraphQLRequestSerializer.getEntry(abbreviatedOid) else "",
"additions: " + GraphQLRequestSerializer.getEntry(additions),
if (associatedPullRequests != null) "associatedPullRequests: " + GraphQLRequestSerializer.getEntry(associatedPullRequests) else "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.kobylynskyi.graphql.test1
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest
import java.util.{ LinkedHashMap => JLinkedHashMap }
import java.util.{ Map => JMap }
import java.util.{ Map => JMap, Set => JSet }
import scala.collection.mutable
import scala.collection.JavaConverters._
import java.util.Objects
Expand All @@ -30,7 +30,7 @@ class QueryINeedQueryRequest(alias: String) extends GraphQLOperationRequest {

override def getInput(): JMap[String, java.lang.Object] = input

override def getUseObjectMapperForInputSerialization(): java.util.Set[String] = useObjectMapperForInputSerialization.asJava
override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava

override def toString(): String = Objects.toString(input)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.kobylynskyi.graphql.test1
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation
import com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperationRequest
import java.util.{ LinkedHashMap => JLinkedHashMap }
import java.util.{ Map => JMap }
import java.util.{ Map => JMap, Set => JSet }
import java.util.Objects
import scala.collection.mutable
import scala.collection.JavaConverters._
Expand All @@ -30,7 +30,7 @@ class QueryINeedQueryRequest(alias: String) extends GraphQLOperationRequest {

override def getInput(): JMap[String, java.lang.Object] = input

override def getUseObjectMapperForInputSerialization(): java.util.Set[String] = useObjectMapperForInputSerialization.asJava
override def getUseObjectMapperForInputSerialization(): JSet[String] = useObjectMapperForInputSerialization.asJava

override def toString(): String = Objects.toString(input)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait CreateEventMutationResolver {
* Create a new event.
*/
@javax.validation.constraints.NotNull
@com.example.CustomAnnotation(roles=Array("admin", "moderator"), boo=Array(true, false, true), float=Array("12.0", "null"), int=42, n="null")
@com.example.CustomAnnotation(roles=scala.Array("admin", "moderator"), boo=scala.Array(true, false, true), float=scala.Array("12.0", "null"), int=42, n="null")
@throws[Exception]
def createEvent(categoryId: String, createdBy: String): Event

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trait MutationResolver {
* Create a new event.
*/
@javax.validation.constraints.NotNull
@com.example.CustomAnnotation(roles=Array("admin", "moderator"), boo=Array(true, false, true), float=Array("12.0", "null"), int=42, n="null")
@com.example.CustomAnnotation(roles=scala.Array("admin", "moderator"), boo=scala.Array(true, false, true), float=scala.Array("12.0", "null"), int=42, n="null")
@throws[Exception]
def createEvent(categoryId: String, createdBy: String): Event

Expand Down
Loading