-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.ts
149 lines (127 loc) · 5.06 KB
/
schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Welcome to your schema
// Schema driven development is Keystone's modus operandi
//
// This file is where we define the lists, fields and hooks for our data.
// If you want to learn more about how lists are configured, please read
// - https://keystonejs.com/docs/config/lists
import { list } from '@keystone-6/core';
import { allowAll } from '@keystone-6/core/access';
// see https://keystonejs.com/docs/fields/overview for the full list of fields
// this is a few common fields for an example
import {
text,
relationship,
password,
timestamp,
select,
} from '@keystone-6/core/fields';
// the document field is a more complicated field, so it has it's own package
import { document } from '@keystone-6/fields-document';
// if you want to make your own fields, see https://keystonejs.com/docs/guides/custom-fields
// when using Typescript, you can refine your types to a stricter subset by importing
// the generated types from '.keystone/types'
import type { Lists } from '.keystone/types';
export const lists: Lists = {
User: list({
// WARNING
// for this starter project, anyone can create, query, update and delete anything
// if you want to prevent random people on the internet from accessing your data,
// you can find out more at https://keystonejs.com/docs/guides/auth-and-access-control
access: allowAll,
// this is the fields for our User list
fields: {
// by adding isRequired, we enforce that every User should have a name
// if no name is provided, an error will be displayed
name: text({ validation: { isRequired: true } }),
email: text({
validation: { isRequired: true },
// by adding isIndexed: 'unique', we're saying that no user can have the same
// email as another user - this may or may not be a good idea for your project
isIndexed: 'unique',
}),
password: password({ validation: { isRequired: true } }),
// we can use this field to see what Posts this User has authored
// more on that in the Post list below
posts: relationship({ ref: 'Post.author', many: true }),
createdAt: timestamp({
// this sets the timestamp to Date.now() when the user is first created
defaultValue: { kind: 'now' },
}),
},
}),
Post: list({
// WARNING
// for this starter project, anyone can create, query, update and delete anything
// if you want to prevent random people on the internet from accessing your data,
// you can find out more at https://keystonejs.com/docs/guides/auth-and-access-control
access: allowAll,
// this is the fields for our Post list
fields: {
title: text({ validation: { isRequired: true } }),
// the document field can be used for making rich editable content
// you can find out more at https://keystonejs.com/docs/guides/document-fields
content: document({
formatting: true,
layouts: [
[1, 1],
[1, 1, 1],
[2, 1],
[1, 2],
[1, 2, 1],
],
links: true,
dividers: true,
}),
// with this field, you can set a User as the author for a Post
author: relationship({
// we could have used 'User', but then the relationship would only be 1-way
ref: 'User.posts',
// this is some customisations for changing how this will look in the AdminUI
ui: {
displayMode: 'cards',
cardFields: ['name', 'email'],
inlineEdit: { fields: ['name', 'email'] },
linkToItem: true,
inlineConnect: true,
},
// a Post can only have one author
// this is the default, but we show it here for verbosity
many: false,
}),
// with this field, you can add some Tags to Posts
tags: relationship({
// we could have used 'Tag', but then the relationship would only be 1-way
ref: 'Tag.posts',
// a Post can have many Tags, not just one
many: true,
// this is some customisations for changing how this will look in the AdminUI
ui: {
displayMode: 'cards',
cardFields: ['name'],
inlineEdit: { fields: ['name'] },
linkToItem: true,
inlineConnect: true,
inlineCreate: { fields: ['name'] },
},
}),
},
}),
// this last list is our Tag list, it only has a name field for now
Tag: list({
// WARNING
// for this starter project, anyone can create, query, update and delete anything
// if you want to prevent random people on the internet from accessing your data,
// you can find out more at https://keystonejs.com/docs/guides/auth-and-access-control
access: allowAll,
// setting this to isHidden for the user interface prevents this list being visible in the Admin UI
ui: {
isHidden: true,
},
// this is the fields for our Tag list
fields: {
name: text(),
// this can be helpful to find out all the Posts associated with a Tag
posts: relationship({ ref: 'Post.tags', many: true }),
},
}),
};