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: stringbackgroundImage: ImagePropsctaLink: DynamicLink | null
1. Define the shared type
What to add
- Add the new value to
BannerTypename. GraphQL Codegen uses this enum for CMS banner types. - Add a typed banner model in
Banner.ts. - Add the model to the
AnyBannerunion and the exports. - If necessary, add a
...UpdatePatchtype and mapping inBannerUpdate.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
- Add a new
typenameoption in thetypename: select({ options: [...] }). - Add all visible fields to
VISIBLE_BANNER_FIELDS_BY_TYPENAMEinBannerFieldRegistry.ts. - Add base metadata for every new field in
FIELD_DEFINITIONS_BY_NAME. - Mark fields required during creation with
requiredForCreate: true. - Add field-level MCP hints to explain payload behavior that the schema does not show.
- Define the Keystone fields, such as
textandrelationship. - For shop functionality, add the banner typename to
SHOP_BANNER_TYPENAMESinpackages/shared/src/util/projectSettings.ts. - For car-dealer functionality, add the banner typename to
CAR_DEALER_BANNER_TYPENAMESinpackages/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
- Add the base definition to
FIELD_DEFINITIONS_BY_NAME. - Add the field descriptor to the banner entry in
VISIBLE_BANNER_FIELDS_BY_TYPENAME. - Set
requiredForCreatewhen the field is necessary for creation or hydration. - Set
autoManagedfor order fields that are usually maintained by the Admin UI. - Set
relationshipWrapperfor relation fields. - Add
enumValuesfor enum and enum-array fields. - Add
hintsfor 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
- For settings stored in
bannerConfig, register the keys in the banner field registry. Duplication copies them automatically. - For a separate column or relationship, select the field in
DUPLICATE_BANNER_QUERYand copy it increateBannerShell. - 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
- Add a fragment for the new banner fields in
banners.graphql.ts. - Add single and batch queries (
GetPromoStripBanner,GetPromoStripBannersByIds). - Import these query constants in
banners.resolver.ts. - Add a
fetchPromoStripBannerfunction. - Add
BannerTypename.PromoStripBanneringetBatchQueryByTypename.
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
- Add
case BannerTypename.PromoStripBannertogetReferencedBanner. - Add
case BannerTypename.PromoStripBannertodecorateReferencedBanner. - Implement:
mapPromoStripBanner(...)getPromoStripBannerById(...)
- 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
- Create the layout component below.
- Add the dynamic renderer to
bannerRegistry.tsx. - Add the
bannerVariantswitch case inBanner.tsx. - For translated labels, declare and export component
nsandinitialNsarrays. - Set
loadMetadatato 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
- Add the new banner to
determineNewBannerLCPValue. - 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
- Run
pnpm util:buildin the repository root. - Create one CMS banner of the new type and attach it to a page.
- Duplicate the page or banner. Make sure the duplicate contains the new fields.
- Open the frontend page. Test rendering and loading behavior.
The banner integration is complete when all four validation steps pass.
Related references
Banner field metadata. Integration points. Common banner properties.