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

@@ -128,6 +128,7 @@ import { MOBILIZON_INSTANCE_HOST } from "../../api/_entrypoint";
import RouteName from "../../router/name";
import { changeIdentity } from "../../utils/auth";
import identityEditionMixin from "../../mixins/identityEdition";
import { ApolloCache, FetchResult, InMemoryCache } from "@apollo/client/core";
@Component({
apollo: {
@@ -164,7 +165,10 @@ export default class Register extends mixins(identityEditionMixin) {
const { data } = await this.$apollo.mutate<{ registerPerson: IPerson }>({
mutation: REGISTER_PERSON,
variables: { email: this.email, ...this.identity },
update: (store, { data: localData }) => {
update: (
store: ApolloCache<InMemoryCache>,
{ data: localData }: FetchResult
) => {
if (this.userAlreadyActivated) {
const identitiesData = store.readQuery<{ identities: IPerson[] }>({
query: IDENTITIES,

View File

@@ -232,9 +232,10 @@ import {
DELETE_FEED_TOKEN,
} from "@/graphql/feed_tokens";
import { IFeedToken } from "@/types/feedtoken.model";
import { ServerParseError } from "apollo-link-http-common";
import { IConfig } from "@/types/config.model";
import { CONFIG } from "@/graphql/config";
import { ServerParseError } from "@apollo/client/link/http";
import { ApolloCache, FetchResult, InMemoryCache } from "@apollo/client/core";
@Component({
components: {
@@ -324,7 +325,7 @@ export default class EditIdentity extends mixins(identityEditionMixin) {
variables: {
id: this.identity.id,
},
update: (store) => {
update: (store: ApolloCache<InMemoryCache>) => {
const data = store.readQuery<{ identities: IPerson[] }>({
query: IDENTITIES,
});
@@ -368,18 +369,21 @@ export default class EditIdentity extends mixins(identityEditionMixin) {
await this.$apollo.mutate({
mutation: UPDATE_PERSON,
variables,
update: (store, { data: { updatePerson } }) => {
update: (
store: ApolloCache<InMemoryCache>,
{ data: updateData }: FetchResult
) => {
const data = store.readQuery<{ identities: IPerson[] }>({
query: IDENTITIES,
});
if (data) {
if (data && updateData?.updatePerson) {
const index = data.identities.findIndex(
(i) => i.id === this.identity.id
);
this.$set(data.identities, index, updatePerson);
this.maybeUpdateCurrentActorCache(updatePerson);
this.$set(data.identities, index, updateData?.updatePerson);
this.maybeUpdateCurrentActorCache(updateData?.updatePerson);
store.writeQuery({ query: IDENTITIES, data });
}
@@ -403,13 +407,16 @@ export default class EditIdentity extends mixins(identityEditionMixin) {
await this.$apollo.mutate({
mutation: CREATE_PERSON,
variables,
update: (store, { data: { createPerson } }) => {
update: (
store: ApolloCache<InMemoryCache>,
{ data: updateData }: FetchResult
) => {
const data = store.readQuery<{ identities: IPerson[] }>({
query: IDENTITIES,
});
if (data) {
data.identities.push(createPerson);
if (data && updateData?.createPerson) {
data.identities.push(updateData?.createPerson);
store.writeQuery({ query: IDENTITIES, data });
}