Skip to content

Instantly share code, notes, and snippets.

@bsgreenb
Created April 16, 2020 07:00
Show Gist options
  • Save bsgreenb/05202d74c7ef079970b536fad0fc5c88 to your computer and use it in GitHub Desktop.
Save bsgreenb/05202d74c7ef079970b536fad0fc5c88 to your computer and use it in GitHub Desktop.
import { ContentfulAuthor as NulledContentfulAuthor } from "./generated-types";
import { ContentfulCategory as NulledContentfulCategory } from "./generated-types";
import { ContentfulPost as NulledContentfulPost } from "./generated-types";
import { ContentfulPage as NulledContentfulPage } from "./generated-types";
import {
ContentfulPostBodyRichTextNode,
ContentfulProductCardBodyRichTextNode,
} from "./generated-types";
import { ContentfulProduct as NulledContentfulProduct } from "./generated-types";
import { ContentfulProductCard as NulledContentfulProductCard } from "./generated-types";
import { ContentfulProductBuyUrlTextNode as NulledContentfulProductBuyUrlTextNode } from "./generated-types";
import { GatsbyImageProps } from "gatsby-image";
import { RequireFields } from "./utility-types";
export type ContentfulAuthor = RequireFields<NulledContentfulAuthor, "name"> & {
photo: GatsbyImageProps;
};
export type ContentfulCategory = RequireFields<
NulledContentfulCategory,
"title" | "slug"
> & {
featuredImage: GatsbyImageProps;
parentCategory: ContentfulCategory;
subCategories: ContentfulCategory[];
featuredPosts: ContentfulPost[];
featuredProducts: ContentfulProduct[];
};
// Right now category is only menu item type, but I can envision others.
export type ContentfulMenuItem = Pick<ContentfulCategory, "title" | "slug">;
export type ContentfulMenu = {
menuItems: ContentfulMenuItem[];
};
// TODO: add publish override, types
export type ContentfulPost = RequireFields<
NulledContentfulPost,
"title" | "subTitle" | "slug" | "updatedAt" | "id"
> & {
featuredImage: GatsbyImageProps;
childContentfulPostBodyRichTextNode: RequireFields<
ContentfulPostBodyRichTextNode,
"json"
>;
category: ContentfulCategory;
author: Pick<ContentfulAuthor, "name" | "photo">;
};
export type ContentfulProduct = RequireFields<
NulledContentfulProduct,
"title" | "slug" | "id" | "hidePage"
> & {
buyUrl: RequireFields<NulledContentfulProductBuyUrlTextNode, "buyUrl">; // Text types require extra stuff
featuredImage: GatsbyImageProps;
category: ContentfulCategory;
};
export type ContentfulProductCard = RequireFields<
NulledContentfulProductCard,
"title"
> & {
product: Pick<ContentfulProduct, "title" | "featuredImage" | "buyUrl">;
childContentfulProductCardBodyRichTextNode: RequireFields<
ContentfulProductCardBodyRichTextNode,
"json"
>;
};
export type ContentfulPage = RequireFields<
NulledContentfulPage,
"title" | "slug"
> & {
featuredImage: GatsbyImageProps;
};
type ContentfulEmbed<T> = {
fields: T;
};
export type ContentfulProductEmbed = ContentfulEmbed<
ContentfulProduct & {
featuredImage: ContentfulEmbed<{
file: {
url: string;
};
}>;
}
>;
export type ContentfulProductCardEmbed = ContentfulEmbed<
ContentfulProductCard & {
product: ContentfulProductEmbed;
}
>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment