Created
June 6, 2020 13:37
-
-
Save sebsto/a81db362d06f5d7b3afc65b4c19048a3 to your computer and use it in GitHub Desktop.
Quick Hack on SelectionSet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// specific for my Data Model to unblock me. | |
// only tested on queries. | |
➜ Landmarks diff -c /Users/stormacq/Documents/amazon/code/amplify/amplify-ios//Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift ./Pods/Amplify/Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift | |
*** /Users/stormacq/Documents/amazon/code/amplify/amplify-ios//Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift Sat Jun 6 08:29:27 2020 | |
--- ./Pods/Amplify/Amplify/Categories/DataStore/Model/Schema/ModelSchema+Definition.swift Sat Jun 6 08:49:47 2020 | |
*************** | |
*** 31,36 **** | |
--- 31,45 ---- | |
return false | |
} | |
} | |
+ | |
+ public var isCustomType: Bool { | |
+ switch self { | |
+ case .customType: | |
+ return true | |
+ default: | |
+ return false | |
+ } | |
+ } | |
public static func from(type: Any.Type) -> ModelFieldType { | |
if type is String.Type { | |
➜ Landmarks diff -c /Users/stormacq/Documents/amazon/code/amplify/amplify-ios//AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift ./Pods/AWSPluginsCore/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift | |
*** /Users/stormacq/Documents/amazon/code/amplify/amplify-ios//AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift Sat Jun 6 08:29:27 2020 | |
--- ./Pods/AWSPluginsCore/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift Sat Jun 6 11:04:44 2020 | |
*************** | |
*** 33,44 **** | |
--- 33,61 ---- | |
withModelFields(fields) | |
} | |
+ func withCodable(_ field: ModelField) { | |
+ switch field.type { | |
+ case let .customType(codableType): | |
+ print("Extracted type \(codableType)") | |
+ print("GraphQL name \(field.graphQLName)") | |
+ self.addChild(settingParentOf: .init(value: .init(name: "latitude", fieldType: .value))) | |
+ self.addChild(settingParentOf: .init(value: .init(name: "longitude", fieldType: .value))) | |
+ // to.addChild(settingParentOf: .init(value: .init(name: "__typename", fieldType: .value))) | |
+ default: | |
+ preconditionFailure("This should not happen") | |
+ } | |
+ } | |
+ | |
func withModelFields(_ fields: [ModelField]) { | |
fields.forEach { field in | |
if field.isAssociationOwner, let associatedModel = field.associatedModel { | |
let child = SelectionSet(value: .init(name: field.name, fieldType: .model)) | |
child.withModelFields(associatedModel.schema.graphQLFields) | |
self.addChild(settingParentOf: child) | |
+ } else if field.type.isCustomType { | |
+ let child = SelectionSet(value: .init(name: field.name, fieldType: SelectionSetFieldType.model)) | |
+ child.withCodable(field) | |
+ self.addChild(settingParentOf: child) | |
} else { | |
self.addChild(settingParentOf: .init(value: .init(name: field.graphQLName, fieldType: .value))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment