fix(fe2): post workspace creation cache update
This commit is contained in:
@@ -137,14 +137,20 @@ import { graphql } from '~~/lib/common/generated/gql'
|
||||
import type { WorkspaceRoles } from '@speckle/shared'
|
||||
import { useMixpanel } from '~~/lib/core/composables/mp'
|
||||
|
||||
graphql(`
|
||||
fragment SettingsDialog_Workspace on Workspace {
|
||||
...WorkspaceAvatar_Workspace
|
||||
id
|
||||
role
|
||||
name
|
||||
}
|
||||
`)
|
||||
|
||||
graphql(`
|
||||
fragment SettingsDialog_User on User {
|
||||
workspaces {
|
||||
items {
|
||||
...WorkspaceAvatar_Workspace
|
||||
id
|
||||
role
|
||||
name
|
||||
...SettingsDialog_Workspace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,8 @@ const documents = {
|
||||
"\n fragment ProjectsDashboardHeaderWorkspaces_User on User {\n ...WorkspaceInviteBanners_User\n }\n": types.ProjectsDashboardHeaderWorkspaces_UserFragmentDoc,
|
||||
"\n fragment ProjectsInviteBanner on PendingStreamCollaborator {\n id\n invitedBy {\n ...LimitedUserAvatar\n }\n projectId\n projectName\n token\n user {\n id\n }\n }\n": types.ProjectsInviteBannerFragmentDoc,
|
||||
"\n fragment ProjectsInviteBanners on User {\n projectInvites {\n ...ProjectsInviteBanner\n }\n }\n": types.ProjectsInviteBannersFragmentDoc,
|
||||
"\n fragment SettingsDialog_User on User {\n workspaces {\n items {\n ...WorkspaceAvatar_Workspace\n id\n role\n name\n }\n }\n }\n": types.SettingsDialog_UserFragmentDoc,
|
||||
"\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n id\n role\n name\n }\n": types.SettingsDialog_WorkspaceFragmentDoc,
|
||||
"\n fragment SettingsDialog_User on User {\n workspaces {\n items {\n ...SettingsDialog_Workspace\n }\n }\n }\n": types.SettingsDialog_UserFragmentDoc,
|
||||
"\n fragment SettingsServerProjects_ProjectCollection on ProjectCollection {\n totalCount\n items {\n ...SettingsSharedProjects_Project\n }\n }\n": types.SettingsServerProjects_ProjectCollectionFragmentDoc,
|
||||
"\n fragment SettingsSharedProjects_Project on Project {\n id\n name\n visibility\n createdAt\n updatedAt\n models {\n totalCount\n }\n versions {\n totalCount\n }\n team {\n id\n user {\n name\n id\n avatar\n }\n }\n }\n": types.SettingsSharedProjects_ProjectFragmentDoc,
|
||||
"\n fragment SettingsUserEmails_User on User {\n id\n emails {\n ...SettingsUserEmailCards_UserEmail\n }\n }\n": types.SettingsUserEmails_UserFragmentDoc,
|
||||
@@ -297,7 +298,7 @@ const documents = {
|
||||
"\n fragment UseWorkspaceInviteManager_PendingWorkspaceCollaborator on PendingWorkspaceCollaborator {\n id\n token\n workspaceId\n user {\n id\n }\n }\n": types.UseWorkspaceInviteManager_PendingWorkspaceCollaboratorFragmentDoc,
|
||||
"\n mutation UpdateRole($input: WorkspaceRoleUpdateInput!) {\n workspaceMutations {\n updateRole(input: $input) {\n team {\n items {\n id\n role\n }\n }\n }\n }\n }\n": types.UpdateRoleDocument,
|
||||
"\n mutation InviteToWorkspace(\n $workspaceId: String!\n $input: [WorkspaceInviteCreateInput!]!\n ) {\n workspaceMutations {\n invites {\n batchCreate(workspaceId: $workspaceId, input: $input) {\n id\n invitedTeam {\n ...SettingsWorkspacesMembersInvitesTable_PendingWorkspaceCollaborator\n }\n }\n }\n }\n }\n": types.InviteToWorkspaceDocument,
|
||||
"\n mutation CreateWorkspace($input: WorkspaceCreateInput!) {\n workspaceMutations {\n create(input: $input) {\n id\n }\n }\n }\n": types.CreateWorkspaceDocument,
|
||||
"\n mutation CreateWorkspace($input: WorkspaceCreateInput!) {\n workspaceMutations {\n create(input: $input) {\n id\n ...SettingsDialog_Workspace\n }\n }\n }\n": types.CreateWorkspaceDocument,
|
||||
"\n mutation ProcessWorkspaceInvite($input: WorkspaceInviteUseInput!) {\n workspaceMutations {\n invites {\n use(input: $input)\n }\n }\n }\n": types.ProcessWorkspaceInviteDocument,
|
||||
"\n query WorkspaceAccessCheck($id: String!) {\n workspace(id: $id) {\n id\n }\n }\n": types.WorkspaceAccessCheckDocument,
|
||||
"\n query WorkspacePageQuery(\n $workspaceId: String!\n $filter: WorkspaceProjectsFilter\n $cursor: String\n $invitesFilter: PendingWorkspaceCollaboratorsFilter\n ) {\n workspace(id: $workspaceId) {\n id\n ...WorkspaceHeader_Workspace\n projects(filter: $filter, cursor: $cursor, limit: 10) {\n ...WorkspaceProjectList_ProjectCollection\n }\n }\n }\n": types.WorkspacePageQueryDocument,
|
||||
@@ -642,7 +643,11 @@ export function graphql(source: "\n fragment ProjectsInviteBanners on User {\n
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n fragment SettingsDialog_User on User {\n workspaces {\n items {\n ...WorkspaceAvatar_Workspace\n id\n role\n name\n }\n }\n }\n"): (typeof documents)["\n fragment SettingsDialog_User on User {\n workspaces {\n items {\n ...WorkspaceAvatar_Workspace\n id\n role\n name\n }\n }\n }\n"];
|
||||
export function graphql(source: "\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n id\n role\n name\n }\n"): (typeof documents)["\n fragment SettingsDialog_Workspace on Workspace {\n ...WorkspaceAvatar_Workspace\n id\n role\n name\n }\n"];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n fragment SettingsDialog_User on User {\n workspaces {\n items {\n ...SettingsDialog_Workspace\n }\n }\n }\n"): (typeof documents)["\n fragment SettingsDialog_User on User {\n workspaces {\n items {\n ...SettingsDialog_Workspace\n }\n }\n }\n"];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
@@ -1470,7 +1475,7 @@ export function graphql(source: "\n mutation InviteToWorkspace(\n $workspace
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n mutation CreateWorkspace($input: WorkspaceCreateInput!) {\n workspaceMutations {\n create(input: $input) {\n id\n }\n }\n }\n"): (typeof documents)["\n mutation CreateWorkspace($input: WorkspaceCreateInput!) {\n workspaceMutations {\n create(input: $input) {\n id\n }\n }\n }\n"];
|
||||
export function graphql(source: "\n mutation CreateWorkspace($input: WorkspaceCreateInput!) {\n workspaceMutations {\n create(input: $input) {\n id\n ...SettingsDialog_Workspace\n }\n }\n }\n"): (typeof documents)["\n mutation CreateWorkspace($input: WorkspaceCreateInput!) {\n workspaceMutations {\n create(input: $input) {\n id\n ...SettingsDialog_Workspace\n }\n }\n }\n"];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -33,7 +33,7 @@ import {
|
||||
processWorkspaceInviteMutation,
|
||||
workspaceUpdateRoleMutation
|
||||
} from '~/lib/workspaces/graphql/mutations'
|
||||
import { isFunction } from 'lodash-es'
|
||||
import { isFunction, isUndefined } from 'lodash-es'
|
||||
import type { GraphQLError } from 'graphql'
|
||||
import { useClipboard } from '~~/composables/browser'
|
||||
|
||||
@@ -358,8 +358,34 @@ export function useCreateWorkspace() {
|
||||
const res = await apollo
|
||||
.mutate({
|
||||
mutation: createWorkspaceMutation,
|
||||
variables: { input }
|
||||
// TODO: Fix the cache update
|
||||
variables: { input },
|
||||
update: (cache, { data }) => {
|
||||
const workspaceId = data?.workspaceMutations.create.id
|
||||
if (!workspaceId) return
|
||||
// Navigation to workspace is gonna fetch everything needed for the page, so we only
|
||||
// really need to update workspace fields used in sidebar & settings: User.workspaces
|
||||
modifyObjectField<User['workspaces'], UserWorkspacesArgs>(
|
||||
cache,
|
||||
getCacheId('User', userId),
|
||||
'workspaces',
|
||||
({ variables, value, details: { DELETE } }) => {
|
||||
if (variables.filter?.search?.length) return DELETE // evict if filtered search
|
||||
|
||||
const totalCount = isUndefined(value?.totalCount)
|
||||
? undefined
|
||||
: value.totalCount + 1
|
||||
const items = isUndefined(value?.items)
|
||||
? undefined
|
||||
: [...value.items, getObjectReference('Workspace', workspaceId)]
|
||||
|
||||
return {
|
||||
...value,
|
||||
totalCount,
|
||||
items
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
.catch(convertThrowIntoFetchResult)
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ export const createWorkspaceMutation = graphql(`
|
||||
workspaceMutations {
|
||||
create(input: $input) {
|
||||
id
|
||||
...SettingsDialog_Workspace
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user