Skip to content

Commit

Permalink
docs: Improve detail view guide example
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Nov 6, 2023
1 parent 187b26f commit ea03d52
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,39 @@ import { TypedBaseDetailComponent, LanguageCode, SharedModule } from '@vendure/a
// This is the TypedDocumentNode & type generated by GraphQL Code Generator
import { graphql } from '../../gql';

export const reviewDetailFragment = graphql(`
fragment ReviewDetail on ProductReview {
id
createdAt
updatedAt
title
rating
text
authorName
productId
}
`);

export const getReviewDetailDocument = graphql(`
query GetReviewDetail($id: ID!) {
review(id: $id) {
id
createdAt
updatedAt
title
rating
text
authorName
productId
...ReviewDetail
}
}
`);

export const createReviewDocument = graphql(`
mutation CreateReview($input: CreateProductReviewInput!) {
createProductReview(input: $input) {
...ReviewDetail
}
}
`);

export const updateReviewDocument = graphql(`
mutation UpdateReview($input: UpdateProductReviewInput!) {
updateProductReview(input: $input) {
...ReviewDetail
}
}
`);
Expand All @@ -63,7 +85,7 @@ export class ReviewDetailComponent extends TypedBaseDetailComponent<typeof getRe
authorName: [''],
});

constructor(private formBuilder: FormBuilder) {
constructor(private formBuilder: FormBuilder, private notificationService: NotificationService) {
super();
}

Expand All @@ -76,11 +98,31 @@ export class ReviewDetailComponent extends TypedBaseDetailComponent<typeof getRe
}

create() {
// Logic to save a Review
const { title, rating, authorName } = this.detailForm.value;
if (!title || rating == null || !authorName) {
return;
}
this.dataService
.mutate(createReviewDocument, {
input: { title, rating, authorName },
})
.subscribe(({ createProductReview }) => {
if (createProductReview.id) {
this.notificationService.success('Review created');
this.router.navigate(['extensions', 'reviews', createProductReview.id]);
}
});
}

update() {
// Logic to update a Review
const { title, rating, authorName } = this.detailForm.value;
this.dataService
.mutate(updateOrganizationDocument, {
input: { id: this.id, title, rating, authorName },
})
.subscribe(() => {
this.notificationService.success('Review updated');
});
}

protected setFormValues(entity: NonNullable<ResultOf<typeof getReviewDetailDocument>['review']>, languageCode: LanguageCode): void {
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/guides/how-to/codegen/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ const config: CodegenConfig = {
'apps/marketplace/src/plugins/marketplace/ui/gql/': {
preset: 'client',
documents: 'apps/marketplace/src/plugins/marketplace/ui/**/*.ts',
// This disables the "fragment masking" feature. Fragment masking
// can improve component isolation but introduces some additional
// complexity that we will avoid for now.
presetConfig: {
fragmentMasking: false,
},
},
// highlight-end
'apps/marketplace/src/plugins/marketplace/gql/generated.ts': {
Expand Down

0 comments on commit ea03d52

Please sign in to comment.