mirror of
https://github.com/wassname/talk.git
synced 2026-07-27 11:28:12 +08:00
[CORL-824] Feature Flags (#2756)
* feat: implemented feature flag * fix: support deprecated enums
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
import TenantContext from "coral-server/graph/tenant/context";
|
||||
import { GQLUpdateSettingsInput } from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
import { Tenant } from "coral-server/models/tenant";
|
||||
import { regenerateSSOKey, update } from "coral-server/services/tenant";
|
||||
import {
|
||||
disableFeatureFlag,
|
||||
enableFeatureFlag,
|
||||
regenerateSSOKey,
|
||||
update,
|
||||
} from "coral-server/services/tenant";
|
||||
|
||||
import {
|
||||
GQLFEATURE_FLAG,
|
||||
GQLUpdateSettingsInput,
|
||||
} from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
|
||||
export const Settings = ({
|
||||
mongo,
|
||||
@@ -15,4 +24,8 @@ export const Settings = ({
|
||||
update(mongo, redis, tenantCache, config, tenant, input.settings),
|
||||
regenerateSSOKey: (): Promise<Tenant | null> =>
|
||||
regenerateSSOKey(mongo, redis, tenantCache, tenant, now),
|
||||
enableFeatureFlag: (flag: GQLFEATURE_FLAG) =>
|
||||
enableFeatureFlag(mongo, redis, tenantCache, tenant, flag),
|
||||
disableFeatureFlag: (flag: GQLFEATURE_FLAG) =>
|
||||
disableFeatureFlag(mongo, redis, tenantCache, tenant, flag),
|
||||
});
|
||||
|
||||
@@ -229,4 +229,12 @@ export const Mutation: Required<GQLMutationTypeResolver<void>> = {
|
||||
user: await ctx.mutators.Users.deleteModeratorNote(input),
|
||||
clientMutationId: input.clientMutationId,
|
||||
}),
|
||||
enableFeatureFlag: async (source, { input }, ctx) => ({
|
||||
flags: await ctx.mutators.Settings.enableFeatureFlag(input.flag),
|
||||
clientMutationId: input.clientMutationId,
|
||||
}),
|
||||
disableFeatureFlag: async (source, { input }, ctx) => ({
|
||||
flags: await ctx.mutators.Settings.disableFeatureFlag(input.flag),
|
||||
clientMutationId: input.clientMutationId,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
import { GQLSettingsTypeResolver } from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
import { Tenant } from "coral-server/models/tenant";
|
||||
|
||||
import {
|
||||
GQLFEATURE_FLAG,
|
||||
GQLSettingsTypeResolver,
|
||||
} from "coral-server/graph/tenant/schema/__generated__/types";
|
||||
|
||||
const filterValidFeatureFlags = () => {
|
||||
// Compute the valid flags based on this enum.
|
||||
const flags = Object.values(GQLFEATURE_FLAG);
|
||||
|
||||
// Return a type guard for the feature flag.
|
||||
return (flag: string | GQLFEATURE_FLAG): flag is GQLFEATURE_FLAG =>
|
||||
flags.includes(flag);
|
||||
};
|
||||
|
||||
export const Settings: GQLSettingsTypeResolver<Tenant> = {
|
||||
slack: ({ slack = {} }) => slack,
|
||||
featureFlags: ({ featureFlags = [] }) =>
|
||||
featureFlags.filter(filterValidFeatureFlags()),
|
||||
};
|
||||
|
||||
@@ -333,6 +333,14 @@ type ActionPresence {
|
||||
## Settings
|
||||
################################################################################
|
||||
|
||||
enum FEATURE_FLAG {
|
||||
"""
|
||||
DISABLE_WARN_USER_OF_TOXIC_COMMENT when enabled will turn off warnings for
|
||||
toxic comments.
|
||||
"""
|
||||
DISABLE_WARN_USER_OF_TOXIC_COMMENT
|
||||
}
|
||||
|
||||
# The moderation mode of the site.
|
||||
enum MODERATION_MODE {
|
||||
"""
|
||||
@@ -967,7 +975,6 @@ type SlackChannelTriggers {
|
||||
featuredComments is whether this channel will receive featured comments
|
||||
"""
|
||||
featuredComments: Boolean!
|
||||
|
||||
}
|
||||
|
||||
type SlackChannel {
|
||||
@@ -1323,6 +1330,11 @@ type Settings {
|
||||
"""
|
||||
stories: StoryConfiguration! @auth(roles: [ADMIN])
|
||||
|
||||
"""
|
||||
featureFlags provides the enabled feature flags.
|
||||
"""
|
||||
featureFlags: [FEATURE_FLAG!]! @auth(roles: [ADMIN])
|
||||
|
||||
"""
|
||||
createdAt is the time that the Settings was created at.
|
||||
"""
|
||||
@@ -3480,7 +3492,6 @@ input SlackTriggersConfigurationInput {
|
||||
featuredComments is whether this channel will receive featured comments
|
||||
"""
|
||||
featuredComments: Boolean
|
||||
|
||||
}
|
||||
|
||||
input SlackChannelConfigurationInput {
|
||||
@@ -5247,6 +5258,62 @@ type RequestUserCommentsDownloadPayload {
|
||||
archiveURL: String!
|
||||
}
|
||||
|
||||
#########################
|
||||
# enableFeatureFlag
|
||||
#########################
|
||||
|
||||
input EnableFeatureFlagInput {
|
||||
"""
|
||||
clientMutationId is required for Relay support.
|
||||
"""
|
||||
clientMutationId: String!
|
||||
|
||||
"""
|
||||
flag is the feature flag to create.
|
||||
"""
|
||||
flag: FEATURE_FLAG!
|
||||
}
|
||||
|
||||
type EnableFeatureFlagPayload {
|
||||
"""
|
||||
clientMutationId is required for Relay support.
|
||||
"""
|
||||
clientMutationId: String!
|
||||
|
||||
"""
|
||||
flags is the current set of flags enabled.
|
||||
"""
|
||||
flags: [FEATURE_FLAG!]!
|
||||
}
|
||||
|
||||
#########################
|
||||
# disableFeatureFlag
|
||||
#########################
|
||||
|
||||
input DisableFeatureFlagInput {
|
||||
"""
|
||||
clientMutationId is required for Relay support.
|
||||
"""
|
||||
clientMutationId: String!
|
||||
|
||||
"""
|
||||
flag is the feature flag to delete.
|
||||
"""
|
||||
flag: FEATURE_FLAG!
|
||||
}
|
||||
|
||||
type DisableFeatureFlagPayload {
|
||||
"""
|
||||
clientMutationId is required for Relay support.
|
||||
"""
|
||||
clientMutationId: String!
|
||||
|
||||
"""
|
||||
flags is the current set of flags enabled.
|
||||
"""
|
||||
flags: [FEATURE_FLAG!]!
|
||||
}
|
||||
|
||||
##################
|
||||
## Mutation
|
||||
##################
|
||||
@@ -5605,6 +5672,19 @@ type Mutation {
|
||||
deleteModeratorNote(
|
||||
input: DeleteModeratorNoteInput!
|
||||
): DeleteModeratorNotePayload! @auth(roles: [ADMIN, MODERATOR])
|
||||
|
||||
"""
|
||||
enableFeatureFlag will enable a given FEATURE_FLAG.
|
||||
"""
|
||||
enableFeatureFlag(input: EnableFeatureFlagInput!): EnableFeatureFlagPayload!
|
||||
@auth(roles: [ADMIN])
|
||||
|
||||
"""
|
||||
disableFeatureFlag will disable a given FEATURE_FLAG
|
||||
"""
|
||||
disableFeatureFlag(
|
||||
input: DisableFeatureFlagInput!
|
||||
): DisableFeatureFlagPayload! @auth(roles: [ADMIN])
|
||||
}
|
||||
|
||||
##################
|
||||
|
||||
Reference in New Issue
Block a user