如何解决Apollo ios codegen 生成可选值
我正在尝试使用所有最新版本的 apollo-ios,但我想解决这个挥之不去的问题:我一直在获取可选值(见下图)。
这是我探索过的(但仍然找不到原因)
当我创建表时,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/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。