-
Notifications
You must be signed in to change notification settings - Fork 733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migration from 0.53 to 1.15 missing factory methods & alternatives #3482
Comments
Hi @bsrz - it sounds like you're looking for the Selection Set Initializers feature. This provides an equivalent way to instantiate the generated models.
It's recommended to steer clear of the underscored properties/functions, such as the As an FYI - the reason you're always getting nil is because Try that and let me know if it still doesn't resolve your issue. |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better. |
@calvincestari thank you for the reply. {
"schemaNamespace": "GraphQL",
"operationManifest": {
"generateManifestOnCodeGeneration": true,
"path": "../../Generated/operation_ids.json",
"version": "persistedQueries"
},
"experimentalFeatures": {
"fieldMerging": [
"all"
],
"legacySafelistingCompatibleOperations": true
},
"input": {
"schemaSearchPaths": [
"./*.graphqls"
],
"operationSearchPaths": [
"../**/*.graphql"
]
},
"options": {
"pruneGeneratedFiles": true,
"selectionSetInitializers": {
"operations": true,
"namedFragments": true
},
},
"output": {
"schemaTypes": {
"moduleType": {
"other": {}
},
"path": "../../Generated/"
},
"operations": {
"inSchemaModule": {}
},
"testMocks": {
"none": {}
}
}
} I already have the If you see in the example I posted in the original comment, the inits with DataDict are the only inits available to me except for the ones that have an generated initializer:
I should mention that some of these types are Union types. |
Not at the moment no. I think you might be needing to use the If you're able to share some of the Swift generated types (such as |
yeah, so I've tried that too, these are all the tests I've written where the assertions fails because the property is continuously nil func test0() {
let internalLink = InternalOrExternalLinkFragment.AsAppPresentation_InternalLink(
text: InternalOrExternalLinkFragment.AsAppPresentation_InternalLink.Text(text: "AppAccountSupport"),
route: InternalOrExternalLinkFragment.AsAppPresentation_InternalLink.Route(
page: "AppAccountSupport",
params: .dictionary([:])
)
)
let intOrExt = InternalOrExternalLinkFragment(
_dataDict: internalLink.__data
)
let link0 = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent.Link.AsAppPresentation_InternalOrExternalLink(
_dataDict: intOrExt.__data
)
let link = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent.Link(
_dataDict: link0.__data
)
let data = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent(
icon: "time",
link: link
)
let finalButton = ButtonsRowFragment.Button(
_dataDict: data.__data
)
XCTAssertNotNil(finalButton.asAppPresentation_PrimaryButtonComponent?.link?.asAppPresentation_InternalOrExternalLink?.fragments.internalOrExternalLinkFragment)
}
func test1() {
let internalLink = InternalOrExternalLinkFragment.AsAppPresentation_InternalLink(
text: InternalOrExternalLinkFragment.AsAppPresentation_InternalLink.Text(text: "AppAccountSupport"),
route: InternalOrExternalLinkFragment.AsAppPresentation_InternalLink.Route(
page: "AppAccountSupport",
params: .dictionary([:])
)
).asRootEntityType
let link = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent.Link.AsAppPresentation_InternalOrExternalLink(
_dataDict: internalLink.__data
).asRootEntityType
let finalButton = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent(
icon: "time",
link: link
).asRootEntityType
XCTAssertNotNil(finalButton.asAppPresentation_PrimaryButtonComponent?.link?.asAppPresentation_InternalOrExternalLink?.fragments.internalOrExternalLinkFragment)
}
func test2() {
let otherLink = InternalLinkFragment(
text: InternalLinkFragment.Text(text: "AppAccountSupport"),
route: InternalLinkFragment.Route(
page: "AppAccountSupport",
params: .dictionary([:])
)
)
let link = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent.Link.AsAppPresentation_InternalOrExternalLink(
_dataDict: otherLink.__data
).asRootEntityType
let finalButton = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent(
icon: "time",
link: link
).asRootEntityType
XCTAssertNotNil(finalButton.asAppPresentation_PrimaryButtonComponent?.link?.asAppPresentation_InternalOrExternalLink?.fragments.internalOrExternalLinkFragment)
}
func test3() {
let data = DataDict(
data: [
"__typename": "AppPresentation_InternalOrExternalLink",
"text": "AppAccountSupport",
],
fulfilledFragments: [
ObjectIdentifier(ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent.Link.self),
ObjectIdentifier(ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent.Link.AsAppPresentation_InternalOrExternalLink.self),
]
)
let link = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent.Link.AsAppPresentation_InternalOrExternalLink(
_dataDict: data
).asRootEntityType
let finalButton = ButtonsRowFragment.Button.AsAppPresentation_PrimaryButtonComponent(
icon: "time",
link: link
).asRootEntityType
XCTAssertNotNil(finalButton.asAppPresentation_PrimaryButtonComponent?.link?.asAppPresentation_InternalOrExternalLink?.fragments.internalOrExternalLinkFragment)
} I've emailed you the full generated code for this type. Let me know if you find anything obvious. |
Question
We migrating our giant code base from 0.53 to 1.15.
There used to be generated factory methods to create types. We used those for tests. For example:
I'm trying to recreate the first button from the example above:
and not matter what I do,
value.asAppPresentation_PrimaryButtonComponent?.link?.asAppPresentation_InternalOrExternalLink
always ends up being nil. I feel like I've tried a ton of permutations but none of them work. I'm clearly missing something. Am I missing something completely obvious? It appears that using.__data
doesn't cary the typenames over? Are there any docs on how resultMap compares to DataDict?Any help would be very appreciated 🙌
The text was updated successfully, but these errors were encountered: