Optional array GraphQLNullable init

I have a mutation that takes in an optional array thus:
mutation CreateBook($topics: [Int])
But the generated corresponding mutation file has this:
public var topics: GraphQLNullable<[Int?]>
I’m not sure how I can pass in topics to initialize this mutation correctly.

You will need to pass in your value as a GraphQLNullable enum value, which could be .none, .null, or .some(topics). I recommend checking out the documentation for GraphQLNullable here to give you a good understanding of how it works and what it provides.

Okay, maybe it’s easier to ask this:

How would you initialize this? GraphQLNullable<[Int?]>

I tried .init(arrayLiteral: someOptionalArray), but it’s giving me this error:
Cannot convert value of type '[Int?]' to expected argument type 'Array<Int?>.ArrayLiteralElement' (aka 'Optional<Int>')

You need to use one of the enum values described in the GraphQLNullable documentation, so something like:
topics = .some(someArray) or topics = .null etc

1 Like