Refetch query on draft creation (#9650)

After hitting use as draft, we redirect the user to the workflow page.
If the user already accessed that page, the workflow and its current
version will be stored in cache. So we also need to update that cache.

I tried to update it manually but it was more complex than expected.
Steps and trigger are not fully defined objects.

I ended with a simple refetch query that I wanted to avoid but that is
at least fully working with minimum logic.
This commit is contained in:
Thomas Trompette
2025-01-16 10:46:23 +01:00
committed by GitHub
parent 34ddeade83
commit c79cb14132
2 changed files with 28 additions and 2 deletions

View File

@ -1553,7 +1553,8 @@ export enum WorkspaceActivationStatus {
Active = 'ACTIVE',
Inactive = 'INACTIVE',
OngoingCreation = 'ONGOING_CREATION',
PendingCreation = 'PENDING_CREATION'
PendingCreation = 'PENDING_CREATION',
Suspended = 'SUSPENDED'
}
export type WorkspaceEdge = {

View File

@ -1,3 +1,5 @@
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useFindManyRecordsQuery } from '@/object-record/hooks/useFindManyRecordsQuery';
import { useApolloClient } from '@apollo/client';
import {
CreateDraftFromWorkflowVersionInput,
@ -11,10 +13,33 @@ export const useCreateDraftFromWorkflowVersion = () => {
client: apolloClient,
});
const { findManyRecordsQuery: findManyWorkflowsQuery } =
useFindManyRecordsQuery({
objectNameSingular: CoreObjectNameSingular.Workflow,
recordGqlFields: {
id: true,
name: true,
statuses: true,
lastPublishedVersionId: true,
versions: true,
},
});
const createDraftFromWorkflowVersion = async (
input: CreateDraftFromWorkflowVersionInput,
) => {
await mutate({ variables: { input } });
await mutate({
variables: { input },
awaitRefetchQueries: true,
refetchQueries: [
{
query: findManyWorkflowsQuery,
variables: {
id: input.workflowId,
},
},
],
});
};
return {