1
- import { g , list } from '@keystone-6/core'
1
+ import { gWithContext , list } from '@keystone-6/core'
2
2
import { allowAll } from '@keystone-6/core/access'
3
3
import { select , relationship , text , timestamp } from '@keystone-6/core/fields'
4
- import { type Context , type Lists } from '.keystone/types'
4
+ import type { Context , Lists } from '.keystone/types'
5
+
6
+ const g = gWithContext < Context > ( )
7
+ type g < T > = gWithContext . infer < T >
5
8
6
9
export const lists = {
7
10
Post : list ( {
@@ -37,23 +40,23 @@ export const extendGraphqlSchema = g.extend(base => {
37
40
fields : {
38
41
draft : g . field ( {
39
42
type : g . Int ,
40
- resolve ( { authorId } , args , context : Context ) {
43
+ resolve ( { authorId } , args , context ) {
41
44
return context . query . Post . count ( {
42
45
where : { author : { id : { equals : authorId } } , status : { equals : 'draft' } } ,
43
46
} )
44
47
} ,
45
48
} ) ,
46
49
published : g . field ( {
47
50
type : g . Int ,
48
- resolve ( { authorId } , args , context : Context ) {
51
+ resolve ( { authorId } , args , context ) {
49
52
return context . query . Post . count ( {
50
53
where : { author : { id : { equals : authorId } } , status : { equals : 'published' } } ,
51
54
} )
52
55
} ,
53
56
} ) ,
54
57
latest : g . field ( {
55
58
type : base . object ( 'Post' ) ,
56
- async resolve ( { authorId } , args , context : Context ) {
59
+ async resolve ( { authorId } , args , context ) {
57
60
const [ post ] = await context . db . Post . findMany ( {
58
61
take : 1 ,
59
62
orderBy : { publishDate : 'desc' } ,
@@ -72,7 +75,7 @@ export const extendGraphqlSchema = g.extend(base => {
72
75
// with the name provided or throw if it doesn't exist
73
76
type : base . object ( 'Post' ) ,
74
77
args : { id : g . arg ( { type : g . nonNull ( g . ID ) } ) } ,
75
- resolve ( source , { id } , context : Context ) {
78
+ resolve ( source , { id } , context ) {
76
79
// Note we use `context.db.Post` here as we have a return type
77
80
// of Post, and this API provides results in the correct format.
78
81
// If you accidentally use `context.query.Post` here you can expect problems
@@ -90,7 +93,7 @@ export const extendGraphqlSchema = g.extend(base => {
90
93
banPost : g . field ( {
91
94
type : base . object ( 'Post' ) ,
92
95
args : { id : g . arg ( { type : g . nonNull ( g . ID ) } ) } ,
93
- resolve ( source , { id } , context : Context ) {
96
+ resolve ( source , { id } , context ) {
94
97
return context . db . Post . updateOne ( {
95
98
where : { id } ,
96
99
data : { status : 'banned' } ,
@@ -107,7 +110,7 @@ export const extendGraphqlSchema = g.extend(base => {
107
110
id : g . arg ( { type : g . nonNull ( g . ID ) } ) ,
108
111
seconds : g . arg ( { type : g . nonNull ( g . Int ) , defaultValue : 600 } ) ,
109
112
} ,
110
- resolve ( source , { id, seconds } , context : Context ) {
113
+ resolve ( source , { id, seconds } , context ) {
111
114
const cutoff = new Date ( Date . now ( ) - seconds * 1000 )
112
115
113
116
// Note we use `context.db.Post` here as we have a return type
0 commit comments