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

chore(ai): add graphql errors to useAIGeneration #5900

Merged
merged 5 commits into from
Oct 15, 2024

Conversation

dbanksdesign
Copy link
Contributor

Description of changes

Errors in GraphQL for AI generation routes are currently being sent to the client in the errors part of the response, but the useAIGeneration hook wasn't setting the hasError. I also moved the error to the message part of the hook. It seemed weird that there could be different places to check for the error message?

Issue #, if available

Description of how you validated changes

Checklist

  • Have read the Pull Request Guidelines
  • PR description included
  • yarn test passes and tests are updated/added
  • PR title and commit messages follow conventional commit syntax
  • If this change should result in a version bump, changeset added (This can be done after creating the PR.) This does not apply to changes made to docs, e2e, examples, or other private packages.

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

@dbanksdesign dbanksdesign requested a review from a team as a code owner October 14, 2024 04:05
Copy link

changeset-bot bot commented Oct 14, 2024

🦋 Changeset detected

Latest commit: 724244b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/ui-react-ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines 82 to 87
if (errors) {
hasError = true;
message = errors.map((error) => error.message).join(' ');
}

return [{ ...result, data, hasError, message }, handler];
Copy link
Member

Choose a reason for hiding this comment

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

Can we ever get into a case where useDataState's result has an error message and we also have graphqlErrors? In that case graphqlErrors would override that useDataState message?

Though I think that would only happen in the case where our previous call had graphqlErrors, then our next generation resulted in an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should be fine because the amplify data client (using appsync) will always return errors in the same way. I don't think there is another way to get an error from the data client.

Copy link
Member

Choose a reason for hiding this comment

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

Thinking useDataState is the wrong approach here for a handful of reasons:

  • output.hasError is true when the API call itself fails, which is why it's false handled in this use case
  • output.message exposes the error message of the failed API call
  • afaict handleGenerate is setting a subscription in a fire and forget fashion rather than using continuous calls to the useDataState handler to provide stateful data

Copy link
Member

@calebpollman calebpollman left a comment

Choose a reason for hiding this comment

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

🚢

@thaddmt
Copy link
Member

thaddmt commented Oct 15, 2024

I forgot my approval counts for nothing 😅

Comment on lines +93 to +94
data,
messages: errors,
Copy link
Member

@calebpollman calebpollman Oct 15, 2024

Choose a reason for hiding this comment

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

Late question and asking mostly out of curiosity, how do consumers correlate data and errors?

@dbanksdesign dbanksdesign merged commit 1421dde into main Oct 15, 2024
36 checks passed
@dbanksdesign dbanksdesign deleted the ai-generation-errors branch October 15, 2024 18:15
@github-actions github-actions bot mentioned this pull request Oct 15, 2024
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.

4 participants