1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-23 11:02:35 +03:00

Ability to remove emails

This commit is contained in:
Quentin Gliech
2023-04-28 17:11:23 +02:00
parent e8b7591d7e
commit 741873b84e
14 changed files with 2085 additions and 1629 deletions

View File

@@ -18,7 +18,11 @@ import { cacheExchange } from "@urql/exchange-graphcache";
import { refocusExchange } from "@urql/exchange-refocus";
import { requestPolicyExchange } from "@urql/exchange-request-policy";
import type { MutationAddEmailArgs } from "./gql/graphql";
import type {
MutationAddEmailArgs,
MutationRemoveEmailArgs,
RemoveEmailPayload,
} from "./gql/graphql";
import schema from "./gql/schema";
const cache = cacheExchange({
@@ -39,6 +43,36 @@ const cache = cacheExchange({
cache.invalidate(key, field.fieldName, field.arguments);
});
},
removeEmail: (
result: { removeEmail?: RemoveEmailPayload },
args: MutationRemoveEmailArgs,
cache,
_info
) => {
// Invalidate the email entity
cache.invalidate({
__typename: "UserEmail",
id: args.input.userEmailId,
});
// Let's try to figure out the userId to invalidate the emails field on the User object
const userId = result.removeEmail?.user?.id;
if (userId) {
const key = cache.keyOfEntity({
__typename: "User",
id: userId,
});
// Invalidate the emails field on the User object so that it gets refetched
cache
.inspectFields(key)
.filter((field) => field.fieldName === "emails")
.forEach((field) => {
cache.invalidate(key, field.fieldName, field.arguments);
});
}
},
},
},
});