Fixed refetch query for GetCommentThreadsByTargets (#336)

* Fixed refetch query for GetCommentThreadsByTargets

* Improvement : use apollo util getOperationName to de-hard code refetch queries arrays
This commit is contained in:
Lucas Bordeau
2023-06-19 17:44:05 +02:00
committed by GitHub
parent 96a53ad765
commit 950a0b77fe
7 changed files with 47 additions and 14 deletions

View File

@ -1,3 +1,4 @@
import { getOperationName } from '@apollo/client/utilities';
import styled from '@emotion/styled';
import { useRecoilState, useRecoilValue } from 'recoil';
import { v4 } from 'uuid';
@ -5,6 +6,8 @@ import { v4 } from 'uuid';
import { currentUserState } from '@/auth/states/currentUserState';
import { commentableEntityArrayState } from '@/comments/states/commentableEntityArrayState';
import { createdCommentThreadIdState } from '@/comments/states/createdCommentThreadIdState';
import { GET_COMPANIES } from '@/companies/services';
import { GET_PEOPLE } from '@/people/services';
import { AutosizeTextInput } from '@/ui/components/inputs/AutosizeTextInput';
import { useOpenRightDrawer } from '@/ui/layout/right-drawer/hooks/useOpenRightDrawer';
import { logError } from '@/utils/logs/logError';
@ -16,6 +19,8 @@ import {
useGetCommentThreadQuery,
} from '~/generated/graphql';
import { GET_COMMENT_THREAD } from '../services';
import { CommentThreadItem } from './CommentThreadItem';
const StyledContainer = styled.div`
@ -99,7 +104,11 @@ export function CommentThreadCreateMode() {
}),
),
},
refetchQueries: ['GetCommentThread', 'GetCompanies', 'GetPeople'],
refetchQueries: [
getOperationName(GET_COMPANIES) ?? '',
getOperationName(GET_PEOPLE) ?? '',
getOperationName(GET_COMMENT_THREAD) ?? '',
],
onCompleted(data) {
setCreatedCommentThreadId(data.createOneCommentThread.id);
openRightDrawer('comments');
@ -114,8 +123,7 @@ export function CommentThreadCreateMode() {
commentText,
createdAt: new Date().toISOString(),
},
// TODO: find a way to have this configuration dynamic and typed
refetchQueries: ['GetCommentThread'],
refetchQueries: [getOperationName(GET_COMMENT_THREAD) ?? ''],
onError: (error) => {
logError(
`In handleCreateCommentThread, createCommentMutation onError, error: ${error}`,