Skip to content
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

fix(API): pass authMode used for lazy loading functionality #3690

Merged
merged 2 commits into from
May 17, 2024

Conversation

lawmicha
Copy link
Member

@lawmicha lawmicha commented May 13, 2024

Issue #

#3677

Description

Lazy Loading functionality is built on metadata passed to it during decoding. For example, the hasMany list will contain the parent's identifiers and the apiName to reconstruct the request when lazy loading. The belongsTo lazy model will contain its identifiers and the apiName used to when the child model was retrieved.

The issue is with the new authMode parameter, the authMode was not being passed down to the lazy types (#3677 (comment))

// default auth type is APIKey.
let message = try await Amplify.API.query(request: .get(Message.self, byId: id, authMode: .amazonCognitoUserPools)).get() // use userPool auth
let sender = try await message.sender  // with fix, uses user pool auth. without fix, uses default API key auth from config
let space = try await message.space // with fix, uses user pool auth. without fix, uses default API key auth from config

General Checklist

  • Added new tests to cover change, if needed
  • Build succeeds with all target using Swift Package Manager
  • All unit tests pass
  • All integration tests pass
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)
  • Documentation update for the change if required
  • PR title conforms to conventional commit style
  • New or updated tests include Given When Then inline code documentation and are named accordingly testThing_condition_expectation()
  • If breaking change, documentation/changelog update with migration instructions

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

codecov bot commented May 13, 2024

Codecov Report

Attention: Patch coverage is 71.69811% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 68.52%. Comparing base (d888124) to head (484e5f8).
Report is 12 commits behind head on main.

Files Patch % Lines
...urces/AWSAPIPlugin/Core/AppSyncModelMetadata.swift 46.15% 7 Missing ⚠️
...gin/Support/Utils/GraphQLRequest+toListQuery.swift 50.00% 3 Missing ⚠️
...ources/AWSAPIPlugin/Core/AppSyncListProvider.swift 86.66% 2 Missing ⚠️
...urces/AWSAPIPlugin/Core/AppSyncModelProvider.swift 60.00% 2 Missing ⚠️
...ort/Decode/GraphQLResponseDecoder+DecodeData.swift 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3690      +/-   ##
==========================================
+ Coverage   68.37%   68.52%   +0.14%     
==========================================
  Files        1096     1096              
  Lines       38089    38120      +31     
==========================================
+ Hits        26044    26122      +78     
+ Misses      12045    11998      -47     
Flag Coverage Δ
API_plugin_unit_test 68.97% <71.69%> (+0.01%) ⬆️
AWSPluginsCore 65.81% <ø> (+0.13%) ⬆️
Amplify 48.19% <ø> (ø)
Analytics_plugin_unit_test 84.52% <ø> (ø)
Auth_plugin_unit_test 79.36% <ø> (-0.11%) ⬇️
CoreMLPredictions_plugin_unit_test 61.15% <ø> (ø)
DataStore_plugin_unit_test 82.39% <ø> (+0.94%) ⬆️
Geo_plugin_unit_test 73.50% <ø> (ø)
Logging_plugin_unit_test 62.87% <ø> (ø)
Predictions_plugin_unit_test 37.31% <ø> (ø)
PushNotifications_plugin_unit_test 86.21% <ø> (ø)
Storage_plugin_unit_test 76.75% <ø> (ø)
unit_tests 68.52% <71.69%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lawmicha lawmicha marked this pull request as ready for review May 17, 2024 16:39
@lawmicha lawmicha requested a review from a team as a code owner May 17, 2024 16:39
thisisabhash
thisisabhash previously approved these changes May 17, 2024
@@ -43,7 +46,7 @@ public struct AppSyncListPayload: Codable {
// `GraphQLFilter`.
guard let filterVariablesData = try? encoder.encode(filterValue),
let filterVariablesJSON = try? JSONSerialization.jsonObject(with: filterVariablesData)
as? GraphQLFilter else {
as? [String: Any] else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Member Author

@lawmicha lawmicha May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've reverted it, when i was compiling earlier Xcode wasn't picking up GraphQLFilter properly from AWSPluginsCore. It is working now

@lawmicha lawmicha merged commit 4156bfb into main May 17, 2024
85 checks passed
@lawmicha lawmicha deleted the fix.lazy-load-auth-mode branch May 17, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants