# Apollo Casting Issue with GraphQLNullable Types(InputDict)

**URL:** <https://community.apollographql.com/t/apollo-casting-issue-with-graphqlnullable-types-inputdict/6116>\
**Category:** Client SDKs\
**Tags:** client, mobile, ios\
**Created:** [April 10, 2023, 8:07pm UTC](https://community.apollographql.com/t/apollo-casting-issue-with-graphqlnullable-types-inputdict/6116 "2023-04-10T20:07:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![geeksweep](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/geeksweep/32/4052_2.png) [@geeksweep](https://community.apollographql.com/u/geeksweep)\
**Post date:** [April 10, 2023, 8:07pm UTC](https://community.apollographql.com/t/apollo-casting-issue-with-graphqlnullable-types-inputdict/6116/1 "2023-04-10T20:07:04Z")

</div>

I seem to be having an issue with casting when creating/initializing my data.

> struct SearchUserInput: InputObject {  
> public private(set) var \_\_data: InputDict
> 
> ```
> public init(_ data: InputDict) {
> __data = data
> }
> 
> public init(
> birthday: GraphQLNullable<DateTime> = nil,
> email: GraphQLNullable<String> = nil,
> name: String,
> phone: GraphQLNullable<String> = nil
> ) {
> __data = InputDict([
> "birthday": birthday,
> "email": email,
> "name": name,
> "phone": phone
> ])
> }
> 
> ```

where InputDict value is of type **GraphQLOperationVariableValue**

so when doing this:

> SearchUserInput(birthday: input.birthday, email: input.email, name: input.name)

i get the error:

> **Could not cast value of type ‘Swift.Optional\<ApolloAPI.GraphQLOperationVariableValue\>’ (0x119d50448) to ‘ApolloAPI.GraphQLNullable\<Swift.String\>’ (0x119d52330).**

name seems to work (basic Swift string) but the GraphQLNullable types seem to be where the issue is. Does the generated model need to change here or what need to happen to make this work?

the wrapper code for InputDict is:

> /// A structure that wraps the underlying data dictionary used by `InputObject`s.
> 
> **public**  **struct** InputDict: GraphQLOperationVariableValue, Hashable {
> 
> **private**  **var** data: [String: GraphQLOperationVariableValue]
> 
> **public**  **init** (\_ data: [String: GraphQLOperationVariableValue] = [:]) {
> 
> **self**.data = data
> 
> }
> 
> **public**  **var** \_jsonEncodableValue: ( **any** JSONEncodable)? { data.\_jsonEncodableObject }
> 
> **public**  **subscript** \<T: GraphQLOperationVariableValue\>(key: String) → T {
> 
> **get** { data[key] **as**! T }
> 
> **set** { data[key] = newValue }
> 
> }
> 
> **public**  **static**  **func** == (lhs: InputDict, rhs: InputDict) → Bool {
> 
> lhs.data.\_jsonEncodableValue?.\_jsonValue == rhs.data.\_jsonEncodableValue?.\_jsonValue
> 
> }
> 
> **public**  **func** hash(into hasher: **inout** Hasher) {
> 
> hasher.combine(data.\_jsonEncodableValue?.\_jsonValue)
> 
> }

so does that mean you can only send in values that are Bool or String in the key,value pairs?

---

<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:49pm UTC](https://community.apollographql.com/t/apollo-casting-issue-with-graphqlnullable-types-inputdict/6116/2 "2025-02-06T20:49:10Z")

</div>


