Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Graphql Java Codegen
提交
5846fe20
G
Graphql Java Codegen
项目概览
梦境迷离
/
Graphql Java Codegen
10 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Graphql Java Codegen
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5846fe20
编写于
2月 10, 2021
作者:
B
Bogdan Kobylynskyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor GraphQLTypeMappers - remove duplicate code
上级
dd048a34
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
70 deletion
+37
-70
src/main/java/com/kobylynskyi/graphql/codegen/java/JavaGraphQLTypeMapper.java
...bylynskyi/graphql/codegen/java/JavaGraphQLTypeMapper.java
+5
-15
src/main/java/com/kobylynskyi/graphql/codegen/kotlin/KotlinGraphQLTypeMapper.java
...nskyi/graphql/codegen/kotlin/KotlinGraphQLTypeMapper.java
+6
-36
src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphQLTypeMapper.java
...kobylynskyi/graphql/codegen/mapper/GraphQLTypeMapper.java
+22
-14
src/main/java/com/kobylynskyi/graphql/codegen/scala/ScalaGraphQLTypeMapper.java
...lynskyi/graphql/codegen/scala/ScalaGraphQLTypeMapper.java
+4
-5
未找到文件。
src/main/java/com/kobylynskyi/graphql/codegen/java/JavaGraphQLTypeMapper.java
浏览文件 @
5846fe20
...
...
@@ -7,7 +7,6 @@ import com.kobylynskyi.graphql.codegen.model.MappingContext;
import
com.kobylynskyi.graphql.codegen.model.NamedDefinition
;
import
com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation
;
import
com.kobylynskyi.graphql.codegen.utils.Utils
;
import
graphql.language.Argument
;
import
java.util.HashSet
;
import
java.util.Map
;
...
...
@@ -79,20 +78,6 @@ public class JavaGraphQLTypeMapper implements GraphQLTypeMapper {
return
!
isPrimitive
(
type
);
}
@Override
public
String
getGenericsString
(
MappingContext
mappingContext
,
String
genericType
,
String
typeParameter
)
{
if
(
genericType
.
contains
(
"%s"
))
{
return
String
.
format
(
genericType
,
typeParameter
);
}
else
{
return
String
.
format
(
"%s<%s>"
,
genericType
,
typeParameter
);
}
}
@Override
public
String
mapDirectiveArgumentValue
(
MappingContext
mappingContext
,
Argument
dirArg
,
String
argumentValueFormatter
)
{
return
valueMapper
.
map
(
mappingContext
,
dirArg
.
getValue
(),
null
,
argumentValueFormatter
);
}
@Override
public
NamedDefinition
getLanguageType
(
MappingContext
mappingContext
,
String
graphQLType
,
String
name
,
String
parentTypeName
,
boolean
mandatory
,
boolean
collection
)
{
...
...
@@ -119,4 +104,9 @@ public class JavaGraphQLTypeMapper implements GraphQLTypeMapper {
mandatory
,
primitiveCanBeUsed
,
serializeUsingObjectMapper
);
}
@Override
public
ValueMapper
getValueMapper
()
{
return
valueMapper
;
}
}
src/main/java/com/kobylynskyi/graphql/codegen/kotlin/KotlinGraphQLTypeMapper.java
浏览文件 @
5846fe20
...
...
@@ -7,7 +7,6 @@ import com.kobylynskyi.graphql.codegen.model.MappingContext;
import
com.kobylynskyi.graphql.codegen.model.NamedDefinition
;
import
com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation
;
import
com.kobylynskyi.graphql.codegen.utils.Utils
;
import
graphql.language.Argument
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -83,45 +82,11 @@ public class KotlinGraphQLTypeMapper implements GraphQLTypeMapper {
return
isKotlinPrimitive
(
kotlinType
);
}
@Override
public
String
getGenericsString
(
MappingContext
mappingContext
,
String
genericType
,
String
typeParameter
)
{
if
(
genericType
.
contains
(
"%s"
))
{
return
String
.
format
(
genericType
,
typeParameter
);
}
else
{
return
String
.
format
(
"%s<%s>"
,
genericType
,
typeParameter
);
}
}
@Override
public
String
mapDirectiveArgumentValue
(
MappingContext
mappingContext
,
Argument
dirArg
,
String
argumentValueFormatter
)
{
return
valueMapper
.
map
(
mappingContext
,
dirArg
.
getValue
(),
null
,
argumentValueFormatter
);
}
@Override
public
boolean
addModelValidationAnnotationForType
(
String
possiblyPrimitiveType
)
{
return
false
;
}
public
static
String
defaultValueKotlinPrimitive
(
String
kotlinType
)
{
switch
(
kotlinType
)
{
case
"Long"
:
return
"0L"
;
case
"Float"
:
return
"0F"
;
case
"Double"
:
return
"0D"
;
case
"Char"
:
return
"0.toChar()"
;
case
"Boolean"
:
return
"false"
;
case
"Int"
:
case
"Byte"
:
case
"Short"
:
default
:
return
"0"
;
}
}
@Override
public
String
getTypeConsideringPrimitive
(
MappingContext
mappingContext
,
NamedDefinition
namedDefinition
,
...
...
@@ -143,7 +108,7 @@ public class KotlinGraphQLTypeMapper implements GraphQLTypeMapper {
if
(
computedTypeName
.
startsWith
(
KOTLIN_UTIL_LIST
)
&&
!
graphqlTypeName
.
endsWith
(
KOTLIN_UTIL_NULLABLE
))
{
String
modelClassNameWithPrefixAndSuffix
=
DataModelMapper
.
getModelClassNameWithPrefixAndSuffix
(
mappingContext
,
graphqlTypeName
);
if
(
computedTypeName
.
contains
(
modelClassNameWithPrefixAndSuffix
+
KOTLIN_UTIL_NULLABLE
)
||
computedTypeName
.
contains
(
graphqlTypeName
+
KOTLIN_UTIL_NULLABLE
)){
computedTypeName
.
contains
(
graphqlTypeName
+
KOTLIN_UTIL_NULLABLE
))
{
return
computedTypeName
;
}
if
(!
computedTypeName
.
contains
(
modelClassNameWithPrefixAndSuffix
+
KOTLIN_UTIL_NULLABLE
)
&&
computedTypeName
.
contains
(
modelClassNameWithPrefixAndSuffix
))
{
...
...
@@ -157,4 +122,9 @@ public class KotlinGraphQLTypeMapper implements GraphQLTypeMapper {
return
computedTypeName
;
}
@Override
public
ValueMapper
getValueMapper
()
{
return
valueMapper
;
}
}
src/main/java/com/kobylynskyi/graphql/codegen/mapper/GraphQLTypeMapper.java
浏览文件 @
5846fe20
...
...
@@ -6,9 +6,20 @@ import com.kobylynskyi.graphql.codegen.model.MultiLanguageDeprecated;
import
com.kobylynskyi.graphql.codegen.model.NamedDefinition
;
import
com.kobylynskyi.graphql.codegen.model.definitions.ExtendedDefinition
;
import
com.kobylynskyi.graphql.codegen.utils.Utils
;
import
graphql.language.*
;
import
graphql.language.Argument
;
import
graphql.language.Directive
;
import
graphql.language.DirectivesContainer
;
import
graphql.language.ListType
;
import
graphql.language.NamedNode
;
import
graphql.language.NonNullType
;
import
graphql.language.Type
;
import
graphql.language.TypeName
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* Map GraphQL type to language-specific type (java/scala/kotlin/etc)
...
...
@@ -116,17 +127,13 @@ public interface GraphQLTypeMapper {
* @param typeParameter Parameter of generics type
* @return type wrapped into generics
*/
String
getGenericsString
(
MappingContext
mappingContext
,
String
genericType
,
String
typeParameter
);
/**
* Map value of the directive argument
*
* @param mappingContext Global mapping context
* @param dirArg Directive argument
* @param argumentValueFormatter Formatter of the directive argument
* @return formatted value
*/
String
mapDirectiveArgumentValue
(
MappingContext
mappingContext
,
Argument
dirArg
,
String
argumentValueFormatter
);
default
String
getGenericsString
(
MappingContext
mappingContext
,
String
genericType
,
String
typeParameter
)
{
if
(
genericType
.
contains
(
"%s"
))
{
return
String
.
format
(
genericType
,
typeParameter
);
}
else
{
return
String
.
format
(
"%s<%s>"
,
genericType
,
typeParameter
);
}
}
/**
* Convert GraphQL type to a corresponding language-specific type
...
...
@@ -297,7 +304,7 @@ public interface GraphQLTypeMapper {
if
(
argumentValueFormatter
!=
null
)
{
directiveAnnotationMapped
=
directiveAnnotationMapped
.
replace
(
String
.
format
(
"{{%s%s}}"
,
dirArg
.
getName
(),
argumentValueFormatter
),
mapDirectiveArgumentValue
(
mappingContext
,
dirArg
,
argumentValueFormatter
));
getValueMapper
().
map
(
mappingContext
,
dirArg
.
getValue
(),
null
,
argumentValueFormatter
));
}
}
directiveAnnotationsMapped
.
add
(
directiveAnnotationMapped
);
...
...
@@ -327,5 +334,6 @@ public interface GraphQLTypeMapper {
.
orElse
(
null
);
}
ValueMapper
getValueMapper
();
}
src/main/java/com/kobylynskyi/graphql/codegen/scala/ScalaGraphQLTypeMapper.java
浏览文件 @
5846fe20
...
...
@@ -6,7 +6,6 @@ import com.kobylynskyi.graphql.codegen.model.MappingContext;
import
com.kobylynskyi.graphql.codegen.model.NamedDefinition
;
import
com.kobylynskyi.graphql.codegen.model.graphql.GraphQLOperation
;
import
com.kobylynskyi.graphql.codegen.utils.Utils
;
import
graphql.language.Argument
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -96,13 +95,13 @@ public class ScalaGraphQLTypeMapper implements GraphQLTypeMapper {
}
@Override
public
String
mapDirectiveArgumentValue
(
MappingContext
mappingContext
,
Argument
dirArg
,
String
argumentValueFormatter
)
{
return
valueMapper
.
map
(
mappingContext
,
dirArg
.
getValue
(),
null
,
argumentValueFormatter
);
public
boolean
addModelValidationAnnotationForType
(
String
possiblyPrimitiveType
)
{
return
!
ScalaGraphQLTypeMapper
.
isScalaPrimitive
(
possiblyPrimitiveType
);
}
@Override
public
boolean
addModelValidationAnnotationForType
(
String
possiblyPrimitiveType
)
{
return
!
ScalaGraphQLTypeMapper
.
isScalaPrimitive
(
possiblyPrimitiveType
)
;
public
ValueMapper
getValueMapper
(
)
{
return
valueMapper
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录