forked from keystonejs/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.ts
46 lines (40 loc) · 1.47 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
import { denyAll, allOperations } from '@keystone-6/core/access'
import { list } from '@keystone-6/core'
import { text, relationship } from '@keystone-6/core/fields'
import type { Session } from './session'
import type { Lists } from '.keystone/types'
// WARNING: this example is for demonstration purposes only
// as with each of our examples, it has not been vetted
// or tested for any particular usage
function hasSession ({ session }: { session?: Session }) {
return Boolean(session)
}
export const lists = {
Post: list({
// WARNING - for this example, anyone can that can login can create, query, update and delete anything
// -- anyone with an account on the auth provider you are using can login
access: hasSession,
fields: {
title: text({ validation: { isRequired: true } }),
// the document field can be used for making rich editable content
// learn more at https://keystonejs.com/docs/guides/document-fields
content: text(),
author: relationship({ ref: 'Author.posts', many: false }),
},
}),
Author: list({
access: {
operation: {
...allOperations(denyAll),
query: hasSession,
},
},
fields: {
// this is the authentication identifier provided by our next-auth session
// which we use to identify a user
authId: text({ isIndexed: 'unique' }),
name: text(),
posts: relationship({ ref: 'Post.author', many: true }),
},
}),
} satisfies Lists<Session>