Skip to content

Commit 323da1d

Browse files
emmatowndcousens
authored andcommitted
update examples/actions (and other GraphQL schemas)
1 parent 1462546 commit 323da1d

73 files changed

Lines changed: 268 additions & 19 deletions

File tree

Some content is hidden

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

examples/actions/schema.graphql

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

147149
input VotePostArgs {
@@ -152,6 +154,11 @@ input ReportAPostArgs {
152154
where: PostWhereUniqueInput!
153155
}
154156

157+
input UpdatePostWithoutValidationArgs {
158+
where: PostWhereUniqueInput!
159+
data: PostUpdateInput!
160+
}
161+
155162
type Query {
156163
post(where: PostWhereUniqueInput!): Post
157164
posts(

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

@@ -38,9 +38,22 @@ const isReportDisabled = {
3838
export const lists = {
3939
Post: list({
4040
access: allowAll, // WARNING: public
41+
4142
fields: {
4243
title: text(),
43-
content: text(),
44+
content: text({
45+
hooks: {
46+
validate: args => {
47+
if (
48+
typeof args.resolvedFieldData === 'string' &&
49+
!args.context.session?.noValidation &&
50+
!args.resolvedFieldData.includes('good content')
51+
) {
52+
args.addValidationError('Content is not valid')
53+
}
54+
},
55+
},
56+
}),
4457
hidden: checkbox({
4558
ui: {
4659
itemView: {
@@ -57,7 +70,7 @@ export const lists = {
5770
reportedAt: timestamp({ ...readOnly }),
5871
},
5972
actions: {
60-
vote: {
73+
vote: action({
6174
access: ({ context }) => {
6275
const ua = context.req?.headers['user-agent'] ?? ''
6376
// only allow voting from Chrome browsers
@@ -87,14 +100,15 @@ export const lists = {
87100
successMany: 'Voted for {countSuccess} {singular|plural}',
88101
},
89102
itemView: {
103+
actionMode: { disabled: { hidden: { equals: true } } },
90104
hidePrompt: true,
91105
},
92106
listView: {
93107
actionMode: 'hidden',
94108
},
95109
},
96-
},
97-
report: {
110+
}),
111+
report: action({
98112
access: allowAll,
99113
async resolve({ actionKey, where }, context) {
100114
console.log(`${actionKey}`, JSON.stringify({ where }))
@@ -136,7 +150,30 @@ export const lists = {
136150
actionMode: { disabled: isReportDisabled },
137151
},
138152
},
139-
},
153+
}),
154+
updateWithoutValidation: action({
155+
access: allowAll,
156+
async resolve({ where, data }, context) {
157+
return context
158+
.withSession({ ...context.session, noValidation: true })
159+
.db.Post.updateOne({ where, data })
160+
},
161+
graphql: {
162+
singular: 'updatePostWithoutValidation',
163+
plural: 'updatePostsWithoutValidation',
164+
__data: true,
165+
},
166+
ui: {
167+
label: 'Save without validation',
168+
itemView: {
169+
navigation: 'refetch',
170+
hideToast: true,
171+
},
172+
listView: {
173+
actionMode: { disabled: { hidden: { equals: true } } },
174+
},
175+
},
176+
}),
140177
},
141178
ui: {
142179
listView: {
@@ -147,4 +184,4 @@ export const lists = {
147184
},
148185
},
149186
}),
150-
} satisfies Lists
187+
} 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)