Fixed bug for refectch activities and create activity on the currently filtered user. (#1493)
* Fixed bug for refectch activities and create activity on the currently filtered user. * Refactor optimistif effect --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,11 +0,0 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const INSERT_PERSON_FRAGMENT = gql`
|
||||
fragment InsertPersonFragment on Person {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
displayName
|
||||
createdAt
|
||||
}
|
||||
`;
|
||||
@ -0,0 +1,24 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const PERSON_FIELDS_FRAGMENT = gql`
|
||||
fragment personFieldsFragment on Person {
|
||||
id
|
||||
phone
|
||||
email
|
||||
city
|
||||
firstName
|
||||
lastName
|
||||
displayName
|
||||
jobTitle
|
||||
linkedinUrl
|
||||
xUrl
|
||||
avatarUrl
|
||||
createdAt
|
||||
_activityCount
|
||||
company {
|
||||
id
|
||||
name
|
||||
domainName
|
||||
}
|
||||
}
|
||||
`;
|
||||
@ -3,7 +3,7 @@ import { gql } from '@apollo/client';
|
||||
export const INSERT_ONE_PERSON = gql`
|
||||
mutation InsertOnePerson($data: PersonCreateInput!) {
|
||||
createOnePerson(data: $data) {
|
||||
...InsertPersonFragment
|
||||
...personFieldsFragment
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
import { ApolloCache } from '@apollo/client';
|
||||
|
||||
import {
|
||||
GetPeopleQuery,
|
||||
GetPeopleQueryVariables,
|
||||
Person,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import { GET_PEOPLE } from '../queries/getPeople';
|
||||
|
||||
function optimisticEffectResolver({
|
||||
cache,
|
||||
entities,
|
||||
variables,
|
||||
}: {
|
||||
cache: ApolloCache<Person>;
|
||||
entities: Person[];
|
||||
variables: GetPeopleQueryVariables;
|
||||
}) {
|
||||
const existingData = cache.readQuery<GetPeopleQuery>({
|
||||
query: GET_PEOPLE,
|
||||
variables: { orderBy: variables.orderBy, where: variables.where },
|
||||
});
|
||||
|
||||
if (!existingData) {
|
||||
return;
|
||||
}
|
||||
|
||||
cache.writeQuery({
|
||||
query: GET_PEOPLE,
|
||||
variables: { orderBy: variables.orderBy, where: variables.where },
|
||||
data: {
|
||||
people: [...entities, ...existingData.people],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function getPeopleOptimisticEffect(variables: GetPeopleQueryVariables) {
|
||||
return {
|
||||
key: 'generic-entity-table-data-person',
|
||||
variables: variables,
|
||||
typename: 'Person',
|
||||
resolver: optimisticEffectResolver,
|
||||
};
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
import { Person } from '~/generated/graphql';
|
||||
|
||||
import { GET_PEOPLE } from '../queries/getPeople';
|
||||
|
||||
export const getPeopleOptimisticEffectDefinition = {
|
||||
key: 'generic-entity-table-data-people',
|
||||
typename: 'Person',
|
||||
query: GET_PEOPLE,
|
||||
resolver: ({
|
||||
currentData,
|
||||
newData,
|
||||
}: {
|
||||
currentData: Person[];
|
||||
newData: Person[];
|
||||
}) => {
|
||||
return [...newData, ...currentData];
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user