Files
klz-cables.com/.pnpm-store/v10/files/b2/e3106fa91b66635afd9fb7019aa535ebc1acf9e916c32a68a97b0b9eb571f8ea09f92f3756f04fade5e8cd4e45082de9ce55935e161d42bc2d6ec38fd47a18
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

86 lines
3.3 KiB
Plaintext

import { GraphQLInputObjectType, GraphQLList } from 'graphql';
import { flattenTopLevelFields } from 'payload';
import { fieldAffectsData, fieldHasSubFields, fieldIsPresentationalOnly } from 'payload/shared';
import { formatName } from '../utilities/formatName.js';
import { fieldToSchemaMap } from './fieldToWhereInputSchemaMap.js';
import { withOperators } from './withOperators.js';
/** This does as the function name suggests. It builds a where GraphQL input type
* for all the fields which are passed to the function.
* Each field has different operators which may be valid for a where input type.
* For example, a text field may have a "contains" operator, but a number field
* may not.
*
* buildWhereInputType is similar to buildObjectType and operates
* on a field basis with a few distinct differences.
*
* 1. Everything needs to be a GraphQLInputObjectType or scalar / enum
* 2. Relationships, groups, repeaters and flex content are not
* directly searchable. Instead, we need to build a chained pathname
* using dot notation so MongoDB can properly search nested paths.
*/ export const buildWhereInputType = ({ name, fields, parentName })=>{
// This is the function that builds nested paths for all
// field types with nested paths.
const idField = flattenTopLevelFields(fields).find((field)=>fieldAffectsData(field) && field.name === 'id');
const fieldTypes = fields.reduce((schema, field)=>{
if (!fieldIsPresentationalOnly(field) && !field.hidden) {
const getFieldSchema = fieldToSchemaMap({
parentName
})[field.type];
if (getFieldSchema) {
const fieldSchema = getFieldSchema(field);
if (fieldHasSubFields(field) || field.type === 'tabs') {
return {
...schema,
...fieldSchema.reduce((subFields, subField)=>({
...subFields,
[formatName(subField.key)]: subField.type
}), {})
};
}
return {
...schema,
[formatName(field.name)]: fieldSchema
};
}
}
return schema;
}, {});
if (!idField) {
fieldTypes.id = {
type: withOperators({
name: 'id',
type: 'text'
}, parentName)
};
}
const fieldName = formatName(name);
const recursiveFields = {
AND: {
type: new GraphQLList(new GraphQLInputObjectType({
name: `${fieldName}_where_and`,
fields: ()=>({
...fieldTypes,
...recursiveFields
})
}))
},
OR: {
type: new GraphQLList(new GraphQLInputObjectType({
name: `${fieldName}_where_or`,
fields: ()=>({
...fieldTypes,
...recursiveFields
})
}))
}
};
return new GraphQLInputObjectType({
name: `${fieldName}_where`,
fields: {
...fieldTypes,
...recursiveFields
}
});
};
//# sourceMappingURL=buildWhereInputType.js.map