From 831e0d77796975c65b5a931dfa3cc2ddc2b621e7 Mon Sep 17 00:00:00 2001 From: Michael Schramm Date: Mon, 3 Jan 2022 08:47:02 +0100 Subject: [PATCH] reload list after adding new form fixes https://github.com/ohmyform/ohmyform/issues/139 --- CHANGELOG.md | 1 + graphql/fragment/form.pager.fragment.ts | 2 +- graphql/fragment/form.public.fragment.ts | 2 +- graphql/mutation/form.create.mutation.ts | 19 +++++++++++++++++-- graphql/query/form.pager.query.ts | 2 +- graphql/query/form.public.query.ts | 2 +- graphql/query/submission.pager.query.ts | 2 +- 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b952a41..f99ecf02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - fixes for hide contrib setting - fix problem with node-prune on production build - translation for prev / continue during form submission +- reload form list after adding new one (https://github.com/ohmyform/ohmyform/issues/139) ### Security diff --git a/graphql/fragment/form.pager.fragment.ts b/graphql/fragment/form.pager.fragment.ts index 19cae2e8..399b5b8a 100644 --- a/graphql/fragment/form.pager.fragment.ts +++ b/graphql/fragment/form.pager.fragment.ts @@ -15,7 +15,7 @@ export interface FormPagerFragment { } export const FORM_PAGER_FRAGMENT = gql` - fragment Form on Form { + fragment PagerForm on Form { id created lastModified diff --git a/graphql/fragment/form.public.fragment.ts b/graphql/fragment/form.public.fragment.ts index 58327c11..ae1514ea 100644 --- a/graphql/fragment/form.public.fragment.ts +++ b/graphql/fragment/form.public.fragment.ts @@ -80,7 +80,7 @@ export interface FormPublicFragment { } export const FORM_PUBLIC_FRAGMENT = gql` - fragment Form on Form { + fragment PublicForm on Form { id title language diff --git a/graphql/mutation/form.create.mutation.ts b/graphql/mutation/form.create.mutation.ts index 3be88189..a758f11b 100644 --- a/graphql/mutation/form.create.mutation.ts +++ b/graphql/mutation/form.create.mutation.ts @@ -26,5 +26,20 @@ const MUTATION = gql` ` export const useFormCreateMutation = ( - data?: MutationHookOptions -): MutationTuple => useMutation(MUTATION, data) + options: MutationHookOptions = {} +): MutationTuple => { + const oldUpdate = options.update + + options.update = (cache, result, options) => { + cache.evict({ + fieldName: 'listForms', + }) + cache.gc() + + if (oldUpdate) { + oldUpdate(cache, result, options) + } + } + + return useMutation(MUTATION, options) +} diff --git a/graphql/query/form.pager.query.ts b/graphql/query/form.pager.query.ts index f8e1e940..13af394c 100644 --- a/graphql/query/form.pager.query.ts +++ b/graphql/query/form.pager.query.ts @@ -21,7 +21,7 @@ const QUERY = gql` query listForms($start: Int, $limit: Int) { pager: listForms(start: $start, limit: $limit) { entries { - ...Form + ...PagerForm } total limit diff --git a/graphql/query/form.public.query.ts b/graphql/query/form.public.query.ts index dc289caf..10580f74 100644 --- a/graphql/query/form.public.query.ts +++ b/graphql/query/form.public.query.ts @@ -13,7 +13,7 @@ interface Variables { const QUERY = gql` query getFormById($id: ID!) { form: getFormById(id: $id) { - ...Form + ...PublicForm } } diff --git a/graphql/query/submission.pager.query.ts b/graphql/query/submission.pager.query.ts index c92f2e25..0d3de61b 100644 --- a/graphql/query/submission.pager.query.ts +++ b/graphql/query/submission.pager.query.ts @@ -25,7 +25,7 @@ interface Variables { const QUERY = gql` query listSubmissions($form: ID!, $start: Int, $limit: Int) { form: getFormById(id: $form) { - ...Form + ...PagerForm } pager: listSubmissions(form: $form, start: $start, limit: $limit) {