11import {
22 type BaseListTypeInfo ,
3- fieldType ,
43 type FieldTypeFunc ,
54 type CommonFieldConfig ,
65 type ImageData ,
76 type ImageExtension ,
87 type KeystoneContext ,
8+ fieldType ,
99} from '../../../types'
1010import { graphql } from '../../..'
1111import { SUPPORTED_IMAGE_EXTENSIONS } from './utils'
@@ -37,9 +37,9 @@ const ImageFieldOutput = graphql.object<ImageData & { storage: string }>()({
3737 fields : {
3838 id : graphql . field ( { type : graphql . nonNull ( graphql . ID ) } ) ,
3939 filesize : graphql . field ( { type : graphql . nonNull ( graphql . Int ) } ) ,
40- extension : graphql . field ( { type : graphql . nonNull ( ImageExtensionEnum ) } ) ,
4140 width : graphql . field ( { type : graphql . nonNull ( graphql . Int ) } ) ,
4241 height : graphql . field ( { type : graphql . nonNull ( graphql . Int ) } ) ,
42+ extension : graphql . field ( { type : graphql . nonNull ( ImageExtensionEnum ) } ) ,
4343 url : graphql . field ( {
4444 type : graphql . nonNull ( graphql . String ) ,
4545 resolve ( data , args , context ) {
@@ -55,8 +55,15 @@ async function inputResolver (
5555 context : KeystoneContext
5656) {
5757 if ( data === null || data === undefined ) {
58- return { extension : data , filesize : data , height : data , id : data , width : data }
58+ return {
59+ id : data ,
60+ filesize : data ,
61+ width : data ,
62+ height : data ,
63+ extension : data ,
64+ }
5965 }
66+
6067 const upload = await data . upload
6168 return context . images ( storage ) . getDataFromStream ( upload . createReadStream ( ) , upload . filename )
6269}
@@ -88,9 +95,9 @@ export function image <ListTypeInfo extends BaseListTypeInfo>(config: ImageField
8895 fields : {
8996 id : { kind : 'scalar' , scalar : 'String' , mode : 'optional' } ,
9097 filesize : { kind : 'scalar' , scalar : 'Int' , mode : 'optional' } ,
91- extension : { kind : 'scalar' , scalar : 'String' , mode : 'optional' } ,
9298 width : { kind : 'scalar' , scalar : 'Int' , mode : 'optional' } ,
9399 height : { kind : 'scalar' , scalar : 'Int' , mode : 'optional' } ,
100+ extension : { kind : 'scalar' , scalar : 'String' , mode : 'optional' } ,
94101 } ,
95102 } ) ( {
96103 ...config ,
@@ -133,23 +140,28 @@ export function image <ListTypeInfo extends BaseListTypeInfo>(config: ImageField
133140 } ,
134141 output : graphql . field ( {
135142 type : ImageFieldOutput ,
136- resolve ( { value : { extension, filesize, height, id, width } } ) {
137- if (
138- extension === null ||
139- ! isValidImageExtension ( extension ) ||
140- filesize === null ||
141- height === null ||
142- width === null ||
143- id === null
144- ) {
145- return null
143+ resolve ( {
144+ value : {
145+ id,
146+ filesize,
147+ width,
148+ height,
149+ extension,
146150 }
151+ } ) {
152+ if ( id === null ) return null
153+ if ( filesize === null ) return null
154+ if ( width === null ) return null
155+ if ( height === null ) return null
156+ if ( extension === null ) return null
157+ if ( ! isValidImageExtension ( extension ) ) return null
158+
147159 return {
148- extension ,
160+ id ,
149161 filesize,
150- height,
151162 width,
152- id,
163+ height,
164+ extension,
153165 storage : config . storage ,
154166 }
155167 } ,
0 commit comments