mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 00:56:26 +08:00
refactor(server): config system (#11081)
This commit is contained in:
@@ -1,17 +1,27 @@
|
||||
import { ApolloDriverConfig } from '@nestjs/apollo';
|
||||
|
||||
import { defineStartupConfig, ModuleConfig } from '../../base/config';
|
||||
import { defineModuleConfig } from '../config';
|
||||
|
||||
declare module '../../base/config' {
|
||||
interface AppConfig {
|
||||
graphql: ModuleConfig<ApolloDriverConfig>;
|
||||
declare global {
|
||||
interface AppConfigSchema {
|
||||
graphql: {
|
||||
apolloDriverConfig: ConfigItem<ApolloDriverConfig>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
defineStartupConfig('graphql', {
|
||||
buildSchemaOptions: {
|
||||
numberScalarMode: 'integer',
|
||||
defineModuleConfig('graphql', {
|
||||
apolloDriverConfig: {
|
||||
desc: 'The config for underlying nestjs GraphQL and apollo driver engine.',
|
||||
default: {
|
||||
buildSchemaOptions: {
|
||||
numberScalarMode: 'integer',
|
||||
},
|
||||
useGlobalPrefix: true,
|
||||
playground: true,
|
||||
introspection: true,
|
||||
sortSchema: true,
|
||||
},
|
||||
link: 'https://docs.nestjs.com/graphql/quick-start',
|
||||
},
|
||||
introspection: true,
|
||||
playground: true,
|
||||
});
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import './config';
|
||||
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import type { ApolloDriverConfig } from '@nestjs/apollo';
|
||||
import { ApolloDriver } from '@nestjs/apollo';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { GraphQLModule } from '@nestjs/graphql';
|
||||
import { Request, Response } from 'express';
|
||||
import type { Request, Response } from 'express';
|
||||
|
||||
import { Config } from '../config';
|
||||
import { mapAnyError } from '../nestjs/exception';
|
||||
@@ -26,18 +25,17 @@ export type GraphqlContext = {
|
||||
driver: ApolloDriver,
|
||||
useFactory: (config: Config) => {
|
||||
return {
|
||||
...config.graphql,
|
||||
path: `${config.server.path}/graphql`,
|
||||
...config.graphql.apolloDriverConfig,
|
||||
autoSchemaFile: join(
|
||||
env.projectRoot,
|
||||
env.testing
|
||||
? './node_modules/.cache/schema.gql'
|
||||
: './src/schema.gql'
|
||||
),
|
||||
path: '/graphql',
|
||||
csrfPrevention: {
|
||||
requestHeaders: ['content-type'],
|
||||
},
|
||||
autoSchemaFile: join(
|
||||
fileURLToPath(import.meta.url),
|
||||
config.node.dev
|
||||
? '../../../schema.gql'
|
||||
: '../../../../node_modules/.cache/schema.gql'
|
||||
),
|
||||
sortSchema: true,
|
||||
context: ({
|
||||
req,
|
||||
res,
|
||||
@@ -55,7 +53,7 @@ export type GraphqlContext = {
|
||||
|
||||
// @ts-expect-error allow assign
|
||||
formattedError.extensions = ufe.toJSON();
|
||||
if (config.affine.canary) {
|
||||
if (env.namespaces.canary) {
|
||||
formattedError.extensions.stacktrace = ufe.stacktrace;
|
||||
}
|
||||
return formattedError;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Type } from '@nestjs/common';
|
||||
import { Field, FieldOptions, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { ApplyType } from '../utils/types';
|
||||
@@ -7,7 +6,7 @@ export function registerObjectType<T>(
|
||||
fields: Record<
|
||||
string,
|
||||
{
|
||||
type: () => Type<any>;
|
||||
type: () => any;
|
||||
options?: FieldOptions;
|
||||
}
|
||||
>,
|
||||
|
||||
Reference in New Issue
Block a user