From 1e8ffaac3e9b89c50b75f92f8e5b983559d32899 Mon Sep 17 00:00:00 2001 From: Jakub Bielski Date: Tue, 1 Aug 2023 13:22:54 +0200 Subject: [PATCH] fix:#351 Adjust plop generator --- .../components/addItem/addItem.component.hbs | 31 +++++-------------- packages/webapp/src/mocks/factories/index.ts | 2 +- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/packages/webapp/plop/crud/templates/components/addItem/addItem.component.hbs b/packages/webapp/plop/crud/templates/components/addItem/addItem.component.hbs index 413ef1db5..ffbfc7ad2 100644 --- a/packages/webapp/plop/crud/templates/components/addItem/addItem.component.hbs +++ b/packages/webapp/plop/crud/templates/components/addItem/addItem.component.hbs @@ -11,8 +11,7 @@ import { useNavigate } from 'react-router'; import { RoutesConfig } from '../../../app/config/routes'; import { {{ pascalCase name }}Form } from '../{{ pascalCase name }}Form/{{ pascalCase name }}Form.component'; import { {{ pascalCase name }}FormFields } from '../{{ pascalCase name }}Form/{{ pascalCase name }}Form.component'; -import { {{ camelCase name }}ListItemFragment } from '../{{ pascalCase name }}List/{{ pascalCase name }}List.graphql'; - +import { ITEMS_PER_PAGE, {{ pascalCase name }}ListQuery } from '../{{ camelCase name }}List/{{ camelCase name }}List.component'; export const add{{ pascalCase name }}Mutation = gql(/* GraphQL */ ` mutation add{{ pascalCase name }}Mutation($input: Create{{ pascalCase name }}MutationInput!) { @@ -39,26 +38,12 @@ export const Add{{ pascalCase name }} = () => { }); const [commit{{ pascalCase name }}FormMutation, { error, loading: loadingMutation }] = useMutation(add{{ pascalCase name }}Mutation, { - update(cache, { data }) { - cache.modify({ - fields: { - all{{ pascalCase name }}s(existingConnection = { edges: [] }) { - const node = data?.create{{ pascalCase name }}?.{{ pascalCase name }}Edge?.node; - if (!node) { - return existingConnection; - } - const newItem = { - node: cache.writeFragment({ - data: node, - fragment: {{ camelCase name }}ListItemFragment, - }), - __typename: '{{ pascalCase name }}Edge', - }; - return { ...existingConnection, edges: [...existingConnection.edges, newItem] }; - }, - }, - }); - }, + refetchQueries: () => [{ + query: {{ pascalCase name }}ListQuery, + variables: { + first: ITEMS_PER_PAGE + } + }], onCompleted: (data) => { const id = data?.create{{ pascalCase name }}?.{{ pascalCase name }}Edge?.node?.id; @@ -88,4 +73,4 @@ export const Add{{ pascalCase name }} = () => { <{{ pascalCase name }}Form onSubmit={onFormSubmit} error={error} loading={loadingMutation} /> ); -}; +}; \ No newline at end of file diff --git a/packages/webapp/src/mocks/factories/index.ts b/packages/webapp/src/mocks/factories/index.ts index faeb21c27..5bef55bd5 100644 --- a/packages/webapp/src/mocks/factories/index.ts +++ b/packages/webapp/src/mocks/factories/index.ts @@ -1 +1 @@ -//<-- INJECT FACTORY --> +//<-- INJECT FACTORY --> \ No newline at end of file