Skip to content

Commit 6fd8507

Browse files
committed
example updates
1 parent 0a221e1 commit 6fd8507

File tree

73 files changed

+268
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+268
-19
lines changed

examples/actions/schema.graphql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ type Mutation {
141141
votePosts(data: [VotePostArgs!]!): [Post]
142142
reportAPost(where: PostWhereUniqueInput!): Post
143143
reportSomePosts(data: [ReportAPostArgs!]!): [Post]
144+
updatePostWithoutValidation(where: PostWhereUniqueInput!, data: PostUpdateInput!): Post
145+
updatePostsWithoutValidation(data: [UpdatePostWithoutValidationArgs!]!): [Post]
144146
}
145147

146148
input VotePostArgs {
@@ -151,6 +153,11 @@ input ReportAPostArgs {
151153
where: PostWhereUniqueInput!
152154
}
153155

156+
input UpdatePostWithoutValidationArgs {
157+
where: PostWhereUniqueInput!
158+
data: PostUpdateInput!
159+
}
160+
154161
type Query {
155162
post(where: PostWhereUniqueInput!): Post
156163
posts(where: PostWhereInput! = {}, orderBy: [PostOrderByInput!]! = [], take: Int, skip: Int! = 0, cursor: PostWhereUniqueInput): [Post!]

examples/actions/schema.ts

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { list } from '@keystone-6/core'
1+
import { list, action } from '@keystone-6/core'
22
import { allowAll, denyAll } from '@keystone-6/core/access'
33
import { checkbox, integer, text, timestamp } from '@keystone-6/core/fields'
44

@@ -34,9 +34,22 @@ const readOnly = {
3434
export const lists = {
3535
Post: list({
3636
access: allowAll, // WARNING: public
37+
3738
fields: {
3839
title: text(),
39-
content: text(),
40+
content: text({
41+
hooks: {
42+
validate: args => {
43+
if (
44+
typeof args.resolvedFieldData === 'string' &&
45+
!args.context.session?.noValidation &&
46+
!args.resolvedFieldData.includes('good content')
47+
) {
48+
args.addValidationError('Content is not valid')
49+
}
50+
},
51+
},
52+
}),
4053
hidden: checkbox({
4154
ui: {
4255
itemView: {
@@ -53,7 +66,7 @@ export const lists = {
5366
reportedAt: timestamp({ ...readOnly }),
5467
},
5568
actions: {
56-
vote: {
69+
vote: action({
5770
access: ({ context }) => {
5871
const ua = context.req?.headers['user-agent'] ?? ''
5972
// only allow voting from Chrome browsers
@@ -83,14 +96,15 @@ export const lists = {
8396
successMany: 'Voted for {countSuccess} {singular|plural}',
8497
},
8598
itemView: {
99+
actionMode: { disabled: { hidden: { equals: true } } },
86100
hidePrompt: true,
87101
},
88102
listView: {
89103
actionMode: 'hidden',
90104
},
91105
},
92-
},
93-
report: {
106+
}),
107+
report: action({
94108
access: allowAll,
95109
async resolve({ actionKey, where }, context) {
96110
console.log(`${actionKey}`, JSON.stringify({ where }))
@@ -130,7 +144,30 @@ export const lists = {
130144
actionMode: { disabled: { hidden: { equals: true } } },
131145
},
132146
},
133-
},
147+
}),
148+
updateWithoutValidation: action({
149+
access: allowAll,
150+
async resolve({ where, data }, context) {
151+
return context
152+
.withSession({ ...context.session, noValidation: true })
153+
.db.Post.updateOne({ where, data })
154+
},
155+
graphql: {
156+
singular: 'updatePostWithoutValidation',
157+
plural: 'updatePostsWithoutValidation',
158+
__data: true,
159+
},
160+
ui: {
161+
label: 'Save without validation',
162+
itemView: {
163+
navigation: 'refetch',
164+
hideToast: true,
165+
},
166+
listView: {
167+
actionMode: { disabled: { hidden: { equals: true } } },
168+
},
169+
},
170+
}),
134171
},
135172
ui: {
136173
listView: {
@@ -141,4 +178,4 @@ export const lists = {
141178
},
142179
},
143180
}),
144-
} satisfies Lists
181+
} satisfies Lists<{ noValidation?: boolean }>

examples/assets-local/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,14 @@ type KeystoneAdminUIActionMetaMessages {
258258
}
259259

260260
type KeystoneAdminUIActionMetaGraphQL {
261+
fields: [String!]!
261262
names: KeystoneAdminUIActionMetaGraphQLNames!
262263
}
263264

264265
type KeystoneAdminUIActionMetaGraphQLNames {
265266
one: String!
266267
many: String
268+
data: String
267269
}
268270

269271
type KeystoneAdminUIActionMetaItemView {

examples/assets-s3/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,14 @@ type KeystoneAdminUIActionMetaMessages {
258258
}
259259

260260
type KeystoneAdminUIActionMetaGraphQL {
261+
fields: [String!]!
261262
names: KeystoneAdminUIActionMetaGraphQLNames!
262263
}
263264

264265
type KeystoneAdminUIActionMetaGraphQLNames {
265266
one: String!
266267
many: String
268+
data: String
267269
}
268270

269271
type KeystoneAdminUIActionMetaItemView {

examples/auth-magic-link/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,14 @@ type KeystoneAdminUIActionMetaMessages {
244244
}
245245

246246
type KeystoneAdminUIActionMetaGraphQL {
247+
fields: [String!]!
247248
names: KeystoneAdminUIActionMetaGraphQLNames!
248249
}
249250

250251
type KeystoneAdminUIActionMetaGraphQLNames {
251252
one: String!
252253
many: String
254+
data: String
253255
}
254256

255257
type KeystoneAdminUIActionMetaItemView {

examples/auth/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,14 @@ type KeystoneAdminUIActionMetaMessages {
221221
}
222222

223223
type KeystoneAdminUIActionMetaGraphQL {
224+
fields: [String!]!
224225
names: KeystoneAdminUIActionMetaGraphQLNames!
225226
}
226227

227228
type KeystoneAdminUIActionMetaGraphQLNames {
228229
one: String!
229230
many: String
231+
data: String
230232
}
231233

232234
type KeystoneAdminUIActionMetaItemView {

examples/better-list-search/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,14 @@ type KeystoneAdminUIActionMetaMessages {
370370
}
371371

372372
type KeystoneAdminUIActionMetaGraphQL {
373+
fields: [String!]!
373374
names: KeystoneAdminUIActionMetaGraphQLNames!
374375
}
375376

376377
type KeystoneAdminUIActionMetaGraphQLNames {
377378
one: String!
378379
many: String
380+
data: String
379381
}
380382

381383
type KeystoneAdminUIActionMetaItemView {

examples/byte-encoding/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,14 @@ type KeystoneAdminUIActionMetaMessages {
212212
}
213213

214214
type KeystoneAdminUIActionMetaGraphQL {
215+
fields: [String!]!
215216
names: KeystoneAdminUIActionMetaGraphQLNames!
216217
}
217218

218219
type KeystoneAdminUIActionMetaGraphQLNames {
219220
one: String!
220221
many: String
222+
data: String
221223
}
222224

223225
type KeystoneAdminUIActionMetaItemView {

examples/cloudinary/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,14 @@ type KeystoneAdminUIActionMetaMessages {
276276
}
277277

278278
type KeystoneAdminUIActionMetaGraphQL {
279+
fields: [String!]!
279280
names: KeystoneAdminUIActionMetaGraphQLNames!
280281
}
281282

282283
type KeystoneAdminUIActionMetaGraphQLNames {
283284
one: String!
284285
many: String
286+
data: String
285287
}
286288

287289
type KeystoneAdminUIActionMetaItemView {

examples/custom-admin-ui-logo/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,14 @@ type KeystoneAdminUIActionMetaMessages {
343343
}
344344

345345
type KeystoneAdminUIActionMetaGraphQL {
346+
fields: [String!]!
346347
names: KeystoneAdminUIActionMetaGraphQLNames!
347348
}
348349

349350
type KeystoneAdminUIActionMetaGraphQLNames {
350351
one: String!
351352
many: String
353+
data: String
352354
}
353355

354356
type KeystoneAdminUIActionMetaItemView {

0 commit comments

Comments
 (0)