Skip to content

Commit

Permalink
fix(graphql-types): ensure short-description is defined
Browse files Browse the repository at this point in the history
This commit ensures that `spec.short_description` is difined before it's
accessed. There is the possibility a param does not include that
property so we should not assume it is always defined.
  • Loading branch information
luqven committed May 23, 2023
1 parent 11f64b3 commit 5ad4503
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/modules/gatsby-plugin/graphqlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const ImgixParamsInputType = ({
new Set(expects.map((expect) => expect.type)),
);

// @ts-expect-error TODO: remove this after short_description is marked as required in imgix-url-params
const shortDescription = spec.short_description || spec.display_name;
const type = expectsTypes.every((type) => type === 'integer')
? 'Int'
: expectsTypes.every(
Expand All @@ -52,9 +54,9 @@ export const ImgixParamsInputType = ({
fields[name] = {
type,
description:
spec.short_description +
shortDescription +
// Ensure the description ends with a period.
(spec.short_description.slice(-1) === '.' ? '' : '.'),
(shortDescription.slice(-1) === '.' ? '' : '.'),
};

const field = fields[
Expand Down

0 comments on commit 5ad4503

Please sign in to comment.