-
Notifications
You must be signed in to change notification settings - Fork 312
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(ai): update useAIGeneration to add graphqlErrors before return #5816
Conversation
🦋 Changeset detectedLatest commit: dfe72eb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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.
The issue here reads as misuse of useDataState
and not necessarily an issue with useDataState
itself. Adding graphqlErrors
to the DataState
output itself can be done by massaging the output of useDataState
before returning from useAIGeneration
Ended up going with your solution, great call out, thanks for catching |
const { data, errors } = result as SingularReturnValue< | ||
Schema[Key]['returnType'] | ||
>; | ||
setGraphqlErrors(errors); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return data; | ||
}; | ||
|
||
return useDataState(updateAIGenerationStateAction, {}); | ||
const [data, handler] = useDataState( | ||
updateAIGenerationStateAction, | ||
undefined | ||
); | ||
return [{ ...data, graphqlErrors }, handler]; |
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.
Can simplify a bit and remove the graphqlErrors
state by returning result
directly from updateAIGenerationStateAction
and restructuring the hook return output, something like:
const { data, errors } =
(result?.data as SingularReturnValue<Schema[Key]['returnType']>) ?? {};
const output: [
state: GenerateState<Schema[Key]['returnType']>,
handleAction: (input: Schema[Key]['args']) => void,
] = [{ ...result, data, graphqlErrors: errors }, handler];
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.
Ah damn this is much cleaner, let me try that and ping you :)
Description of changes
Issue #, if available
Description of how you validated changes
Checklist
yarn test
passes and tests are updated/addeddocs
,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.