From 4048991ba7db234a694287000beaf2ea052cd24e Mon Sep 17 00:00:00 2001 From: Mitchell Hamilton Date: Thu, 9 Sep 2021 15:33:56 +1000 Subject: [PATCH] Remove isRequired and defaultValue from some fields (#6513) --- .changeset/forty-jobs-grow.md | 5 +++++ .changeset/real-jars-buy.md | 5 +++++ docs/pages/docs/apis/fields.mdx | 18 ++---------------- packages/cloudinary/src/index.ts | 6 ------ packages/cloudinary/src/test-fixtures.skip.ts | 1 + .../keystone/src/fields/types/file/index.ts | 18 ++++-------------- .../fields/types/file/tests/test-fixtures.ts | 1 + .../keystone/src/fields/types/image/index.ts | 18 ++++-------------- .../fields/types/image/tests/test-fixtures.ts | 1 + 9 files changed, 23 insertions(+), 50 deletions(-) create mode 100644 .changeset/forty-jobs-grow.md create mode 100644 .changeset/real-jars-buy.md diff --git a/.changeset/forty-jobs-grow.md b/.changeset/forty-jobs-grow.md new file mode 100644 index 00000000000..805deffff7b --- /dev/null +++ b/.changeset/forty-jobs-grow.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/cloudinary': major +--- + +Removed `isRequired` and `defaultValue` from the `cloudinaryImage` field. If you were using these options, the same behaviour can be re-created with the `validateInput` and `resolveInput` hooks respectively. diff --git a/.changeset/real-jars-buy.md b/.changeset/real-jars-buy.md new file mode 100644 index 00000000000..588974c8516 --- /dev/null +++ b/.changeset/real-jars-buy.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/keystone': major +--- + +Removed `isRequired` and `defaultValue` from the `image` and `file` fields. If you were using these options, the same behaviour can be re-created with the `validateInput` and `resolveInput` hooks respectively. diff --git a/docs/pages/docs/apis/fields.mdx b/docs/pages/docs/apis/fields.mdx index b8dff67d9a4..4ffbb2f6632 100644 --- a/docs/pages/docs/apis/fields.mdx +++ b/docs/pages/docs/apis/fields.mdx @@ -621,10 +621,6 @@ A `file` field represents a file of any type. See [`config.files`](./config#files) for details on how to configure your Keystone system with support for the `file` field type. -Options: - -- `isRequired` (default: `false`): If `true` then this field can never be set to `null`. - ```typescript import { config, createSchema, list } from '@keystone-next/keystone'; import { file } from '@keystone-next/keystone/fields'; @@ -633,9 +629,7 @@ export default config({ lists: createSchema({ ListName: list({ fields: { - repo: file({ - isRequired: true, - }), + repo: file(), /* ... */ }, }), @@ -651,10 +645,6 @@ An `image` field represents an image file, i.e. `.jpg`, `.png`, `.webp`, or `.gi See [`config.images`](./config#images) for details on how to configure your Keystone system with support for the `image` field type. -Options: - -- `isRequired` (default: `false`): If `true` then this field can never be set to `null`. - ```typescript import { config, createSchema, list } from '@keystone-next/keystone'; import { image } from '@keystone-next/keystone/fields'; @@ -663,9 +653,7 @@ export default config({ lists: createSchema({ ListName: list({ fields: { - avatar: image({ - isRequired: true, - }), + avatar: image(), /* ... */ }, }), @@ -722,7 +710,6 @@ export default config({ (coming soon) -- `isRequired` (default: `false`): If `true` then this field can never be set to `null`. - `cloudinary`: Configuration for the connected Cloudinary account. - `cloudName` - `apiKey` @@ -738,7 +725,6 @@ export default config({ ListName: list({ fields: { fieldName: cloudinaryImage({ - isRequired: true, cloudinary: { cloudName: process.env.CLOUDINARY_CLOUD_NAME, apiKey: process.env.CLOUDINARY_API_KEY, diff --git a/packages/cloudinary/src/index.ts b/packages/cloudinary/src/index.ts index cd29d08786e..38db4e66cf2 100644 --- a/packages/cloudinary/src/index.ts +++ b/packages/cloudinary/src/index.ts @@ -5,7 +5,6 @@ import { FieldTypeFunc, jsonFieldTypePolyfilledForSQLite, graphql, - FieldDefaultValue, } from '@keystone-next/keystone/types'; import { FileUpload } from 'graphql-upload'; import cuid from 'cuid'; @@ -23,8 +22,6 @@ type StoredFile = { type CloudinaryImageFieldConfig = CommonFieldConfig & { - isRequired?: boolean; - defaultValue?: FieldDefaultValue; cloudinary: { cloudName: string; apiKey: string; @@ -111,8 +108,6 @@ const outputType = graphql.object()({ export const cloudinaryImage = ({ cloudinary, - isRequired, - defaultValue, ...config }: CloudinaryImageFieldConfig): FieldTypeFunc => meta => { @@ -170,6 +165,5 @@ export const cloudinaryImage = }, }), views: path.join(path.dirname(__dirname), 'views'), - __legacy: { isRequired, defaultValue }, }); }; diff --git a/packages/cloudinary/src/test-fixtures.skip.ts b/packages/cloudinary/src/test-fixtures.skip.ts index a7aac8c2dbe..8d7477accbf 100644 --- a/packages/cloudinary/src/test-fixtures.skip.ts +++ b/packages/cloudinary/src/test-fixtures.skip.ts @@ -30,6 +30,7 @@ const prepareFile = (_filePath: string) => { export const name = 'CloudinaryImage'; export const typeFunction = cloudinaryImage; export const supportsUnique = false; +export const skipRequiredTest = true; export const fieldName = 'image'; export const subfieldName = 'originalFilename'; diff --git a/packages/keystone/src/fields/types/file/index.ts b/packages/keystone/src/fields/types/file/index.ts index 734b51818d3..7288cce8db4 100644 --- a/packages/keystone/src/fields/types/file/index.ts +++ b/packages/keystone/src/fields/types/file/index.ts @@ -7,16 +7,12 @@ import { BaseGeneratedListTypes, KeystoneContext, FileData, - FieldDefaultValue, } from '../../../types'; import { resolveView } from '../../resolve-view'; import { getFileRef } from './utils'; export type FileFieldConfig = - CommonFieldConfig & { - isRequired?: boolean; - defaultValue?: FieldDefaultValue; - }; + CommonFieldConfig; const FileFieldInput = graphql.inputObject({ name: 'FileFieldInput', @@ -84,11 +80,9 @@ async function inputResolver(data: FileFieldInputType, context: KeystoneContext) } export const file = - ({ - isRequired, - defaultValue, - ...config - }: FileFieldConfig = {}): FieldTypeFunc => + ( + config: FileFieldConfig = {} + ): FieldTypeFunc => () => { if ((config as any).isIndexed === 'unique') { throw Error("isIndexed: 'unique' is not a supported option for field type file"); @@ -123,9 +117,5 @@ export const file = }), unreferencedConcreteInterfaceImplementations: [LocalFileFieldOutput], views: resolveView('file/views'), - __legacy: { - isRequired, - defaultValue, - }, }); }; diff --git a/packages/keystone/src/fields/types/file/tests/test-fixtures.ts b/packages/keystone/src/fields/types/file/tests/test-fixtures.ts index 4a6b898d317..5e8d11f22c5 100644 --- a/packages/keystone/src/fields/types/file/tests/test-fixtures.ts +++ b/packages/keystone/src/fields/types/file/tests/test-fixtures.ts @@ -26,6 +26,7 @@ export const createReturnedValue = 3250; export const updateReturnedValue = 5562; export const supportsUnique = false; +export const skipRequiredTest = true; export const fieldName = 'secretFile'; export const subfieldName = 'filesize'; diff --git a/packages/keystone/src/fields/types/image/index.ts b/packages/keystone/src/fields/types/image/index.ts index fe601665885..f2ecd8559cc 100644 --- a/packages/keystone/src/fields/types/image/index.ts +++ b/packages/keystone/src/fields/types/image/index.ts @@ -1,7 +1,6 @@ import { FileUpload } from 'graphql-upload'; import { BaseGeneratedListTypes, - FieldDefaultValue, fieldType, FieldTypeFunc, CommonFieldConfig, @@ -14,10 +13,7 @@ import { resolveView } from '../../resolve-view'; import { getImageRef, SUPPORTED_IMAGE_EXTENSIONS } from './utils'; export type ImageFieldConfig = - CommonFieldConfig & { - defaultValue?: FieldDefaultValue; - isRequired?: boolean; - }; + CommonFieldConfig; const ImageExtensionEnum = graphql.enum({ name: 'ImageExtension', @@ -96,11 +92,9 @@ function isValidImageExtension(extension: string): extension is ImageExtension { } export const image = - ({ - isRequired, - defaultValue, - ...config - }: ImageFieldConfig = {}): FieldTypeFunc => + ( + config: ImageFieldConfig = {} + ): FieldTypeFunc => () => { if ((config as any).isIndexed === 'unique') { throw Error("isIndexed: 'unique' is not a supported option for field type image"); @@ -142,9 +136,5 @@ export const image = }), unreferencedConcreteInterfaceImplementations: [LocalImageFieldOutput], views: resolveView('image/views'), - __legacy: { - isRequired, - defaultValue, - }, }); }; diff --git a/packages/keystone/src/fields/types/image/tests/test-fixtures.ts b/packages/keystone/src/fields/types/image/tests/test-fixtures.ts index 04d89b592dc..dac21afee35 100644 --- a/packages/keystone/src/fields/types/image/tests/test-fixtures.ts +++ b/packages/keystone/src/fields/types/image/tests/test-fixtures.ts @@ -27,6 +27,7 @@ export const createReturnedValue = 'jpg'; export const updateReturnedValue = createReturnedValue; export const supportsUnique = false; +export const skipRequiredTest = true; export const fieldName = 'avatar'; export const subfieldName = 'extension';