[QRQC_2] No implicitAny in twenty-server (#12075)

# Introduction
Following https://github.com/twentyhq/twenty/pull/12068
Related with https://github.com/twentyhq/core-team-issues/issues/975

We're enabling `noImplicitAny` handled few use case manually, added a
`ts-expect-error` to the others, we should plan to handle them in the
future
This commit is contained in:
Paul Rastoin
2025-05-15 18:23:22 +02:00
committed by GitHub
parent 08ce2f831e
commit 442f8dbe3c
120 changed files with 331 additions and 50 deletions

View File

@ -300,11 +300,13 @@ export const objectMetadataMapItemMock = {
namePlural: 'objectsName',
fields,
fieldsById: fields.reduce((acc, field) => {
// @ts-expect-error legacy noImplicitAny
acc[field.id] = field;
return acc;
}, {}),
fieldsByName: fields.reduce((acc, field) => {
// @ts-expect-error legacy noImplicitAny
acc[field.name] = field;
return acc;

View File

@ -117,6 +117,7 @@ export abstract class GraphqlQueryBaseResolverService<
const computedArgs = (await this.queryRunnerArgsFactory.create(
hookedArgs,
options,
// @ts-expect-error legacy noImplicitAny
ResolverArgsType[capitalize(operationName)],
)) as Input;
@ -195,6 +196,7 @@ export abstract class GraphqlQueryBaseResolverService<
)
) {
const permissionRequired: SettingPermissionType =
// @ts-expect-error legacy noImplicitAny
SYSTEM_OBJECTS_PERMISSIONS_REQUIREMENTS[
objectMetadataItemWithFieldMaps.nameSingular
];

View File

@ -209,6 +209,7 @@ export class GraphqlQueryCreateManyResolverService extends GraphqlQueryBaseResol
.filter(Boolean);
if (fieldValues.length > 0) {
// @ts-expect-error legacy noImplicitAny
whereConditions[field.column] = In(fieldValues);
}
}

View File

@ -52,6 +52,7 @@ export class ApiEventEmitterService {
objectMetadataNameSingular: objectMetadataItem.nameSingular,
action: DatabaseEventAction.UPDATED,
events: records.map((record) => {
// @ts-expect-error legacy noImplicitAny
const before = mappedExistingRecords[record.id];
const after = record;
const diff = objectRecordChangedValues(

View File

@ -10,6 +10,7 @@ export class ScalarsExplorerService {
constructor() {
this.scalarImplementations = scalars.reduce((acc, scalar) => {
// @ts-expect-error legacy noImplicitAny
acc[scalar.name] = scalar;
return acc;

View File

@ -44,6 +44,7 @@ const findFieldNode = (
return field;
};
// @ts-expect-error legacy noImplicitAny
const parseValueNode = (
valueNode: ValueNode,
variables: GraphQLResolveInfo['variableValues'],
@ -62,6 +63,7 @@ const parseValueNode = (
return valueNode.values.map((value) => parseValueNode(value, variables));
case Kind.OBJECT:
return valueNode.fields.reduce((obj, field) => {
// @ts-expect-error legacy noImplicitAny
obj[field.name.value] = parseValueNode(field.value, variables);
return obj;

View File

@ -260,12 +260,15 @@ export class QueryRunnerArgsFactory {
const overrideFilter = (filterObject: ObjectRecordFilter) => {
return Object.entries(filterObject).reduce((acc, [key, value]) => {
if (key === 'and' || key === 'or') {
// @ts-expect-error legacy noImplicitAny
acc[key] = value.map((nestedFilter: ObjectRecordFilter) =>
overrideFilter(nestedFilter),
);
} else if (key === 'not') {
// @ts-expect-error legacy noImplicitAny
acc[key] = overrideFilter(value);
} else {
// @ts-expect-error legacy noImplicitAny
acc[key] = this.transformFilterValueByType(
key,
value,

View File

@ -5,6 +5,7 @@ import {
} from 'src/engine/api/graphql/workspace-query-runner/utils/parse-result.util';
describe('handleSpecialKey', () => {
// @ts-expect-error legacy noImplicitAny
let result;
beforeEach(() => {
@ -13,10 +14,12 @@ describe('handleSpecialKey', () => {
test('should correctly process a composite key and add it to the result object', () => {
handleCompositeKey(
// @ts-expect-error legacy noImplicitAny
result,
createCompositeFieldKey('complexField', 'link'),
'value1',
);
// @ts-expect-error legacy noImplicitAny
expect(result).toEqual({
complexField: {
link: 'value1',
@ -26,15 +29,18 @@ describe('handleSpecialKey', () => {
test('should add values under the same newKey if called multiple times', () => {
handleCompositeKey(
// @ts-expect-error legacy noImplicitAny
result,
createCompositeFieldKey('complexField', 'link'),
'value1',
);
handleCompositeKey(
// @ts-expect-error legacy noImplicitAny
result,
createCompositeFieldKey('complexField', 'text'),
'value2',
);
// @ts-expect-error legacy noImplicitAny
expect(result).toEqual({
complexField: {
link: 'value1',
@ -44,7 +50,9 @@ describe('handleSpecialKey', () => {
});
test('should not create a new field if the composite key is not correctly formed', () => {
// @ts-expect-error legacy noImplicitAny
handleCompositeKey(result, 'COMPOSITE___complexField', 'value1');
// @ts-expect-error legacy noImplicitAny
expect(result).toEqual({});
});
});

View File

@ -35,6 +35,7 @@ const pgGraphQLErrorMapping: PgGraphQLErrorMapping = {
'duplicate key value violates unique constraint': (command, objectName, _) =>
new WorkspaceQueryRunnerException(
`Cannot ${
// @ts-expect-error legacy noImplicitAny
pgGraphQLCommandMapping[command] ?? command
} ${objectName} because it violates a uniqueness constraint.`,
WorkspaceQueryRunnerExceptionCode.QUERY_VIOLATES_UNIQUE_CONSTRAINT,
@ -42,6 +43,7 @@ const pgGraphQLErrorMapping: PgGraphQLErrorMapping = {
'violates foreign key constraint': (command, objectName, _) =>
new WorkspaceQueryRunnerException(
`Cannot ${
// @ts-expect-error legacy noImplicitAny
pgGraphQLCommandMapping[command] ?? command
} ${objectName} because it violates a foreign key constraint.`,
WorkspaceQueryRunnerExceptionCode.QUERY_VIOLATES_FOREIGN_KEY_CONSTRAINT,

View File

@ -110,11 +110,13 @@ export class WorkspaceQueryHookExplorer implements OnModuleInit {
contextId,
);
// @ts-expect-error legacy noImplicitAny
return contextInstance[methodName].call(
contextInstance,
...executeParams,
);
} else {
// @ts-expect-error legacy noImplicitAny
return instance[methodName].call(instance, ...executeParams);
}
}
@ -173,6 +175,7 @@ export class WorkspaceQueryHookExplorer implements OnModuleInit {
contextId,
);
// @ts-expect-error legacy noImplicitAny
return contextInstance[methodName].call(
contextInstance,
executeParams[0],
@ -180,6 +183,7 @@ export class WorkspaceQueryHookExplorer implements OnModuleInit {
transformedPayload,
);
} else {
// @ts-expect-error legacy noImplicitAny
return instance[methodName].call(
instance,
executeParams[0],

View File

@ -97,6 +97,7 @@ export class WorkspaceResolverFactory {
methodName,
)
) {
// @ts-expect-error legacy noImplicitAny
resolvers.Query[resolverName] = resolverFactory.create({
authContext,
objectMetadataMaps,
@ -120,6 +121,7 @@ export class WorkspaceResolverFactory {
throw new Error(`Unknown mutation resolver type: ${methodName}`);
}
// @ts-expect-error legacy noImplicitAny
resolvers.Mutation[resolverName] = resolverFactory.create({
authContext,
objectMetadataMaps,

View File

@ -37,6 +37,7 @@ export class InputTypeDefinitionFactory {
kind: InputTypeDefinitionKind,
options: WorkspaceBuildSchemaOptions,
): InputTypeDefinition {
// @ts-expect-error legacy noImplicitAny
const inputType = new GraphQLInputObjectType({
name: `${pascalCase(objectMetadata.nameSingular)}${kind.toString()}Input`,
description: objectMetadata.description,
@ -46,6 +47,7 @@ export class InputTypeDefinitionFactory {
* Filter input type has additional fields for filtering and is self referencing
*/
case InputTypeDefinitionKind.Filter: {
// @ts-expect-error legacy noImplicitAny
const andOrType = this.typeMapperService.mapToGqlType(inputType, {
isArray: true,
arrayDepth: 1,

View File

@ -172,6 +172,7 @@ export class TypeDefinitionsGenerator {
) {
const objectTypeDefs = objectMetadataCollection.map((objectMetadata) =>
this.objectTypeDefinitionFactory.create(
// @ts-expect-error legacy noImplicitAny
objectMetadata,
ObjectTypeDefinitionKind.Plain,
options,

View File

@ -104,12 +104,14 @@ export const generateFields = <
throw new Error('Join column name is not defined');
}
// @ts-expect-error legacy noImplicitAny
fields[joinColumnName] = {
type,
description: fieldMetadata.description,
};
}
// @ts-expect-error legacy noImplicitAny
fields[fieldMetadata.name] = {
type,
description: fieldMetadata.description,

View File

@ -42,8 +42,10 @@ export const parseFilter = (
`'filter' invalid. 'not' conjunction should contain only 1 condition. eg: not(field[eq]:1)`,
);
}
// @ts-expect-error legacy noImplicitAny
result[conjunction] = subResult[0];
} else {
// @ts-expect-error legacy noImplicitAny
result[conjunction] = subResult;
}

View File

@ -69,11 +69,13 @@ export class OrderByInputFactory {
if (Object.keys(fieldResult).length) {
fieldResult = { [field]: fieldResult };
} else {
// @ts-expect-error legacy noImplicitAny
fieldResult[field] = itemDirection;
}
}, itemDirection);
const resultFields = Object.keys(fieldResult).map((key) => ({
// @ts-expect-error legacy noImplicitAny
[key]: fieldResult[key],
}));

View File

@ -6,6 +6,7 @@ import { fetchMetadataFields } from 'src/engine/api/rest/metadata/query-builder/
@Injectable()
export class FindManyMetadataQueryFactory {
// @ts-expect-error legacy noImplicitAny
create(objectNamePlural): string {
const fields = fetchMetadataFields(objectNamePlural);

View File

@ -16,15 +16,18 @@ export const cleanGraphQLResponse = (input: any) => {
if (isObject(obj[key])) {
if (obj[key].edges) {
// Handle edges by mapping over them and applying cleanObject to each node
// @ts-expect-error legacy noImplicitAny
cleanedObj[key] = obj[key].edges.map((edge) =>
cleanObject(edge.node),
);
} else {
// Recursively clean nested objects
// @ts-expect-error legacy noImplicitAny
cleanedObj[key] = cleanObject(obj[key]);
}
} else {
// Directly assign non-object properties
// @ts-expect-error legacy noImplicitAny
cleanedObj[key] = obj[key];
}
});
@ -35,22 +38,29 @@ export const cleanGraphQLResponse = (input: any) => {
Object.keys(input).forEach((key) => {
if (isObject(input[key]) && input[key].edges) {
// Handle collections with edges, ensuring data is placed under the data key
// @ts-expect-error legacy noImplicitAny
output.data[key] = input[key].edges.map((edge) => cleanObject(edge.node));
// Move pageInfo and totalCount to the top level
if (input[key].pageInfo) {
// @ts-expect-error legacy noImplicitAny
output['pageInfo'] = input[key].pageInfo;
}
if (input[key].totalCount) {
// @ts-expect-error legacy noImplicitAny
output['totalCount'] = input[key].totalCount;
}
} else if (isObject(input[key])) {
// Recursively clean and assign nested objects under the data key
// @ts-expect-error legacy noImplicitAny
output.data[key] = cleanObject(input[key]);
} else if (Array.isArray(input[key])) {
// @ts-expect-error legacy noImplicitAny
const itemsWithEdges = input[key].filter((item) => item.edges);
// @ts-expect-error legacy noImplicitAny
const cleanedObjArray = itemsWithEdges.map(({ edges, ...item }) => {
return {
...item,
// @ts-expect-error legacy noImplicitAny
[key]: edges.map((edge) => cleanObject(edge.node)),
};
});
@ -58,6 +68,7 @@ export const cleanGraphQLResponse = (input: any) => {
output.data = cleanedObjArray;
} else {
// Assign all other properties directly under the data key
// @ts-expect-error legacy noImplicitAny
output.data[key] = input[key];
}
});

View File

@ -47,11 +47,14 @@ export const buildDuplicateConditions = (
compositeFieldMetadataMap.get(columnName);
if (compositeFieldMetadata) {
// @ts-expect-error legacy noImplicitAny
condition[compositeFieldMetadata.parentField] = {
// @ts-expect-error legacy noImplicitAny
...condition[compositeFieldMetadata.parentField],
[compositeFieldMetadata.name]: { eq: record[columnName] },
};
} else {
// @ts-expect-error legacy noImplicitAny
condition[columnName] = { eq: record[columnName] };
}
});