Generate interfaces for schema types defined in schema in kotlin projects
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- graphql, kotlin
调研方向
首先跟踪 Kotlin 项目的 generateInterfaces 和 generateJava 任务,并查看相关 issue #200 以了解之前的上下文。当 Kotlin 项目可以通过 generateInterfaces 为 schema 定义的类型生成接口,并且通过适当的测试验证该行为时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
When I'm trying to generateInterfaces for kotlin language with use of generateJava task, they are not generated.
I saw ticket here that touch on this topic and it was stated that it is probably a feature of not a first priority.
I could probably add some context to highlight that this is pretty vital thing to have in kotlin based projects.
Let's take a look at the following setup:
type Team {
id: Int
parentTeam: Team!
childTeams: [Team!]!
}
Now I'm trying to organize my dataloaders and data fetchers as optimal as possible.
In kotlin projects I have the following options and none of them looks optimal to me:
-
Option 1: manually create interface for your types (not optimal from contract/schema perspective)
- Create
ITeaminterface:
interface ITeam { id: Int parentTeam: Team childTeams: [Team!]! } type Team implemets ITeam { id: Int parentTeam: ITeam! childTeams: [Team!]! }Then data fetcher will be something like this:
@DgsData fun fetchParentTeam( dfe: DgsDataFetchingEnvironment ): CompletableFuture<Team> { val parentTeamId = dfe.getSource<Team>()?.parentTeam?.id return parentTeamId?.let { val loader: DataLoader<Long, Team> = dfe.getDataLoader(TeamDataLoader::class.java) loader.load(it) } }In case of relational database on
val parentTeamId = dfe.getSource<Team>()?.parentTeam?.idline I have access to parent team id since it is...toOnerelation and I don't need additional db queries to find it out.Also in data loader I do this:
@DgsDataLoader class TeamDataLoader( private val teamService: TeamService, private val gqlDtoBuilder: GQLDtoBuilder ) : MappedBatchLoader<Long, Team?> { override fun load(keys: MutableSet<Long>): CompletionStage<Map<Long, Team?>> { return CompletableFuture.supplyAsync { val results = teamService .getTeamsByIds(keys) .associate { it.id to gqlDtoBuilder.build(it) } .toMutableMap<Long, Team?>() for (key in keys) { results.putIfAbsent(key, null) } results } } }Looks good so far but the query for such a schema is not that concise as it could be:
teams { parentTeam { id ... on Team { parentTeam // etc. } } }From client perspective it looks weird and doesn't feel right when performance backend stuff affects contract with external clients (another backend services, frontend, etc)
- Create
-
Option 2: not optimal from support perspective. We can use local context and it is good all in all but in a long team it looks a bit error prone since every time we do a fetch of
Teamtype we need to remember to pass local context in all data/entity fetchers. If we don't do that we got an error. Moreover if we get an additional field in schema liketeamLeadwe need to populate it everywhere we populate local context.
If project's graphql contract is not 100% covered with tests it could lead to errors on test/prod environments and with graphql request variety it is pretty difficult to keep test coverage on these high levels. -
Option 3: not optimal from performance perspective. We can fetch
parentTeamwith use of separate join db query and separate data loader logic but it is obviously not that fast and produces extra load on microservice itself and database. -
Option 4: looks promising, but has some java<->kotlin interop issues. In this cause we have the same interfaces like in option 1 but clients don't see them and we can extend them the way we like and use to carry info required by fetchers.
-
Option 5: ideal option. Have interfaces generated for kotlin projects too. The same as option 4, but java<->kotlin interop boilerplate is not there.
Could you please share if there any plans to make generateInterfaces available for kotlin?
Thank you very much!
- 主要语言
- Kotlin
- 星标
- 220
- 派生
- 123
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 23
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Netflix/dgs-codegen 的其他 Issue
-
Integer default values on `Float` input fields generate code that does not compile (Java and Kotlin)可能已有人在做 @0z5a 于 9 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 72/100
Netflix/dgs-codegen#1015 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 45/100
Netflix/dgs-codegen#1002 ·
维护者通常 1 天内回复
-
Object literal default value on a custom scalar fails with NoSuchElementException可能已有人在做 @nboisnea 于 49 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
Netflix/dgs-codegen#982 ·
维护者通常 1 天内回复
-
HV000271: Using @Valid on a container (java.util.List) is deprecated. You should apply the annotation on the type argument(s).可能已有人在做 @jiholee17 于 73 天前认领。 未关闭enhancement
Netflix/dgs-codegen#954 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Support Immutable java Data Types可能重新可做 @jiholee17 于 184 天前认领,目前没有进行中的 PR。 未关闭enhancement
Netflix/dgs-codegen#944 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 Netflix/dgs-codegen 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
help wanted
难度 2/5 1-3 小时 新手友好度 88/100
DojoCodingLabs/hermit#23 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
signalapp/Signal-Android#15148 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 1/5 1 小时以内 新手友好度 78/100
PranshulGG/WeatherMaster#1266 · 3 条评论 ·
维护者通常 1 天内回复