-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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(data): update all operations to return flattened response, null
, or empty array response on error
#13179
Conversation
|
||
export function getFactory( | ||
client: ClientWithModels, | ||
modelIntrospection: ModelIntrospectionSchema, | ||
model: SchemaModel, | ||
operation: ModelOperation, | ||
useContext = false | ||
useContext = false, |
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.
We have always used trailing commas, but this PR removed them during a Prettier upgrade.
Will discuss during standup, but it's worth us making a decision on this now so we can either 1) reformat the library, or 2) change our local config to avoid these changes being included in future PRs
/** | ||
* Handle errors for list and index query operations | ||
*/ | ||
export function handleListGraphQlError(error: any) { |
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.
I considered using a single utility that accepted a flag (something like isList
), but decided against it as this approach seems slightly less error prone / more straightforward to parse. This is only a slight preference, so if someone feels more strongly that handleListGraphQlError
and handleSingularGraphQlError
should be a single utility function, I'm happy to combine them.
null
or empty array response on error
* if `flattenedResult`, result is an actual record: | ||
*/ | ||
if (flattenedResult) { | ||
// TODO: custom selection set. current selection set is default selection set only |
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 the same TODO that can be found with the existing implementation in the try
block
if (options?.selectionSet) { | ||
return { data: flattenedResult, errors }; | ||
} else { | ||
// TODO: refactor to avoid destructuring here |
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 the same TODO that can be found with the existing implementation in the try
block
null
or empty array response on errornull
, or empty array response on error
Description of changes
NOTE:
These changes have been ported over to the
amplify-api-next
repo, and a new PR has been created for the tests added to this repo:https://github.com/aws-amplify/amplify-api-next/pull/145/files
#13279
fix(data): update all operations to return flattened response, null, or empty array response on error
Note: unit tests will not pass until the related types PR has been merged.
As of today, there are several response shapes for
data
returned to the customer when an error is present.data
can be:null
null
value:{ getPost: null }
{ getPost: { id: '1', title: 'Hello, World!' } }
This PR handles each of the above scenarios for all model operations by flattening the error response when necessary, and returning either
null
or an empty array unless actual data is present.Issue #, if available
Description of how you validated changes
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.