Files
klz-cables.com/.pnpm-store/v10/files/03/e858b0127d2add898432ce42875a058d65a13d242c79ae3620c61f844693fef86214a25ef1480813dc244a93e88f46da34230a33264c3e4131bb776c902af8
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

48 lines
1.3 KiB
Plaintext

import { GraphQLError } from '../../error/GraphQLError.mjs';
/**
* Unique type names
*
* A GraphQL document is only valid if all defined types have unique names.
*/
export function UniqueTypeNamesRule(context) {
const knownTypeNames = Object.create(null);
const schema = context.getSchema();
return {
ScalarTypeDefinition: checkTypeName,
ObjectTypeDefinition: checkTypeName,
InterfaceTypeDefinition: checkTypeName,
UnionTypeDefinition: checkTypeName,
EnumTypeDefinition: checkTypeName,
InputObjectTypeDefinition: checkTypeName,
};
function checkTypeName(node) {
const typeName = node.name.value;
if (schema !== null && schema !== void 0 && schema.getType(typeName)) {
context.reportError(
new GraphQLError(
`Type "${typeName}" already exists in the schema. It cannot also be defined in this type definition.`,
{
nodes: node.name,
},
),
);
return;
}
if (knownTypeNames[typeName]) {
context.reportError(
new GraphQLError(`There can be only one type named "${typeName}".`, {
nodes: [knownTypeNames[typeName], node.name],
}),
);
} else {
knownTypeNames[typeName] = node.name;
}
return false;
}
}