Skip to content

Commit

Permalink
fix:#351 Adjust plop generator
Browse files Browse the repository at this point in the history
  • Loading branch information
bielsky0 committed Aug 1, 2023
1 parent 3ae7867 commit 1e8ffaa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!) {
Expand All @@ -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;

Expand Down Expand Up @@ -88,4 +73,4 @@ export const Add{{ pascalCase name }} = () => {
<{{ pascalCase name }}Form onSubmit={onFormSubmit} error={error} loading={loadingMutation} />
</PageLayout>
);
};
};
2 changes: 1 addition & 1 deletion packages/webapp/src/mocks/factories/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//<-- INJECT FACTORY -->
//<-- INJECT FACTORY -->

0 comments on commit 1e8ffaa

Please sign in to comment.