Apollo ios codegen 生成可选值
Posted
技术标签:
【中文标题】Apollo ios codegen 生成可选值【英文标题】:Apollo ios codegen generates optional values 【发布时间】:2021-09-02 07:33:04 【问题描述】:我正在尝试所有最新版本的 apollo-ios,但我想解决这个挥之不去的问题:我不断获得可选值(见下图)。
这是我探索过的(但仍然找不到原因)
当我创建表时,Nullable 为 false。然后,我创建了一个供公众访问的视图。
使用 apollo schema:download 命令,生成的 json 如下:schema.json
使用 graphqurl 命令,生成的 schema.graphql 如下:schema.graphql。这是sn-p。
"""
columns and relationships of "schedule"
"""
type schedule
activity: String
end_at: timestamptz
id: Int
"""An array relationship"""
speakers(
"""distinct select on columns"""
distinct_on: [talk_speakers_view_select_column!]
"""limit the number of rows returned"""
limit: Int
"""skip the first n rows. Use only with order_by"""
offset: Int
"""sort the rows by one or more columns"""
order_by: [talk_speakers_view_order_by!]
"""filter the rows returned"""
where: talk_speakers_view_bool_exp
): [talk_speakers_view!]!
start_at: timestamptz
talk_description: String
talk_type: String
title: String
我怀疑 id: Int
在架构中缺少 !
,这是 codegen 将其解释为可选的原因。但我也可能是错的。这是完整参考的 repo https://github.com/vinamelody/MyApolloTest/tree/test
【问题讨论】:
【参考方案1】:这是因为 Postgres 出于某种未知原因将视图列标记为显式可空,而不管底层列是否可空。
Vamshi(核心 Hasura 服务器开发)在本期中对此进行了解释: https://github.com/hasura/graphql-engine/issues/1965
你不需要那个视图——它和查询一样:
query
talks(
where: activity: _like: "iosconfig21%" ,
order_by: start_at: "asc"
)
id
title
start
<rest of fields>
除了现在您需要在 Hasura 元数据中管理一个视图,并像常规表一样,在它从中选择的表的顶部创建权限。反正我的 0.02 美元。
如果您真的坚持在 JSON 响应中将其称为“调度”,您甚至可以使用 GraphQL 别名 https://graphql.org/learn/queries/
【讨论】:
感谢您在他们的 github 上指出问题链接。这确实是一种反特征:(以上是关于Apollo ios codegen 生成可选值的主要内容,如果未能解决你的问题,请参考以下文章
Apollo 的检查并运行 apollo-codegen.sh 不起作用?
从 graphql-codegen 获取类似于 apollo codegen 生成的类型
为啥 apollo client:codegen 不生成类型?