Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate GQL cache for org when a new project added to it #976

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/LexBoxApi/GraphQL/OrgMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task<IQueryable<Organization>> AddProjectToOrg(
Guid orgId,
Guid projectId)
{
var org = await dbContext.Orgs.FindAsync(orgId);
var org = await dbContext.Orgs.Include(o => o.Members).SingleOrDefaultAsync(o => o.Id == orgId);
NotFoundException.ThrowIfNull(org);
permissionService.AssertCanAddProjectToOrg(org);
var project = await dbContext.Projects.Where(p => p.Id == projectId)
Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task<IQueryable<Organization>> RemoveProjectFromOrg(
Guid orgId,
Guid projectId)
{
var org = await dbContext.Orgs.FindAsync(orgId);
var org = await dbContext.Orgs.Include(o => o.Members).SingleOrDefaultAsync(o => o.Id == orgId);
NotFoundException.ThrowIfNull(org);
permissionService.AssertCanAddProjectToOrg(org);
var project = await dbContext.Projects.Where(p => p.Id == projectId)
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/lib/gql/gql-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
type BulkAddOrgMembersMutationVariables,
type ChangeOrgMemberRoleMutationVariables,
type AddOrgMemberMutationVariables,
type CreateProjectMutationVariables,
} from './types';
import type {Readable, Unsubscriber} from 'svelte/store';
import {derived} from 'svelte/store';
Expand All @@ -57,6 +58,11 @@ function createGqlClient(_gqlEndpoint?: string): Client {
},
updates: {
Mutation: {
createProject: (result, args: CreateProjectMutationVariables, cache, _info) => {
if (args.input.orgId) {
cache.invalidate({__typename: 'OrgById', id: args.input.orgId}, 'projects');
}
},
softDeleteProject: (result, args: SoftDeleteProjectMutationVariables, cache, _info) => {
cache.invalidate({__typename: 'Project', id: args.input.projectId});
},
Expand Down Expand Up @@ -88,9 +94,11 @@ function createGqlClient(_gqlEndpoint?: string): Client {
},
addProjectToOrg: (result, args: MutationAddProjectToOrgArgs, cache, _info) => {
cache.invalidate({__typename: 'Project', id: args.input.projectId});
cache.invalidate({__typename: 'OrgById', id: args.input.orgId}, 'projects');
},
removeProjectFromOrg: (result, args: MutationRemoveProjectFromOrgArgs, cache, _info) => {
cache.invalidate({__typename: 'Project', id: args.input.projectId});
cache.invalidate({__typename: 'OrgById', id: args.input.orgId}, 'projects');
}
}
}
Expand Down
Loading