Parsing JsonField fails in Swift

Hi,

I want to represent a content with a list is String. I used the datocms-plugin-typed-list and created a field bullets with that type.

In the content editor and in the graphql response, it looks as I’d expect: it’s a list of strings.

{
  "data": {
    "impact": {
      "bullets": [
        "First item",
        "Second item"
      ]
    }
  }
}

However, in the client iOS application, the generated native type is

public var bullets: JsonField { __data["bullets"] }

and JsonField is a typealias for String so the parsing of the response fails because Swift is trying to parse that array of strings into a String

 GraphQLExecutionError
  ▿ path : impact.bullets
    ▿ head : Optional<Node>
      ▿ some : <Node: 0x600003995100>
  ▿ underlying : JSONDecodingError
    ▿ couldNotConvert : 2 elements
      ▿ value : AnyHashable([AnyHashable("First item"), AnyHashable("Second item")])
        ▿ value : 2 elements
          ▿ 0 : AnyHashable("First item")
            - value : "First item"
          ▿ 1 : AnyHashable("Second item")
            - value : "Second item"
      - to : Swift.String

What is the correct way to allow a model property to have a list of Strings?

cheers
Jan

So to answer my self, I think it’s better to define an other model representing my Items and then reference an array of those models using the Link type

1 Like