3d1c53ec9d
#### Direct Execution __typename & null backfill ##### __typename filling The direct execution path now correctly derives __typename at every level of the GraphQL response: Connection types — CompanyConnection, CompanyEdge, Company, PageInfo GroupBy types — TaskGroupByConnection (was incorrectly producing TaskConnection) Composite fields — Links, FullName, Currency, etc. handled by a dedicated formatter (was inheriting the parent object's typename) Previously, __typename was derived from the object's universal identifier (a UUID), producing broken values like 20202020B3744779A56180086Cb2E17FConnection. ##### Null backfill Selected fields missing from the resolver result are backfilled with null, matching the standard Yoga schema behavior. ##### Integration test A new test runs the same findMany query (with __typename at all structural levels) through both paths — standard Yoga schema and direct execution — and asserts identical output via toStrictEqual.
131 lines
4.0 KiB
TypeScript
131 lines
4.0 KiB
TypeScript
import {
|
|
isArray,
|
|
isBoolean,
|
|
isNumber,
|
|
isObject,
|
|
isString,
|
|
} from 'class-validator';
|
|
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { STANDARD_ERROR_MESSAGE } from 'src/engine/api/common/common-query-runners/errors/standard-error-message.constant';
|
|
import {
|
|
GraphqlDirectExecutionException,
|
|
GraphqlDirectExecutionExceptionCode,
|
|
} from 'src/engine/api/graphql/direct-execution/errors/graphql-direct-execution.exception';
|
|
import { type GroupByResolverArgs } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
|
|
|
|
export function assertGroupByArgs(
|
|
args: unknown,
|
|
): asserts args is GroupByResolverArgs {
|
|
if (!isObject(args)) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Invalid argument: it must be an object',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
|
|
const argKeys = Object.keys(args);
|
|
|
|
const allowedKeys = new Set([
|
|
'filter',
|
|
'orderBy',
|
|
'orderByForRecords',
|
|
'groupBy',
|
|
'viewId',
|
|
'includeRecords',
|
|
'limit',
|
|
'offsetForRecords',
|
|
]);
|
|
|
|
for (const key of argKeys) {
|
|
if (!allowedKeys.has(key)) {
|
|
throw new GraphqlDirectExecutionException(
|
|
`Argument not allowed: ${key}`,
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
}
|
|
|
|
if (
|
|
!('groupBy' in args) ||
|
|
(!Array.isArray(args.groupBy) && !isObject(args.groupBy))
|
|
) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Missing required argument: "groupBy" must be an array.',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
|
|
if ('filter' in args && isDefined(args.filter) && !isObject(args.filter)) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Invalid argument: "filter" must be an object',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
|
|
if ('orderBy' in args && isDefined(args.orderBy) && !isArray(args.orderBy)) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Invalid argument: "orderBy" must be an array',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
|
|
if (
|
|
'orderByForRecords' in args &&
|
|
isDefined(args.orderByForRecords) &&
|
|
!isArray(args.orderByForRecords)
|
|
) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Invalid argument: "orderByForRecords" must be an array',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
|
|
if ('viewId' in args && isDefined(args.viewId) && !isString(args.viewId)) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Invalid argument: "viewId" must be a string',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
|
|
if (
|
|
'includeRecords' in args &&
|
|
isDefined(args.includeRecords) &&
|
|
!isBoolean(args.includeRecords)
|
|
) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Invalid argument: "includeRecords" must be a boolean',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
|
|
if ('limit' in args && isDefined(args.limit) && !isNumber(args.limit)) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Invalid argument: "limit" must be a number',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
|
|
if (
|
|
'offsetForRecords' in args &&
|
|
isDefined(args.offsetForRecords) &&
|
|
!isNumber(args.offsetForRecords)
|
|
) {
|
|
throw new GraphqlDirectExecutionException(
|
|
'Invalid argument: "offsetForRecords" must be a number',
|
|
GraphqlDirectExecutionExceptionCode.INVALID_QUERY_INPUT,
|
|
{ userFriendlyMessage: STANDARD_ERROR_MESSAGE },
|
|
);
|
|
}
|
|
}
|