How to initialise inline fragments manually?

I am trying to initiate inline fragments manually due to some api requirements like below.

let details = BalanceHistoryQuery.Data.Me.BalanceHistoryEvents.Edge.Node.Details(_dataDict: node.details.__data)

But details object has one inline fragment that is not getting initialised apart from that every field has value. for example: “__typename” has value.

This is details Apollo object

I am using 1.16 Apollo iOS.

I used to do it like this in Apollo 0.5
let details = BalanceHistoryQuery.Data.Me.BalanceHistoryEvent.Edge.Node.Detail(unsafeResultMap: node.details.resultMap)

I would need to see more of your code in order to know exactly what is going on here. But for more context on how this works, when using the unsafe init(_dataDict:) initializer, the fragments themselves aren’t actually “initialized”. The inline fragment accessors use the _asInlineFragment() function to determine if their data can be converted to a given fragment type, and if so, initializes and returns the inline fragment at that time.

The DataDict object keeps track of which fragments are fulfilled for the object using the DataDict._fulfilledFragments property. This is computed and set during the GraphQL execution step, which converts a network response into the generated model objects. The logic to determine which fragments are fulfilled is complicated, but primarily it looks at the __typename of the data and compares that against the known schema types to determine if the underlying type should have that fragment fulfilled (ie. does the type conform to the interface or match the concrete type of the fragment).

In this case, it seems you are initializing one model by passing it the __data of another model. Even if the model contains all of the fields necessary to fulfill the fragment you want, if it’s DataDict does not contain that type in it’s _fulfilledFragments list, you won’t be able to convert to that fragment using the as{{MyFragmentName}} property.

I hope that points you in the right direction. I’d also note that, depending on your use case and what you are trying to achieve here, using our generated selection set initializers may be a better approach.