Move to Apollo v3

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-05-12 18:10:07 +02:00
parent 7cb40bd9e2
commit e96dcc42b9
51 changed files with 1247 additions and 817 deletions

View File

@@ -442,7 +442,7 @@ section {
<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { RefetchQueryDescription } from "apollo-client/core/watchQueryOptions";
import { RefetchQueryDescription } from "@apollo/client/core/watchQueryOptions";
import PictureUpload from "@/components/PictureUpload.vue";
import EditorComponent from "@/components/Editor.vue";
import TagInput from "@/components/Event/TagInput.vue";
@@ -485,6 +485,7 @@ import RouteName from "../../router/name";
import "intersection-observer";
import { CONFIG } from "../../graphql/config";
import { IConfig } from "../../types/config.model";
import { ApolloCache, FetchResult, InMemoryCache } from "@apollo/client/core";
const DEFAULT_LIMIT_NUMBER_OF_PLACES = 10;
@@ -706,10 +707,12 @@ export default class EditEvent extends Vue {
const { data } = await this.$apollo.mutate({
mutation: CREATE_EVENT,
variables,
update: (store, { data: { createEvent } }) =>
this.postCreateOrUpdate(store, createEvent),
refetchQueries: ({ data: { createEvent } }) =>
this.postRefetchQueries(createEvent),
update: (
store: ApolloCache<InMemoryCache>,
{ data: updatedData }: FetchResult
) => this.postCreateOrUpdate(store, updatedData?.createEvent),
refetchQueries: ({ data: updatedData }: FetchResult) =>
this.postRefetchQueries(updatedData?.createEvent),
});
this.$buefy.notification.open({
@@ -739,10 +742,12 @@ export default class EditEvent extends Vue {
await this.$apollo.mutate({
mutation: EDIT_EVENT,
variables,
update: (store, { data: { updateEvent } }) =>
this.postCreateOrUpdate(store, updateEvent),
refetchQueries: ({ data: { updateEvent } }) =>
this.postRefetchQueries(updateEvent),
update: (
store: ApolloCache<InMemoryCache>,
{ data: updatedData }: FetchResult
) => this.postCreateOrUpdate(store, updatedData?.updateEvent),
refetchQueries: ({ data }: FetchResult) =>
this.postRefetchQueries(data?.updateEvent),
});
this.$buefy.notification.open({

View File

@@ -665,6 +665,7 @@ import EventMetadataBlock from "../../components/Event/EventMetadataBlock.vue";
import ActorCard from "../../components/Account/ActorCard.vue";
import PopoverActorCard from "../../components/Account/PopoverActorCard.vue";
import { IParticipant } from "../../types/participant.model";
import { ApolloCache, FetchResult, InMemoryCache } from "@apollo/client/core";
// noinspection TypeScriptValidateTypes
@Component({
@@ -1002,7 +1003,7 @@ export default class Event extends EventMixin {
actorId: identity.id,
message,
},
update: (store, { data }) => {
update: (store: ApolloCache<InMemoryCache>, { data }: FetchResult) => {
if (data == null) return;
const participationCachedData = store.readQuery<{ person: IPerson }>({

View File

@@ -265,28 +265,6 @@ export default class MyEvents extends Vue {
page: this.futurePage,
limit: this.limit,
},
// Transform the previous result with new data
updateQuery: (previousResult, { fetchMoreResult }) => {
const oldParticipations = previousResult.loggedUser.participations;
const newParticipations = fetchMoreResult.loggedUser.participations;
this.hasMoreFutureParticipations =
newParticipations.total ===
oldParticipations.length + newParticipations.length;
return {
loggedUser: {
__typename: previousResult.loggedUser.__typename,
participations: {
__typename: newParticipations.__typename,
total: newParticipations.total,
elements: [
...oldParticipations.elements,
...newParticipations.elements,
],
},
},
};
},
});
}
@@ -298,28 +276,6 @@ export default class MyEvents extends Vue {
page: this.pastPage,
limit: this.limit,
},
// Transform the previous result with new data
updateQuery: (previousResult, { fetchMoreResult }) => {
const oldParticipations = previousResult.loggedUser.participations;
const newParticipations = fetchMoreResult.loggedUser.participations;
this.hasMorePastParticipations =
newParticipations.total ===
oldParticipations.length + newParticipations.length;
return {
loggedUser: {
__typename: previousResult.loggedUser.__typename,
participations: {
__typename: newParticipations.__typename,
total: newParticipations.total,
elements: [
...oldParticipations.elements,
...newParticipations.elements,
],
},
},
};
},
});
}

View File

@@ -308,25 +308,6 @@ export default class Participants extends Vue {
page: this.page,
limit: this.limit,
},
// Transform the previous result with new data
updateQuery: (previousResult, { fetchMoreResult }) => {
const oldParticipants = previousResult.event.participants;
const newParticipants = fetchMoreResult.event.participants;
return {
event: {
...previousResult.event,
participants: {
elements: [
...oldParticipants.elements,
...newParticipants.elements,
],
total: newParticipants.total,
__typename: oldParticipants.__typename,
},
},
};
},
});
}