keystonejs / keystone

The superpowered headless CMS for Node.js — built with GraphQL and React
https://keystonejs.com
MIT License
9.18k stars 1.15k forks source link

WhereInput filter for multiselect field #9036

Open remihuigen opened 7 months ago

remihuigen commented 7 months ago

First off: Not sure if this is a bug or a feature request

When using a multiselect field, this field cant be used as part of a WHERE filter.

// Example usage
export default list({
  // list config
  fields: {
     stage: multiselect({
      label: "Relevant in fase",
      db: { map: 'stage' },
      type: 'string',
      options: stageOptions,
      defaultValue: ['orientatie'],
      ui: {
        itemView: {
          fieldPosition: 'sidebar'
        },
        listView: {
          fieldMode: () => 'read',
        },
      },
      hooks: {
        validateInput: ({operation, resolvedData, inputData, fieldKey, addValidationError}) => {
          if (operation === 'create' && !resolvedData[fieldKey]?.length) addValidationError('Een item moet ten minste één relevante fase hebben')
          else if (operation === 'update' && inputData[fieldKey] && !inputData[fieldKey].length) addValidationError('Een item moet ten minste één relevante fase hebben')
        }
      }
    })
  }
})

I expected to be able to write queries with filters for this field. Such as

query {
  pages(where: { stage: { some: { equals: "orientatie" }}}) {
    id
  }
}

But this gives an error Field "stage" is not defined by type "PageWhereInput".

I case this is not a bug: is such a feature going to be implemented any time soon? Because otherwise I'll need to look for another solution...

gautamsi commented 7 months ago

you can implement your own multi select field without using JSON, that way it is text field for storage and select field for display