keystone icon indicating copy to clipboard operation
keystone copied to clipboard

Field hooks beforeOperation and afterOperation not running with default value

Open stentibbing opened this issue 1 year ago • 0 comments

To reproduce:

  1. Create new Keystone app with the following config:
import { config, list } from "@keystone-6/core";
import { allowAll } from "@keystone-6/core/access";
import { text, integer } from "@keystone-6/core/fields";
import { session } from "./auth";

export default config({
  db: {
    provider: "sqlite",
    url: "file:./keystone.db",
  },
  lists: {
    Material: list({
      access: allowAll,
      fields: {
        name: text({ validation: { isRequired: true }, isIndexed: "unique" }),
        order: integer({
          validation: {
            isRequired: false,
            min: 1,
          },
          defaultValue: 1,
          hooks: {
            resolveInput: async () => console.log("resolveInput"),
            beforeOperation: async () => console.log("beforeOperation"),
          },
        }),
      },
    }),
  },
  session,
  ui: {
    isAccessAllowed: () => true,
  },
});
  1. Create new entity, without changing the default value
  2. Observe the stdout having only "resolveInput" being logged

Note: If the value of order field is different from default value, the hooks are firing as expected

Expectation:

Fields with default values should not behave any different from fields with default values.

Using: node 20.18.0 keystone-6/core 6.3.0

stentibbing avatar Oct 29 '24 16:10 stentibbing