-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load the new featureFlags into global state and allow updating via qu…
…ery params (prefix: `pinboardFeatureFlag_`)
- Loading branch information
1 parent
a4c4519
commit 4e2ee67
Showing
6 changed files
with
115 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { readAndThenSilentlyDropQueryParamFromURL } from "./util"; | ||
import { ApolloClient } from "@apollo/client"; | ||
import { gqlChangeFeatureFlag } from "../gql"; | ||
|
||
export const ALLOWED_FEATURE_FLAGS = ["test"] as const; | ||
export type AllowedFeatureFlags = (typeof ALLOWED_FEATURE_FLAGS)[number]; | ||
|
||
export type FeatureFlags = Partial<Record<AllowedFeatureFlags, boolean>>; | ||
|
||
export const extractFeatureFlags = ( | ||
featureFlagsStr: string | null | undefined | ||
): FeatureFlags => | ||
featureFlagsStr ? (JSON.parse(featureFlagsStr) as FeatureFlags) : {}; | ||
|
||
export const consumeFeatureFlagQueryParamsAndUpdateAccordingly = ( | ||
apolloClient: ApolloClient<unknown> | ||
) => | ||
ALLOWED_FEATURE_FLAGS.forEach((flagId) => { | ||
const flagStringValue = readAndThenSilentlyDropQueryParamFromURL( | ||
`pinboardFeatureFlag_${flagId}` | ||
); | ||
if (flagStringValue !== null) { | ||
apolloClient | ||
.mutate({ | ||
mutation: gqlChangeFeatureFlag, | ||
variables: { | ||
flagId, | ||
newValue: flagStringValue === "true", | ||
}, | ||
}) | ||
.catch(console.error); | ||
// we rely on the subscription 'updateUserWithChanges' | ||
} | ||
}); |
Oops, something went wrong.