[flexible-schema] Add reserved keyword check on object creation (#5303)
## Context Because creating an object in metadata also generates a graphql type and because graphql does not allow 2 types with the same name, we have to manage a list of reserved keywords that can't be used as object names. Currently we were maintaining a list of the core objects but we also have to introduce composite fields that are also generated as gql types.
This commit is contained in:
@ -12,12 +12,24 @@ import {
|
|||||||
import { CreateObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/create-object.input';
|
import { CreateObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/create-object.input';
|
||||||
|
|
||||||
const coreObjectNames = [
|
const coreObjectNames = [
|
||||||
'featureFlag',
|
|
||||||
'appToken',
|
'appToken',
|
||||||
'workspace',
|
'billingSubscription',
|
||||||
|
'billingSubscriptionItem',
|
||||||
|
'featureFlag',
|
||||||
'user',
|
'user',
|
||||||
|
'userWorkspace',
|
||||||
|
'workspace',
|
||||||
|
];
|
||||||
|
|
||||||
|
const reservedKeywords = [
|
||||||
|
...coreObjectNames,
|
||||||
'event',
|
'event',
|
||||||
'field',
|
'field',
|
||||||
|
'link',
|
||||||
|
'currency',
|
||||||
|
'fullName',
|
||||||
|
'address',
|
||||||
|
'links',
|
||||||
];
|
];
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -35,8 +47,8 @@ export class BeforeCreateOneObject<T extends CreateObjectInput>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
coreObjectNames.includes(instance.input.nameSingular) ||
|
reservedKeywords.includes(instance.input.nameSingular) ||
|
||||||
coreObjectNames.includes(instance.input.namePlural)
|
reservedKeywords.includes(instance.input.namePlural)
|
||||||
) {
|
) {
|
||||||
throw new ForbiddenException(
|
throw new ForbiddenException(
|
||||||
'You cannot create an object with this name.',
|
'You cannot create an object with this name.',
|
||||||
|
|||||||
Reference in New Issue
Block a user