From f880614ad8b69d0f6cd2be4192acea571e14bc4d Mon Sep 17 00:00:00 2001 From: Gustav Hansen Date: Tue, 12 Jul 2022 17:38:15 +0200 Subject: [PATCH] chore: Add comments on why the GraphQL regex is needed in core right now --- .../src/components/FormModal/attributes/types.js | 13 ++++++++++++- .../lib/core/domain/content-type/validator.js | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/core/content-type-builder/admin/src/components/FormModal/attributes/types.js b/packages/core/content-type-builder/admin/src/components/FormModal/attributes/types.js index 60671da9cc..2a75b72634 100644 --- a/packages/core/content-type-builder/admin/src/components/FormModal/attributes/types.js +++ b/packages/core/content-type-builder/admin/src/components/FormModal/attributes/types.js @@ -131,7 +131,18 @@ const types = { return yup.object(shape); }, enumeration: (usedAttributeNames, reservedNames) => { - // See GraphQL Spec https://spec.graphql.org/June2018/#sec-Names + /** + * For enumerations the least common denomiator is GraphQL, where + * values needs to match the secure name regex: + * GraphQL Spec https://spec.graphql.org/June2018/#sec-Names + * + * Therefore we need to make sure our users only use values, which + * can be returned by GraphQL, by checking the regressed values + * agains the GraphQL regex. + * + * TODO V5: check if we can avoid this coupling by moving this logic + * into the GraphQL plugin. + */ const GRAPHQL_ENUM_REGEX = new RegExp('^[_A-Za-z][_0-9A-Za-z]*$'); const shape = { diff --git a/packages/core/strapi/lib/core/domain/content-type/validator.js b/packages/core/strapi/lib/core/domain/content-type/validator.js index 9fe2babb0a..f2b2d42b84 100644 --- a/packages/core/strapi/lib/core/domain/content-type/validator.js +++ b/packages/core/strapi/lib/core/domain/content-type/validator.js @@ -24,7 +24,18 @@ const LIFECYCLES = [ 'afterDeleteMany', ]; -// See GraphQL Spec https://spec.graphql.org/June2018/#sec-Names +/** + * For enumerations the least common denomiator is GraphQL, where + * values needs to match the secure name regex: + * GraphQL Spec https://spec.graphql.org/June2018/#sec-Names + * + * Therefore we need to make sure our users only use values, which + * can be returned by GraphQL, by checking the regressed values + * agains the GraphQL regex. + * + * TODO V5: check if we can avoid this coupling by moving this logic + * into the GraphQL plugin. + */ const GRAPHQL_ENUM_REGEX = new RegExp('^[_A-Za-z][_0-9A-Za-z]*$'); const lifecyclesShape = _.mapValues(_.keyBy(LIFECYCLES), () =>