Skip to content

Commit c62e0a5

Browse files
committed
example updates
1 parent c36e555 commit c62e0a5

File tree

72 files changed

+254
-17
lines changed

Some content is hidden

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

72 files changed

+254
-17
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: 43 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
@@ -89,8 +102,8 @@ export const lists = {
89102
actionMode: 'hidden',
90103
},
91104
},
92-
},
93-
report: {
105+
}),
106+
report: action({
94107
access: allowAll,
95108
async resolve({ actionKey, where }, context) {
96109
console.log(`${actionKey}`, JSON.stringify({ where }))
@@ -130,7 +143,30 @@ export const lists = {
130143
actionMode: 'enabled',
131144
},
132145
},
133-
},
146+
}),
147+
updateWithoutValidation: action({
148+
access: allowAll,
149+
async resolve({ where, data }, context) {
150+
return context
151+
.withSession({ ...context.session, noValidation: true })
152+
.db.Post.updateOne({ where, data })
153+
},
154+
graphql: {
155+
singular: 'updatePostWithoutValidation',
156+
plural: 'updatePostsWithoutValidation',
157+
__data: true,
158+
},
159+
ui: {
160+
label: 'Save without validation',
161+
itemView: {
162+
navigation: 'refetch',
163+
hideToast: true,
164+
},
165+
listView: {
166+
actionMode: 'enabled',
167+
},
168+
},
169+
}),
134170
},
135171
ui: {
136172
listView: {
@@ -141,4 +177,4 @@ export const lists = {
141177
},
142178
},
143179
}),
144-
} satisfies Lists
180+
} 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)