0

I'm trying with all the latest version of apollo-ios but i'd like to solve this one lingering problem: I keep getting optional values (see image below).

xcode

Here's what I've explored (but still can't find whyyy)

When I created the table, Nullable is false. Then, I create a view which is for public to access it.

table

view

With apollo schema:download command, here's the generated json: schema.json

With graphqurl command, here's the generated schema.graphql: schema.graphql. Here's the snippet.

"""
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
}

I am suspecting that it looks like id: Int is missing ! in the schema, is the cause of codegen interpreting it as optional. But I could be wrong too. Here's the repo for the complete reference https://github.com/vinamelody/MyApolloTest/tree/test

Vina
  • 920
  • 1
  • 9
  • 12

1 Answers1

1

It's because Postgres marks view columns as explicitly nullable, regardless of the underlying column nullability, for some unknown reason.

Vamshi (core Hasura server dev) explains it here in this issue: https://github.com/hasura/graphql-engine/issues/1965

You don't need that view though -- it's the same as doing a query:

query {
  talks(
    where: { activity: { _like: "iosconfig21%" } },
    order_by: { start_at: "asc" }
  }) {
    id
    title
    start
    <rest of fields>
}

Except now you have a view you need to manage in your Hasura metadata and create permissions for, like a regular table, on top of the table it's selecting from. My $0.02 anyways.

You can even use a GraphQL alias if you really insist on it being called "schedule" in the JSON response https://graphql.org/learn/queries/

Gavin Ray
  • 595
  • 1
  • 3
  • 10
  • Thanks for pointing the issue link on their github. This is indeed, a kind of anti-feature :( – Vina Jun 24 '21 at 13:57