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-graphql): update error handling #13177

Merged
merged 1 commit into from
Mar 27, 2024

Conversation

HuiSF
Copy link
Contributor

@HuiSF HuiSF commented Mar 25, 2024

Description of changes

See the commit message.

Issue #, if available

Description of how you validated changes

  1. unit tests
  2. manual tests in a sample app

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

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

@HuiSF HuiSF force-pushed the hui/chore/api-graphql/error-handling branch from e734eb0 to 46d2101 Compare March 25, 2024 23:55
AllanZhengYP
AllanZhengYP previously approved these changes Mar 26, 2024
Copy link
Contributor

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you @HuiSF

@HuiSF HuiSF force-pushed the hui/chore/api-graphql/error-handling branch from 46d2101 to c6f26fa Compare March 26, 2024 22:32
@HuiSF HuiSF marked this pull request as ready for review March 26, 2024 22:33
@HuiSF HuiSF requested review from a team as code owners March 26, 2024 22:33
@@ -2,7 +2,6 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"strictNullChecks": true,
"baseUrl": ".",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was add along with line 7-8 to resolve the type issues in the unit test suite. This baseUrl was actually not needed, and it caused an issue when IDE auto import symbols, it uses src/... path instead of relative paths.

await amplify.Auth.fetchAuthSession()
).tokens?.accessToken.toString();

if (!token) {
throw new Error(GraphQLAuthError.NO_FEDERATED_JWT);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This specific error was being swallowed by the catch clause. Rearranged the flow here to ensure both errors in this block to be able to surface.

@@ -335,7 +335,7 @@
"name": "[API] generateClient (AppSync)",
"path": "./dist/esm/api/index.mjs",
"import": "{ generateClient }",
"limit": "38.00 kB"
"limit": "38.5 kB"
Copy link
Contributor Author

@HuiSF HuiSF Mar 26, 2024

Choose a reason for hiding this comment

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

Mostly from the new messaging strings.

Copy link
Contributor

@svidgen svidgen left a comment

Choose a reason for hiding this comment

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

Can we follow this up with a PR to defined-behavior in the builder package(s) to solidify and make clear what our error handling contract looks like? (Both for .graphql() and a sampling of the .models.*.*() operations?)

  - Use GraphApiError to create errors to be thrown
    * error message field remained the same as before
    * added recoverySuggestion field for each error case
  - Created createGraphQLResultWithError utility for rewrapping error into GraphQLResult format
@HuiSF HuiSF force-pushed the hui/chore/api-graphql/error-handling branch from c6f26fa to 7087449 Compare March 27, 2024 19:33
Copy link
Contributor

@ashika112 ashika112 left a comment

Choose a reason for hiding this comment

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

Approving as admin on package.json - size change

@HuiSF HuiSF merged commit d4a48f1 into main Mar 27, 2024
30 checks passed
@HuiSF HuiSF deleted the hui/chore/api-graphql/error-handling branch March 27, 2024 20:40
Samaritan1011001 pushed a commit that referenced this pull request Apr 1, 2024
chore(api-graphql): improve error handling

  - Use GraphApiError to create errors to be thrown
    * error message field remained the same as before
    * added recoverySuggestion field for each error case
  - Created createGraphQLResultWithError utility for rewrapping error into GraphQLResult format
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

4 participants