d562a384c2
Bug fixes exposed by always-on direct execution
1. GraphQL spec compliance — data[field] = null on resolver error
direct-execution.service.ts — Changed from Promise.allSettled (which
lost the responseKey on rejection) to Promise.all with per-field
try/catch; errors now set data[responseKey] = null per spec
2. Empty object arguments skipped (extractArgumentsFromAst)
extract-arguments-from-ast.util.ts — Removed isEmptyObject check;
filter: {}, data: {} now correctly passed to resolvers instead of
silently dropped (which caused permissions to never be checked)
3. orderBy: {} factory default treated as "no ordering"
direct-execution.service.ts — Before calling the resolver, strips
orderBy: {} and orderByForRecords: {} (empty-object factory defaults
that mean "no ordering")
assert-find-many-args.util.ts / assert-group-by-args.util.ts — Accept {}
for orderBy without throwing
4. orderBy: { field: '...' } object auto-coerced to [{ field: '...' }]
array
direct-execution.service.ts — Applies GraphQL list coercion: a
non-array, non-empty orderBy object is wrapped in an array before
assertion and resolver call
5. totalCount and aggregate fields returned as strings from PostgreSQL
graphql-format-result-from-selected-fields.util.ts — Added
coerceAggregateValue that parses numeric strings to numbers for
totalCount, sum*, avg*, min*, max*, count*, percentageOf* fields
Test updates
nested-relation-queries.integration-spec.ts — Updated expected error
message from Yoga schema-validation message to direct execution resolver
message
~30 snapshot files — Updated to reflect direct execution's error
messages (different from Yoga schema-validation messages for input type
errors)
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
|
|
import { makeExecutableSchema } from '@graphql-tools/schema';
|
|
import { GraphQLSchema } from 'graphql';
|
|
import { gql } from 'graphql-tag';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { ScalarsExplorerService } from 'src/engine/api/graphql/services/scalars-explorer.service';
|
|
import { WorkspaceGraphqlSchemaSDLService } from 'src/engine/api/graphql/workspace-graphql-schema-sdl/workspace-graphql-schema-sdl.service';
|
|
import { workspaceResolverBuilderMethodNames } from 'src/engine/api/graphql/workspace-resolver-builder/factories/factories';
|
|
import { WorkspaceResolverFactory } from 'src/engine/api/graphql/workspace-resolver-builder/workspace-resolver.factory';
|
|
import { FlatWorkspace } from 'src/engine/core-modules/workspace/types/flat-workspace.type';
|
|
import { buildObjectIdByNameMaps } from 'src/engine/metadata-modules/flat-object-metadata/utils/build-object-id-by-name-maps.util';
|
|
|
|
@Injectable()
|
|
export class WorkspaceSchemaFactory {
|
|
constructor(
|
|
private readonly scalarsExplorerService: ScalarsExplorerService,
|
|
private readonly workspaceResolverFactory: WorkspaceResolverFactory,
|
|
private readonly workspaceGraphqlSchemaSDLService: WorkspaceGraphqlSchemaSDLService,
|
|
) {}
|
|
|
|
async createGraphQLSchema(
|
|
workspace: FlatWorkspace,
|
|
applicationId?: string,
|
|
): Promise<GraphQLSchema> {
|
|
const schemaSDLResult =
|
|
await this.workspaceGraphqlSchemaSDLService.getOrComputeSchemaSDL(
|
|
workspace,
|
|
applicationId,
|
|
);
|
|
|
|
if (!isDefined(schemaSDLResult)) {
|
|
return new GraphQLSchema({});
|
|
}
|
|
|
|
const {
|
|
sdl,
|
|
usedScalarNames,
|
|
flatObjectMetadataMaps,
|
|
flatFieldMetadataMaps,
|
|
} = schemaSDLResult;
|
|
|
|
const { idByNameSingular } = buildObjectIdByNameMaps(
|
|
flatObjectMetadataMaps,
|
|
);
|
|
|
|
const autoGeneratedResolvers = await this.workspaceResolverFactory.create(
|
|
flatObjectMetadataMaps,
|
|
flatFieldMetadataMaps,
|
|
idByNameSingular,
|
|
workspaceResolverBuilderMethodNames,
|
|
);
|
|
const scalarsResolvers =
|
|
this.scalarsExplorerService.getScalarResolvers(usedScalarNames);
|
|
|
|
const executableSchema = makeExecutableSchema({
|
|
typeDefs: gql`
|
|
${sdl}
|
|
`,
|
|
resolvers: {
|
|
...scalarsResolvers,
|
|
...autoGeneratedResolvers,
|
|
},
|
|
});
|
|
|
|
return executableSchema;
|
|
}
|
|
}
|