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:
@ -1,15 +1,20 @@
|
|||||||
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { currentUserState } from '@/auth/states/currentUserState';
|
import { currentUserState } from '@/auth/states/currentUserState';
|
||||||
import { CommentThreadForDrawer } from '@/comments/types/CommentThreadForDrawer';
|
import { CommentThreadForDrawer } from '@/comments/types/CommentThreadForDrawer';
|
||||||
|
import { GET_COMPANIES } from '@/companies/services';
|
||||||
|
import { GET_PEOPLE } from '@/people/services';
|
||||||
import { AutosizeTextInput } from '@/ui/components/inputs/AutosizeTextInput';
|
import { AutosizeTextInput } from '@/ui/components/inputs/AutosizeTextInput';
|
||||||
import { logError } from '@/utils/logs/logError';
|
import { logError } from '@/utils/logs/logError';
|
||||||
import { isDefined } from '@/utils/type-guards/isDefined';
|
import { isDefined } from '@/utils/type-guards/isDefined';
|
||||||
import { isNonEmptyString } from '@/utils/type-guards/isNonEmptyString';
|
import { isNonEmptyString } from '@/utils/type-guards/isNonEmptyString';
|
||||||
import { useCreateCommentMutation } from '~/generated/graphql';
|
import { useCreateCommentMutation } from '~/generated/graphql';
|
||||||
|
|
||||||
|
import { GET_COMMENT_THREADS_BY_TARGETS } from '../services';
|
||||||
|
|
||||||
import { CommentThreadItem } from './CommentThreadItem';
|
import { CommentThreadItem } from './CommentThreadItem';
|
||||||
import { CommentThreadRelationPicker } from './CommentThreadRelationPicker';
|
import { CommentThreadRelationPicker } from './CommentThreadRelationPicker';
|
||||||
|
|
||||||
@ -67,12 +72,10 @@ export function CommentThread({ commentThread }: OwnProps) {
|
|||||||
commentText,
|
commentText,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
},
|
},
|
||||||
// TODO: find a way to have this configuration dynamic and typed
|
|
||||||
// Also it cannot refetch queries than are not in the cache
|
|
||||||
refetchQueries: [
|
refetchQueries: [
|
||||||
'GetCommentThreadsByTargets',
|
getOperationName(GET_COMPANIES) ?? '',
|
||||||
'GetCompanies',
|
getOperationName(GET_PEOPLE) ?? '',
|
||||||
'GetPeople',
|
getOperationName(GET_COMMENT_THREADS_BY_TARGETS) ?? '',
|
||||||
],
|
],
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
logError(
|
logError(
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
@ -5,6 +6,8 @@ import { v4 } from 'uuid';
|
|||||||
import { currentUserState } from '@/auth/states/currentUserState';
|
import { currentUserState } from '@/auth/states/currentUserState';
|
||||||
import { commentableEntityArrayState } from '@/comments/states/commentableEntityArrayState';
|
import { commentableEntityArrayState } from '@/comments/states/commentableEntityArrayState';
|
||||||
import { createdCommentThreadIdState } from '@/comments/states/createdCommentThreadIdState';
|
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 { AutosizeTextInput } from '@/ui/components/inputs/AutosizeTextInput';
|
||||||
import { useOpenRightDrawer } from '@/ui/layout/right-drawer/hooks/useOpenRightDrawer';
|
import { useOpenRightDrawer } from '@/ui/layout/right-drawer/hooks/useOpenRightDrawer';
|
||||||
import { logError } from '@/utils/logs/logError';
|
import { logError } from '@/utils/logs/logError';
|
||||||
@ -16,6 +19,8 @@ import {
|
|||||||
useGetCommentThreadQuery,
|
useGetCommentThreadQuery,
|
||||||
} from '~/generated/graphql';
|
} from '~/generated/graphql';
|
||||||
|
|
||||||
|
import { GET_COMMENT_THREAD } from '../services';
|
||||||
|
|
||||||
import { CommentThreadItem } from './CommentThreadItem';
|
import { CommentThreadItem } from './CommentThreadItem';
|
||||||
|
|
||||||
const StyledContainer = styled.div`
|
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) {
|
onCompleted(data) {
|
||||||
setCreatedCommentThreadId(data.createOneCommentThread.id);
|
setCreatedCommentThreadId(data.createOneCommentThread.id);
|
||||||
openRightDrawer('comments');
|
openRightDrawer('comments');
|
||||||
@ -114,8 +123,7 @@ export function CommentThreadCreateMode() {
|
|||||||
commentText,
|
commentText,
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
},
|
},
|
||||||
// TODO: find a way to have this configuration dynamic and typed
|
refetchQueries: [getOperationName(GET_COMMENT_THREAD) ?? ''],
|
||||||
refetchQueries: ['GetCommentThread'],
|
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
logError(
|
logError(
|
||||||
`In handleCreateCommentThread, createCommentMutation onError, error: ${error}`,
|
`In handleCreateCommentThread, createCommentMutation onError, error: ${error}`,
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
|
import { GET_COMPANIES } from '@/companies/services';
|
||||||
|
import { GET_PEOPLE } from '@/people/services';
|
||||||
import {
|
import {
|
||||||
useAddCommentThreadTargetOnCommentThreadMutation,
|
useAddCommentThreadTargetOnCommentThreadMutation,
|
||||||
useRemoveCommentThreadTargetOnCommentThreadMutation,
|
useRemoveCommentThreadTargetOnCommentThreadMutation,
|
||||||
} from '~/generated/graphql';
|
} from '~/generated/graphql';
|
||||||
|
|
||||||
import { EntityForSelect } from '../components/MultipleEntitySelect';
|
import { EntityForSelect } from '../components/MultipleEntitySelect';
|
||||||
|
import { GET_COMMENT_THREADS_BY_TARGETS } from '../services';
|
||||||
import { CommentThreadForDrawer } from '../types/CommentThreadForDrawer';
|
import { CommentThreadForDrawer } from '../types/CommentThreadForDrawer';
|
||||||
|
|
||||||
export function useHandleCheckableCommentThreadTargetChange({
|
export function useHandleCheckableCommentThreadTargetChange({
|
||||||
@ -15,12 +19,20 @@ export function useHandleCheckableCommentThreadTargetChange({
|
|||||||
}) {
|
}) {
|
||||||
const [addCommentThreadTargetOnCommentThread] =
|
const [addCommentThreadTargetOnCommentThread] =
|
||||||
useAddCommentThreadTargetOnCommentThreadMutation({
|
useAddCommentThreadTargetOnCommentThreadMutation({
|
||||||
refetchQueries: ['GetCompanies', 'GetPeople'],
|
refetchQueries: [
|
||||||
|
getOperationName(GET_COMPANIES) ?? '',
|
||||||
|
getOperationName(GET_PEOPLE) ?? '',
|
||||||
|
getOperationName(GET_COMMENT_THREADS_BY_TARGETS) ?? '',
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const [removeCommentThreadTargetOnCommentThread] =
|
const [removeCommentThreadTargetOnCommentThread] =
|
||||||
useRemoveCommentThreadTargetOnCommentThreadMutation({
|
useRemoveCommentThreadTargetOnCommentThreadMutation({
|
||||||
refetchQueries: ['GetCompanies', 'GetPeople'],
|
refetchQueries: [
|
||||||
|
getOperationName(GET_COMPANIES) ?? '',
|
||||||
|
getOperationName(GET_PEOPLE) ?? '',
|
||||||
|
getOperationName(GET_COMMENT_THREADS_BY_TARGETS) ?? '',
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
return function handleCheckItemChange(
|
return function handleCheckItemChange(
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
import { FetchResult, gql } from '@apollo/client';
|
import { FetchResult, gql } from '@apollo/client';
|
||||||
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
|
|
||||||
import { apiClient } from '~/apollo';
|
import { apiClient } from '~/apollo';
|
||||||
|
|
||||||
import { UpdateCompanyMutationVariables } from '../../../generated/graphql';
|
import { UpdateCompanyMutationVariables } from '../../../generated/graphql';
|
||||||
import { Company, mapToGqlCompany } from '../interfaces/company.interface';
|
import { Company, mapToGqlCompany } from '../interfaces/company.interface';
|
||||||
|
|
||||||
|
import { GET_COMPANIES } from './select';
|
||||||
|
|
||||||
export const UPDATE_COMPANY = gql`
|
export const UPDATE_COMPANY = gql`
|
||||||
mutation UpdateCompany(
|
mutation UpdateCompany(
|
||||||
$id: String
|
$id: String
|
||||||
@ -94,7 +97,7 @@ export async function insertCompany(
|
|||||||
const result = await apiClient.mutate({
|
const result = await apiClient.mutate({
|
||||||
mutation: INSERT_COMPANY,
|
mutation: INSERT_COMPANY,
|
||||||
variables: mapToGqlCompany(company),
|
variables: mapToGqlCompany(company),
|
||||||
refetchQueries: ['GetCompanies'],
|
refetchQueries: [getOperationName(GET_COMPANIES) ?? ''],
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
import { FetchResult, gql } from '@apollo/client';
|
import { FetchResult, gql } from '@apollo/client';
|
||||||
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
|
|
||||||
import { apiClient } from '../../../apollo';
|
import { apiClient } from '../../../apollo';
|
||||||
import { mapToGqlPerson, Person } from '../interfaces/person.interface';
|
import { mapToGqlPerson, Person } from '../interfaces/person.interface';
|
||||||
|
|
||||||
|
import { GET_PEOPLE } from './select';
|
||||||
|
|
||||||
export const UPDATE_PERSON = gql`
|
export const UPDATE_PERSON = gql`
|
||||||
mutation UpdatePeople(
|
mutation UpdatePeople(
|
||||||
$id: String
|
$id: String
|
||||||
@ -104,7 +107,7 @@ export async function insertPerson(
|
|||||||
const result = await apiClient.mutate({
|
const result = await apiClient.mutate({
|
||||||
mutation: INSERT_PERSON,
|
mutation: INSERT_PERSON,
|
||||||
variables: mapToGqlPerson(person),
|
variables: mapToGqlPerson(person),
|
||||||
refetchQueries: ['GetPeople'],
|
refetchQueries: [getOperationName(GET_PEOPLE) ?? ''],
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
|
import { GET_COMPANIES } from '@/companies/services';
|
||||||
import { EntityTableActionBarButton } from '@/ui/components/table/action-bar/EntityTableActionBarButton';
|
import { EntityTableActionBarButton } from '@/ui/components/table/action-bar/EntityTableActionBarButton';
|
||||||
import { IconTrash } from '@/ui/icons/index';
|
import { IconTrash } from '@/ui/icons/index';
|
||||||
import { useResetTableRowSelection } from '@/ui/tables/hooks/useResetTableRowSelection';
|
import { useResetTableRowSelection } from '@/ui/tables/hooks/useResetTableRowSelection';
|
||||||
@ -12,7 +14,7 @@ export function TableActionBarButtonDeleteCompanies() {
|
|||||||
const resetRowSelection = useResetTableRowSelection();
|
const resetRowSelection = useResetTableRowSelection();
|
||||||
|
|
||||||
const [deleteCompanies] = useDeleteCompaniesMutation({
|
const [deleteCompanies] = useDeleteCompaniesMutation({
|
||||||
refetchQueries: ['GetCompanies'],
|
refetchQueries: [getOperationName(GET_COMPANIES) ?? ''],
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleDeleteClick() {
|
async function handleDeleteClick() {
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
|
import { GET_PEOPLE } from '@/people/services';
|
||||||
import { EntityTableActionBarButton } from '@/ui/components/table/action-bar/EntityTableActionBarButton';
|
import { EntityTableActionBarButton } from '@/ui/components/table/action-bar/EntityTableActionBarButton';
|
||||||
import { IconTrash } from '@/ui/icons/index';
|
import { IconTrash } from '@/ui/icons/index';
|
||||||
import { useResetTableRowSelection } from '@/ui/tables/hooks/useResetTableRowSelection';
|
import { useResetTableRowSelection } from '@/ui/tables/hooks/useResetTableRowSelection';
|
||||||
@ -12,7 +14,7 @@ export function TableActionBarButtonDeletePeople() {
|
|||||||
const resetRowSelection = useResetTableRowSelection();
|
const resetRowSelection = useResetTableRowSelection();
|
||||||
|
|
||||||
const [deletePeople] = useDeletePeopleMutation({
|
const [deletePeople] = useDeletePeopleMutation({
|
||||||
refetchQueries: ['GetPeople'],
|
refetchQueries: [getOperationName(GET_PEOPLE) ?? ''],
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleDeleteClick() {
|
async function handleDeleteClick() {
|
||||||
|
|||||||
Reference in New Issue
Block a user