Skip to content

Instantly share code, notes, and snippets.

@eabald
Created February 20, 2022 20:10
import { list } from '@keystone-6/core';
import {
text,
relationship,
password,
timestamp,
select,
} from '@keystone-6/core/fields';
import { document } from '@keystone-6/fields-document';
import { Lists } from '.keystone/types';
export const lists: Lists = {
User: list({
fields: {
name: text({ validation: { isRequired: true } }),
email: text({
validation: { isRequired: true },
isIndexed: 'unique',
isFilterable: true,
}),
password: password({ validation: { isRequired: true } }),
posts: relationship({ ref: 'Post.author', many: true }),
},
ui: {
listView: {
initialColumns: ['name', 'posts'],
},
},
}),
Post: list({
fields: {
title: text(),
status: select({
options: [
{ label: 'Published', value: 'published' },
{ label: 'Draft', value: 'draft' },
],
defaultValue: 'draft',
ui: {
displayMode: 'segmented-control',
},
}),
content: document({
formatting: true,
layouts: [
[1, 1],
[1, 1, 1],
[2, 1],
[1, 2],
[1, 2, 1],
],
links: true,
dividers: true,
}),
publishDate: timestamp(),
author: relationship({
ref: 'User.posts',
ui: {
displayMode: 'cards',
cardFields: ['name', 'email'],
inlineEdit: { fields: ['name', 'email'] },
linkToItem: true,
inlineCreate: { fields: ['name', 'email'] },
},
}),
tags: relationship({
ref: 'Tag.posts',
ui: {
displayMode: 'cards',
cardFields: ['name'],
inlineEdit: { fields: ['name'] },
linkToItem: true,
inlineConnect: true,
inlineCreate: { fields: ['name'] },
},
many: true,
}),
},
}),
Tag: list({
ui: {
isHidden: true,
},
fields: {
name: text(),
posts: relationship({ ref: 'Post.tags', many: true }),
},
}),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment