-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: API.swift compatibility with AWSAPIPlugin #630
Conversation
fe0e112
to
8b46ccf
Compare
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## main #630 +/- ##
==========================================
+ Coverage 84.44% 85.89% +1.45%
==========================================
Files 152 153 +1
Lines 6435 7495 +1060
Branches 1383 1956 +573
==========================================
+ Hits 5434 6438 +1004
- Misses 901 964 +63
+ Partials 100 93 -7
... and 116 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
8b46ccf
to
e9cb77e
Compare
209646f
to
114ce84
Compare
extension GraphQLSelectionSet { | ||
public init(from decoder: Decoder) throws { | ||
if let jsonObject = try? APISwiftJSONValue(from: decoder) { | ||
let encoder = JSONEncoder() | ||
let jsonData = try encoder.encode(jsonObject) | ||
let decodedDictionary = try JSONSerialization.jsonObject(with: jsonData, options: []) as! [String: Any] | ||
let optionalDictionary = decodedDictionary.mapValues { $0 as Any? } | ||
|
||
self.init(snapshot: optionalDictionary) | ||
} else { | ||
self.init(snapshot: [:]) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the custom decoder was added. It uses an internally defined JSON value type called APISwiftJSONValue
(to avoid developer defined "JSONValue" type) to get the data into an JSON object before serializing and deserializing back to the expected output a Snapshot (typealias for [String:Any?]))
114ce84
to
f20cfdc
Compare
Are there any unit tests covering this change? |
good point, @dpilch just added one to verify the |
d1e2cb8
to
5eefab1
Compare
Description of changes
Currently developers that have an AppSync backend that was not provisioned with Amplify CLI can still generate the API.swift file from the introspection schema. This file has a hard dependency on iOS AppSync SDK client.. The top of API.swift contains
imports AWSAppSync
.This file is pretty useful as it contains all the different operations available and components to successfully make a request, but cannot be used with Amplify's APIPlugin. This PR makes the API.swift file compatible with Amplify AWSAPIPlugin, removing the dependency on AppSync SDK.
We considered that if the developer has AppSync SDK and Amplify already in the same app, and API.swift was compilng due to AppSync SDK. The developer is most likely using AppSync SDK to interact with the backend, while the rest of Amplify (excluding AWSAPIPlugin) for the remaining plugins. If they did not add AWSAPIPlugin, there's no impact and they can upgrade to use AWSAPIPlugin when they are ready to.
if AWSAPIPlugin was added, it may have been
The upgrade guide is meant for both existing customers to move to AWSAPIPlugin and new customers that have built AppSync backends without using the Amplify's provisioning, see upgrade guide PR for more details: aws-amplify/docs#5649
Issue #, if available
Description of how you validated changes
Local testing:
amplify-dev
testingWe validate the new API.swift file compiles and works during runtime by the integration tests in the following PRs:
Tagged release
@aws-amplify/[email protected]
example of CLI required changes to create CLI tagged release: aws-amplify/amplify-cli@3e4d27a
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.