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

WIP my account page

This commit is contained in:
Quentin Gliech
2023-04-27 12:03:46 +02:00
parent f62d045b8c
commit 574514638e
14 changed files with 272 additions and 224 deletions

View File

@@ -17,33 +17,35 @@ import { cacheExchange } from "@urql/exchange-graphcache";
import schema from "./gql/schema";
import type { MutationAddEmailArgs } from "./gql/graphql";
import { devtoolsExchange } from "@urql/devtools";
const cache = cacheExchange({
schema,
updates: {
Mutation: {
addEmail: (result, args: MutationAddEmailArgs, cache, _info) => {
const key = cache.keyOfEntity({
__typename: "User",
id: args.input.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);
});
},
},
},
});
export const client = createClient({
url: "/graphql",
// XXX: else queries don't refetch on cache invalidation for some reason
requestPolicy: "cache-and-network",
exchanges: [
cacheExchange({
schema,
updates: {
Mutation: {
addEmail: (result, args: MutationAddEmailArgs, cache, _info) => {
const key = cache.keyOfEntity({
__typename: "User",
id: args.input.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);
});
},
},
},
}),
fetchExchange,
],
exchanges: import.meta.env.DEV
? [devtoolsExchange, cache, fetchExchange]
: [cache, fetchExchange],
});