diff --git a/packages/backend/server/src/modules/config.ts b/packages/backend/server/src/modules/config.ts new file mode 100644 index 0000000000..d0fb9e69d4 --- /dev/null +++ b/packages/backend/server/src/modules/config.ts @@ -0,0 +1,30 @@ +import { Module } from '@nestjs/common'; +import { Field, ObjectType, Query } from '@nestjs/graphql'; + +import { SERVER_FLAVOR } from '../modules'; + +@ObjectType() +export class ServerConfigType { + @Field({ description: 'server version' }) + version!: string; + + @Field({ description: 'server flavor' }) + flavor!: string; +} + +export class ServerConfigResolver { + @Query(() => ServerConfigType, { + description: 'server config', + }) + serverConfig(): ServerConfigType { + return { + version: AFFiNE.version, + flavor: SERVER_FLAVOR || 'allinone', + }; + } +} + +@Module({ + providers: [ServerConfigResolver], +}) +export class ServerConfigModule {} diff --git a/packages/backend/server/src/modules/index.ts b/packages/backend/server/src/modules/index.ts index 34458f4a2d..0239a5c5b6 100644 --- a/packages/backend/server/src/modules/index.ts +++ b/packages/backend/server/src/modules/index.ts @@ -3,7 +3,7 @@ import { EventEmitterModule } from '@nestjs/event-emitter'; import { ScheduleModule } from '@nestjs/schedule'; import { GqlModule } from '../graphql.module'; -import { AuthModule } from './auth'; +import { ServerConfigModule } from './config'; import { DocModule } from './doc'; import { PaymentModule } from './payment'; import { SyncModule } from './sync'; @@ -22,13 +22,23 @@ switch (SERVER_FLAVOR) { case 'sync': BusinessModules.push(SyncModule, DocModule.forSync()); break; - case 'graphql': + case 'selfhosted': BusinessModules.push( + ServerConfigModule, + ScheduleModule.forRoot(), + GqlModule, + WorkspaceModule, + UsersModule, + DocModule.forRoot() + ); + break; + case 'graphql': + BusinessModules.push( + ServerConfigModule, ScheduleModule.forRoot(), GqlModule, WorkspaceModule, UsersModule, - AuthModule, DocModule.forRoot(), PaymentModule ); @@ -36,11 +46,11 @@ switch (SERVER_FLAVOR) { case 'allinone': default: BusinessModules.push( + ServerConfigModule, ScheduleModule.forRoot(), GqlModule, WorkspaceModule, UsersModule, - AuthModule, SyncModule, DocModule.forRoot(), PaymentModule @@ -48,4 +58,4 @@ switch (SERVER_FLAVOR) { break; } -export { BusinessModules }; +export { BusinessModules, SERVER_FLAVOR }; diff --git a/packages/backend/server/src/schema.gql b/packages/backend/server/src/schema.gql index 9bbce9fb1c..cd76576875 100644 --- a/packages/backend/server/src/schema.gql +++ b/packages/backend/server/src/schema.gql @@ -2,6 +2,14 @@ # THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) # ------------------------------------------------------ +type ServerConfigType { + """server version""" + version: String! + + """server flavor""" + flavor: String! +} + type UserType { id: ID! @@ -240,6 +248,9 @@ type DocHistoryType { } type Query { + """server config""" + serverConfig: ServerConfigType! + """Get is owner of workspace""" isOwner(workspaceId: String!): Boolean! diff --git a/packages/frontend/graphql/src/graphql/index.ts b/packages/frontend/graphql/src/graphql/index.ts index 4fd2c04148..86ef26cfd1 100644 --- a/packages/frontend/graphql/src/graphql/index.ts +++ b/packages/frontend/graphql/src/graphql/index.ts @@ -545,6 +545,20 @@ mutation sendVerifyChangeEmail($token: String!, $email: String!, $callbackUrl: S }`, }; +export const serverConfigQuery = { + id: 'serverConfigQuery' as const, + operationName: 'serverConfig', + definitionName: 'serverConfig', + containsFile: false, + query: ` +query serverConfig { + serverConfig { + version + flavor + } +}`, +}; + export const setWorkspacePublicByIdMutation = { id: 'setWorkspacePublicByIdMutation' as const, operationName: 'setWorkspacePublicById', diff --git a/packages/frontend/graphql/src/graphql/server-config.gql b/packages/frontend/graphql/src/graphql/server-config.gql new file mode 100644 index 0000000000..6f7a99a477 --- /dev/null +++ b/packages/frontend/graphql/src/graphql/server-config.gql @@ -0,0 +1,6 @@ +query serverConfig { + serverConfig { + version + flavor + } +} diff --git a/packages/frontend/graphql/src/schema.ts b/packages/frontend/graphql/src/schema.ts index 99b6282ca3..e1d84f572b 100644 --- a/packages/frontend/graphql/src/schema.ts +++ b/packages/frontend/graphql/src/schema.ts @@ -533,6 +533,17 @@ export type SendVerifyChangeEmailMutation = { sendVerifyChangeEmail: boolean; }; +export type ServerConfigQueryVariables = Exact<{ [key: string]: never }>; + +export type ServerConfigQuery = { + __typename?: 'Query'; + serverConfig: { + __typename?: 'ServerConfigType'; + version: string; + flavor: string; + }; +}; + export type SetWorkspacePublicByIdMutationVariables = Exact<{ id: Scalars['ID']['input']; public: Scalars['Boolean']['input']; @@ -732,6 +743,11 @@ export type Queries = variables: PricesQueryVariables; response: PricesQuery; } + | { + name: 'serverConfigQuery'; + variables: ServerConfigQueryVariables; + response: ServerConfigQuery; + } | { name: 'subscriptionQuery'; variables: SubscriptionQueryVariables;