Skip to Content
How-to guidesDevelopmentAdd a banner type

Add a banner type

Audience: developers who work with TypeScript, Keystone, GraphQL, and React.

Prerequisites

Use a repository checkout with its workspace dependencies installed. You must be able to start the CMS, backend, and frontend. The examples add one banner type across all packages. They are additions to existing files. Use a unique typename for your implementation.

See integration points for the file map and the banner pipeline for the design.

Example banner in this guide: PromoStripBanner

  • typename: BannerTypename.PromoStripBanner
  • fields:
    • message: string
    • backgroundImage: ImageProps
    • ctaLink: DynamicLink | null

1. Define the shared type

What to add

  1. Add the new value to BannerTypename. GraphQL Codegen uses this enum for CMS banner types.
  2. Add a typed banner model in Banner.ts.
  3. Add the model to the AnyBanner union and the exports.
  4. If necessary, add a ...UpdatePatch type and mapping in BannerUpdate.ts.

Example

// BannerTypename.ts enum BannerTypename { // ... PromoStripBanner = 'PromoStripBanner', }
// Banner.ts type PromoStripBanner = DefaultBannerProps<BannerTypename.PromoStripBanner> & BannerCSS & { id: string; message: string; backgroundImage: ImageProps; ctaLink: DynamicLink | null; }; type AnyBanner = // ... | PromoStripBanner;
// BannerUpdate.ts (only if update-patch support is needed) type PromoStripBannerUpdatePatch = BannerSharedUpdatePatch & { message?: string | null; }; type BannerUpdatePatchByTypename = { // ... [BannerTypename.PromoStripBanner]: PromoStripBannerUpdatePatch; };

2. Add CMS fields

What to add

  1. Add a new typename option in the typename: select({ options: [...] }).
  2. Add all visible fields to VISIBLE_BANNER_FIELDS_BY_TYPENAME in BannerFieldRegistry.ts.
  3. Add base metadata for every new field in FIELD_DEFINITIONS_BY_NAME.
  4. Mark fields required during creation with requiredForCreate: true.
  5. Add field-level MCP hints to explain payload behavior that the schema does not show.
  6. Define the Keystone fields, such as text and relationship.
  7. For shop functionality, add the banner typename to SHOP_BANNER_TYPENAMES in packages/shared/src/util/projectSettings.ts.
  8. For car-dealer functionality, add the banner typename to CAR_DEALER_BANNER_TYPENAMES in packages/shared/src/util/projectSettings.ts.

Import CMS field metadata from @haendlerapp/shared/server. The public shared entry must not export this metadata.

Example

// packages/shared/src/util/BannerFieldRegistry.ts const FIELD_DEFINITIONS_BY_NAME: Record<string, BannerFieldBaseDefinition> = { // ... promoMessage: { type: 'string', hints: ['A promo strip without a message is filtered as invalid on fetch.'], }, promoBackgroundImage: { type: 'relation_one', relationshipWrapper: 'oneToOne', hints: ['Use a connected ImageList record for the background image.'], }, promoCtaLink: { type: 'relation_one', relationshipWrapper: 'oneToOne', }, }; export const VISIBLE_BANNER_FIELDS_BY_TYPENAME = { // ... [BannerTypename.PromoStripBanner]: withDefaultVisibleFields([ defineBannerField('promoMessage', { requiredForCreate: true }), defineBannerField('promoBackgroundImage', { requiredForCreate: true }), defineBannerField('promoCtaLink'), ]), };
// typename select option { label: 'Promo Strip Banner', value: BannerTypename.PromoStripBanner, }
// fields promoMessage: text({ label: 'Nachricht', ui: fieldModeFor('promoMessage'), }), promoBackgroundImage: relationship({ ref: 'ImageList', many: false, label: 'Hintergrundbild', ui: fieldModeFor('promoBackgroundImage'), }), promoCtaLink: relationship({ ref: 'Link', many: false, label: 'CTA Link', ui: fieldModeFor('promoCtaLink'), }),

Add a new field

  1. Add the base definition to FIELD_DEFINITIONS_BY_NAME.
  2. Add the field descriptor to the banner entry in VISIBLE_BANNER_FIELDS_BY_TYPENAME.
  3. Set requiredForCreate when the field is necessary for creation or hydration.
  4. Set autoManaged for order fields that are usually maintained by the Admin UI.
  5. Set relationshipWrapper for relation fields.
  6. Add enumValues for enum and enum-array fields.
  7. Add hints for hidden behavior that an MCP caller needs to know.

Supply enough metadata for AI callers to create, update, and validate the banner without reading its backend mapper.

3. Preserve duplication

What to add

  1. For settings stored in bannerConfig, register the keys in the banner field registry. Duplication copies them automatically.
  2. For a separate column or relationship, select the field in DUPLICATE_BANNER_QUERY and copy it in createBannerShell.
  3. If the banner owns nested entities, add deep-copy logic in patchBannerWithOwnedChildrenAndNestedContent.

Example

// fetchBannerForDuplication query promoMessage promoBackgroundImage { id } promoCtaLink { id } // createBannerShell data promoMessage: sourceBanner?.promoMessage ?? null, promoBackgroundImage: sourceBanner?.promoBackgroundImage?.id ? { connect: { id: String(sourceBanner.promoBackgroundImage.id) } } : undefined, promoCtaLink: sourceBanner?.promoCtaLink?.id ? { connect: { id: String(sourceBanner.promoCtaLink.id) } } : undefined,

4. Add backend queries and resolvers

What to add

  1. Add a fragment for the new banner fields in banners.graphql.ts.
  2. Add single and batch queries (GetPromoStripBanner, GetPromoStripBannersByIds).
  3. Import these query constants in banners.resolver.ts.
  4. Add a fetchPromoStripBanner function.
  5. Add BannerTypename.PromoStripBanner in getBatchQueryByTypename.

Example

// packages/backend/src/globals/graphql/queries/banners.graphql.ts const PROMO_STRIP_FIELDS = gql` fragment PromoStripBannerFields on Banner { promoMessage promoBackgroundImage { ...ImageDetails } promoCtaLink { ...LinkLiteDetails } } ${IMAGE_FRAGMENT} ${LINK_LITE_FRAGMENT} `; const GET_PROMO_STRIP_BANNER_QUERY = gql` query GetPromoStripBanner($id: ID!) { banner(where: { id: $id, typename: { equals: PromoStripBanner } }) { ...PromoStripBannerFields } } ${PROMO_STRIP_FIELDS} `; const GET_PROMO_STRIP_BANNERS_BY_IDS_QUERY = gql` query GetPromoStripBannersByIds($ids: [ID!]!) { banners( where: { id: { in: $ids }, typename: { equals: PromoStripBanner } } ) { ...PromoStripBannerFields } } ${PROMO_STRIP_FIELDS} `;
// packages/backend/src/modules/banners/banners.resolver.ts import { GET_PROMO_STRIP_BANNER_QUERY, GET_PROMO_STRIP_BANNERS_BY_IDS_QUERY, } from '@/globals/graphql/queries/banners.graphql'; // inside getBatchQueryByTypename(...) case BannerTypename.PromoStripBanner: return GET_PROMO_STRIP_BANNERS_BY_IDS_QUERY; public fetchPromoStripBanner(id: string, fetchPolicy: FetchPolicy) { return this.fetchBannerById<GraphQL.GetPromoStripBannerQuery>({ label: 'fetchPromoStripBanner', errorMessage: 'Failed to query promo strip banner', query: GET_PROMO_STRIP_BANNER_QUERY, id, fetchPolicy, }); }

5. Map backend data

What to add

  1. Add case BannerTypename.PromoStripBanner to getReferencedBanner.
  2. Add case BannerTypename.PromoStripBanner to decorateReferencedBanner.
  3. Implement:
    • mapPromoStripBanner(...)
    • getPromoStripBannerById(...)
  4. To support patch updates, add the banner type case in buildBannerUpdateInput.

Example

// packages/backend/src/modules/banners/banners.service.ts private mapPromoStripBanner( data: ApolloLink.Result<GraphQL.GetPromoStripBannerQuery>['data'], originDomain?: string | null ): PromoStripBanner | null { const banner = data?.banner; if (!banner?.id || !banner.promoMessage || !banner.promoBackgroundImage) { return null; } return { typename: BannerTypename.PromoStripBanner, id: banner.id, title: banner.title ?? null, titleTag: banner.titleTag ?? 'h2', titleAlign: banner.titleAlign ?? 'left', cssId: banner.cssId ?? null, cssClasses: banner.cssClasses ?? null, message: banner.promoMessage, backgroundImage: DbParser.getImage(banner.promoBackgroundImage), ctaLink: this.resolveLink(banner.promoCtaLink, originDomain), }; } private async getPromoStripBannerById( id: string, fetchPolicy: FetchPolicy, originDomain?: string | null ): Promise<PromoStripBanner | null> { return this.bannersResolver .fetchPromoStripBanner(id, fetchPolicy) .then((query) => this.mapPromoStripBanner(query.data, originDomain)) .catch((err) => { logger.error( `[getPromoStripBannerById] Fetching promo strip banner with id: ${id} failed.`, err ); return null; }); }
// getReferencedBanner(...) case BannerTypename.PromoStripBanner: result = await this.getPromoStripBannerById(info.id, fetchPolicy, originDomain); break; // decorateReferencedBanner(...) case BannerTypename.PromoStripBanner: result = this.mapPromoStripBanner(data, originDomain); break;
// buildBannerUpdateInput(...) case BannerTypename.PromoStripBanner: { const typedPatch = patch as BannerUpdatePatch<BannerTypename.PromoStripBanner>; return { ...common, ...(typedPatch.message !== undefined ? { promoMessage: typedPatch.message } : {}), }; }

6. Register the frontend renderer

What to add

  1. Create the layout component below.
  2. Add the dynamic renderer to bannerRegistry.tsx.
  3. Add the bannerVariant switch case in Banner.tsx.
  4. For translated labels, declare and export component ns and initialNs arrays.
  5. Set loadMetadata to import the source component when it needs translation catalogs.

This example renders CMS text and needs no translation catalog. Its metadata loader is null.

Example

// packages/frontend/src/components/blocks/layout/PromoStripBanner.tsx import type { PromoStripBanner as PromoStripBannerType } from '@haendlerapp/types'; type PromoStripBannerProps = { component: Omit<PromoStripBannerType, 'typename'>; priority: boolean; }; function PromoStripBanner({ component, priority }: PromoStripBannerProps) { return ( <section className="promo-strip-banner relative w-full"> <img src={component.backgroundImage.file.url} alt={component.backgroundImage.alt ?? ''} loading={priority ? 'eager' : 'lazy'} /> <p>{component.message}</p> </section> ); } export { PromoStripBanner };
// packages/frontend/src/components/ui/banners/bannerRegistry.tsx [BannerTypename.PromoStripBanner]: { Component: dynamic(() => import('@/components/blocks/layout/PromoStripBanner').then( (c) => c.PromoStripBanner ) ), loadMetadata: null, },
// packages/frontend/src/components/ui/banners/Banner.tsx // inside switch(bannerData.typename) case BannerTypename.PromoStripBanner: return ( <BannerWrapper {...wrapperProps}> <BannerRegistry.PromoStripBanner.Component component={bannerData} priority={priority} /> </BannerWrapper> );

7. Set media loading priority

What to add

  1. Add the new banner to determineNewBannerLCPValue.
  2. If it can contain large media, also include it in checkGridWrapperForMedia.

Example

// packages/frontend/src/util/createLcpEvaluator.ts function checkGridWrapperForMedia(banner: GridWrapperBanner): boolean { // ... switch (column.typename) { case BannerTypename.PromoStripBanner: return true; // existing cases... } } function determineNewBannerLCPValue(banner: AnyBanner): number { switch (banner.typename) { case BannerTypename.PromoStripBanner: return 5; // image-heavy banner; keep eager threshold behavior similar to ImageBlock // existing cases... } }

8. Verify the integration

  1. Run pnpm util:build in the repository root.
  2. Create one CMS banner of the new type and attach it to a page.
  3. Duplicate the page or banner. Make sure the duplicate contains the new fields.
  4. Open the frontend page. Test rendering and loading behavior.

The banner integration is complete when all four validation steps pass.

Banner field metadata. Integration points. Common banner properties.

Last updated on