# Optional array GraphQLNullable init

**URL:** <https://community.apollographql.com/t/optional-array-graphqlnullable-init/6300>\
**Category:** Client SDKs\
**Tags:** mobile, ios\
**Created:** [May 25, 2023, 3:46pm UTC](https://community.apollographql.com/t/optional-array-graphqlnullable-init/6300 "2023-05-25T15:46:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![William](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/william/32/4314_2.png) [@William](https://community.apollographql.com/u/William)\
**Post date:** [May 25, 2023, 3:46pm UTC](https://community.apollographql.com/t/optional-array-graphqlnullable-init/6300/1 "2023-05-25T15:46:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ZachF-Apollo](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/zachf-apollo/32/4210_2.png) [@ZachF-Apollo](https://community.apollographql.com/u/ZachF-Apollo)\
**Post date:** [May 25, 2023, 4:23pm UTC](https://community.apollographql.com/t/optional-array-graphqlnullable-init/6300/2 "2023-05-25T16:23:16Z")

</div>

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](https://www.apollographql.com/docs/ios/docc/documentation/apolloapi/graphqlnullable) to give you a good understanding of how it works and what it provides.

---

<div class="post-metadata">

**Author:** ![William](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/william/32/4314_2.png) [@William](https://community.apollographql.com/u/William)\
**Post date:** [May 25, 2023, 8:07pm UTC](https://community.apollographql.com/t/optional-array-graphqlnullable-init/6300/3 "2023-05-25T20:07:24Z")

</div>

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>')`

---

<div class="post-metadata">

**Author:** ![ZachF-Apollo](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/zachf-apollo/32/4210_2.png) [@ZachF-Apollo](https://community.apollographql.com/u/ZachF-Apollo)\
**Post date:** [May 25, 2023, 8:40pm UTC](https://community.apollographql.com/t/optional-array-graphqlnullable-init/6300/4 "2023-05-25T20:40:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/optional-array-graphqlnullable-init/6300/5 "2025-02-06T20:48:51Z")

</div>

Archived on February 6, 2025, 8:48pm UTC


