ios - Apollo ios codegen 生成可选值
问题描述
我正在尝试使用所有最新版本的 apollo-ios,但我想解决这个挥之不去的问题:我不断获得可选值(见下图)。
这是我探索过的(但仍然找不到whyyy)
当我创建表时,Nullable 为 false。然后,我创建了一个供公众访问的视图。
使用 apollo schema:download 命令,这是生成的 json:schema.json
使用 graphqurl 命令,这是生成的 schema.graphql:schema.graphql。这是片段。
"""
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 将其解释为可选的原因。但我也可能是错的。这是完整参考的回购https://github.com/vinamelody/MyApolloTest/tree/test
解决方案
这是因为 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/
推荐阅读
- git - 关于github中的版本控制
- json - 使用 swift 从 JSON 中删除不需要的数据
- git - 有多个同名文件时如何忽略一个文件
- java - 使用 Spring @RequestParam 无法在控制器中获取“#”符号
- snowflake-cloud-data-platform - 我怎么知道雪花“预览”功能何时会进入“生产”状态?
- graphviz - 如何动态增加 GraphViz 中两个节点之间的距离?
- flutter - Flutter:ThemeData 中bottomNavigationBar 的常用明暗主题
- azure-eventhub - 跨区域的 Azure 事件中心
- solr - Sitecore 将 Lucene 配置转换为 Solr 配置
- reactjs - 自动刷新函数从 Url 传递 id