1- import { g , list } from '@keystone-6/core'
1+ import { initG , list } from '@keystone-6/core'
22import { allowAll } from '@keystone-6/core/access'
33import { select , relationship , text , timestamp } from '@keystone-6/core/fields'
4- import { type Context , type Lists } from '.keystone/types'
4+ import type { TypeInfo , Lists } from '.keystone/types'
5+
6+ const g = initG < TypeInfo > ( )
7+ type g < T > = initG < T >
58
69export const lists = {
710 Post : list ( {
@@ -37,23 +40,23 @@ export const extendGraphqlSchema = g.extend(base => {
3740 fields : {
3841 draft : g . field ( {
3942 type : g . Int ,
40- resolve ( { authorId } , args , context : Context ) {
43+ resolve ( { authorId } , args , context ) {
4144 return context . query . Post . count ( {
4245 where : { author : { id : { equals : authorId } } , status : { equals : 'draft' } } ,
4346 } )
4447 } ,
4548 } ) ,
4649 published : g . field ( {
4750 type : g . Int ,
48- resolve ( { authorId } , args , context : Context ) {
51+ resolve ( { authorId } , args , context ) {
4952 return context . query . Post . count ( {
5053 where : { author : { id : { equals : authorId } } , status : { equals : 'published' } } ,
5154 } )
5255 } ,
5356 } ) ,
5457 latest : g . field ( {
5558 type : base . object ( 'Post' ) ,
56- async resolve ( { authorId } , args , context : Context ) {
59+ async resolve ( { authorId } , args , context ) {
5760 const [ post ] = await context . db . Post . findMany ( {
5861 take : 1 ,
5962 orderBy : { publishDate : 'desc' } ,
@@ -72,7 +75,7 @@ export const extendGraphqlSchema = g.extend(base => {
7275 // with the name provided or throw if it doesn't exist
7376 type : base . object ( 'Post' ) ,
7477 args : { id : g . arg ( { type : g . nonNull ( g . ID ) } ) } ,
75- resolve ( source , { id } , context : Context ) {
78+ resolve ( source , { id } , context ) {
7679 // Note we use `context.db.Post` here as we have a return type
7780 // of Post, and this API provides results in the correct format.
7881 // If you accidentally use `context.query.Post` here you can expect problems
@@ -90,7 +93,7 @@ export const extendGraphqlSchema = g.extend(base => {
9093 banPost : g . field ( {
9194 type : base . object ( 'Post' ) ,
9295 args : { id : g . arg ( { type : g . nonNull ( g . ID ) } ) } ,
93- resolve ( source , { id } , context : Context ) {
96+ resolve ( source , { id } , context ) {
9497 return context . db . Post . updateOne ( {
9598 where : { id } ,
9699 data : { status : 'banned' } ,
@@ -107,7 +110,7 @@ export const extendGraphqlSchema = g.extend(base => {
107110 id : g . arg ( { type : g . nonNull ( g . ID ) } ) ,
108111 seconds : g . arg ( { type : g . nonNull ( g . Int ) , defaultValue : 600 } ) ,
109112 } ,
110- resolve ( source , { id, seconds } , context : Context ) {
113+ resolve ( source , { id, seconds } , context ) {
111114 const cutoff = new Date ( Date . now ( ) - seconds * 1000 )
112115
113116 // Note we use `context.db.Post` here as we have a return type
0 commit comments