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): do not include null values in ModelMutations.create #2504
fix(api): do not include null values in ModelMutations.create #2504
Conversation
Codecov Report
@@ Coverage Diff @@
## next #2504 +/- ##
==========================================
+ Coverage 56.19% 56.21% +0.02%
==========================================
Files 115 115
Lines 6987 6991 +4
==========================================
+ Hits 3926 3930 +4
Misses 3061 3061
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
What about update
? I'm guessing that would suffer the same problem.
You're correct that we should be setting null
in cases where the user passed null
but it's possible to distinguish these cases precisely. In the variables
map, the presence of that field's key indicates the user passed a value for it. You need to check that instead of the value.
final variables = {
'setNull': null,
};
// Doing this gives no insight about the user's intentions.
print(variables['setNull'] == null); // true
print(variables['doNotSetNull'] == null); // true
// Here we see what their intentions were.
print(variables.containsKey('setNull')); // true
print(variables.containsKey('doNotSetNull')); // false
…lMutations helpers" This reverts commit dd58058.
- fix(auth)!: Fetch Auth Session offline behavior ([aws-amplify#2585](aws-amplify#2585)) - fix(api): do not include null values in ModelMutations.create ([aws-amplify#2504](aws-amplify#2504)) - fix(api): model helpers use targetNames in schemas with CPK enabled ([aws-amplify#2559](aws-amplify#2559)) - fix(auth): Clear credentials before redirect on Web ([aws-amplify#2603](aws-amplify#2603)) - fix(auth): Refresh token in non-state machine calls ([aws-amplify#2572](aws-amplify#2572)) - fix(authenticator): ARB syntax ([aws-amplify#2560](aws-amplify#2560)) - fix(aws_common): AWSFile contentType getter should not throw exception - fix(datastore): prevent unhandled exception crashing App rebuilding sync expression - fix(storage): incorrect transferred bytes emitted from upload task - feat(analytics): Legacy data migration of Pinpoint Endpoint ID ([aws-amplify#2489](aws-amplify#2489)) - feat(smithy_aws): add copyWith to S3ClientConfig - feat(storage): allow configuring transfer acceleration Updated-Components: Amplify Flutter, Amplify Dart, Amplify UI, DB Common, Secure Storage, AWS Common, Smithy, Worker Bee
- fix(auth)!: Fetch Auth Session offline behavior ([aws-amplify#2585](aws-amplify#2585)) - fix(api): do not include null values in ModelMutations.create ([aws-amplify#2504](aws-amplify#2504)) - fix(api): model helpers use targetNames in schemas with CPK enabled ([aws-amplify#2559](aws-amplify#2559)) - fix(auth): Clear credentials before redirect on Web ([aws-amplify#2603](aws-amplify#2603)) - fix(auth): Refresh token in non-state machine calls ([aws-amplify#2572](aws-amplify#2572)) - fix(authenticator): ARB syntax ([aws-amplify#2560](aws-amplify#2560)) - fix(aws_common): AWSFile contentType getter should not throw exception - fix(datastore): prevent unhandled exception crashing App rebuilding sync expression - fix(storage): incorrect transferred bytes emitted from upload task - feat(analytics): Legacy data migration of Pinpoint Endpoint ID ([aws-amplify#2489](aws-amplify#2489)) - feat(smithy_aws): add copyWith to S3ClientConfig - feat(storage): allow configuring transfer acceleration Updated-Components: Amplify Flutter, Amplify Dart, Amplify UI, DB Common, Secure Storage, AWS Common, Smithy, Worker Bee
* chore(repo): Update component definition Adds `amplify_api_dart` to the mix and creates components for DB Common, Secure Storage, and AWS Common * fix(aft): Update changelog logic For the version commit message changelog, only include publishable packages. Also updates base ref logic to ensure packages can be moved in and out of components. * chore(version): Bump version - fix(auth)!: Fetch Auth Session offline behavior ([#2585](#2585)) - fix(api): do not include null values in ModelMutations.create ([#2504](#2504)) - fix(api): model helpers use targetNames in schemas with CPK enabled ([#2559](#2559)) - fix(auth): Clear credentials before redirect on Web ([#2603](#2603)) - fix(auth): Refresh token in non-state machine calls ([#2572](#2572)) - fix(authenticator): ARB syntax ([#2560](#2560)) - fix(aws_common): AWSFile contentType getter should not throw exception - fix(datastore): prevent unhandled exception crashing App rebuilding sync expression - fix(storage): incorrect transferred bytes emitted from upload task - feat(analytics): Legacy data migration of Pinpoint Endpoint ID ([#2489](#2489)) - feat(smithy_aws): add copyWith to S3ClientConfig - feat(storage): allow configuring transfer acceleration Updated-Components: Amplify Flutter, Amplify Dart, Amplify UI, DB Common, Secure Storage, AWS Common, Smithy, Worker Bee --------- Co-authored-by: Dillon Nys <nydillon@amazon.com>
Addresses #2492
GraphQL model helpers have mutation helpers that generate JSON input for mutation variables based on models'
toJson()
methods. In the case of the model having a null value for an owner field, that null value gets passed to AppSync which will reject the mutation. This PR removes null fields from input variables when callingModelMutations.create()
. That avoids the error for the case of owner fields and generally simplifies client logic, allowing the server to set null values if omitted.Note the original issue states "Model helpers should not pass null fields" but I believe that in general, there are valid cases of setting null values in mutations, like unsetting a nullable field that had previously been set to something non-null. For that reason, this PR only scopes the fix to create operations, which does not have any need to explicitly send null values.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.