-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Aenimus <daviditstutt@gmail.com> Co-authored-by: Aenimus <47415099+Aenimus@users.noreply.github.com> Co-authored-by: starptech <deusdustin@gmail.com> Co-authored-by: Sergiy 🇺🇦 <818351+devsergiy@users.noreply.github.com> Co-authored-by: hardworker-bot <bot@wundergraph.com> Co-authored-by: Nithin Kumar B <nithinkumar5353@gmail.com>
- Loading branch information
1 parent
974ac21
commit 5461bb5
Showing
192 changed files
with
32,441 additions
and
15,113 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
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,76 @@ | ||
import { splitLabel } from '@wundergraph/cosmo-shared'; | ||
import { Command } from 'commander'; | ||
import ora from 'ora'; | ||
import pc from 'picocolors'; | ||
import { getBaseHeaders } from '../../../core/config.js'; | ||
import { BaseCommandOptions } from '../../../core/types/types.js'; | ||
import { handleFeatureFlagResult } from '../../../handle-feature-flag-result.js'; | ||
|
||
export default (opts: BaseCommandOptions) => { | ||
const command = new Command('create'); | ||
command.description( | ||
'Creates a feature flag on the control plane. A feature flag must contain one or more feature subgraphs.', | ||
); | ||
command.argument('<name>', 'The name of the feature flag to create.'); | ||
command.option('-n, --namespace [string]', 'The namespace of the feature flag.'); | ||
command.option( | ||
'--label [labels...]', | ||
'The labels to apply to the feature flag. The labels are passed in the format <key>=<value> <key>=<value>.', | ||
); | ||
command.requiredOption( | ||
'--fs, --feature-subgraphs <featureSubgraphs...>', | ||
'The names of the feature subgraphs that will form the feature flag.' + | ||
' The feature subgraphs are passed in the format <featureSubgraph1> <featureSubgraph2> <featureSubgraph3>.' + | ||
' The feature flag must have at least one feature subgraph.', | ||
); | ||
command.option( | ||
'-e, --enabled', | ||
'Flag that if included will enable the feature flag upon creation.' + | ||
' A new feature flag is disabled by default to prevent accidental compositions.', | ||
); | ||
command.action(async (name, options) => { | ||
const spinner = ora('The feature flag is being created...').start(); | ||
const resp = await opts.client.platform.createFeatureFlag( | ||
{ | ||
name, | ||
namespace: options.namespace, | ||
labels: options.label ? options.label.map((label: string) => splitLabel(label)) : [], | ||
featureSubgraphNames: options.featureSubgraphs, | ||
isEnabled: !!options.enabled, | ||
}, | ||
{ | ||
headers: getBaseHeaders(), | ||
}, | ||
); | ||
|
||
try { | ||
handleFeatureFlagResult({ | ||
responseCode: resp.response?.code, | ||
responseDetails: resp.response?.details, | ||
compositionErrors: resp.compositionErrors, | ||
deploymentErrors: resp.deploymentErrors, | ||
spinner, | ||
successMessage: `The feature flag "${name}" was created successfully. ${ | ||
options.enabled | ||
? '' | ||
: `To enable it, use the "wgc feature-flag enable" command or pass the "--enabled" flag when creating it.` | ||
}`, | ||
subgraphCompositionBaseErrorMessage: `The feature flag "${name}" was created but with composition errors.`, | ||
subgraphCompositionDetailedErrorMessage: | ||
`There were composition errors when composing at least one federated graph related to the` + | ||
` creation of feature flag "${name}"` + | ||
`.\nThe federated graphs will not be updated until the errors are fixed.` + | ||
`\n${pc.bold('Please check the errors below:')}`, | ||
deploymentErrorMessage: | ||
`The feature flag "${name}" was created, but the updated composition could not be deployed.` + | ||
`\nThis means the updated composition is not accessible to the router.` + | ||
`\n${pc.bold('Please check the errors below:')}`, | ||
defaultErrorMessage: `Failed to create the feature flag "${name}".`, | ||
}); | ||
} catch { | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
return command; | ||
}; |
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,66 @@ | ||
import { Command } from 'commander'; | ||
import pc from 'picocolors'; | ||
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; | ||
import inquirer from 'inquirer'; | ||
import Table from 'cli-table3'; | ||
import ora from 'ora'; | ||
import { BaseCommandOptions } from '../../../core/types/types.js'; | ||
import { getBaseHeaders } from '../../../core/config.js'; | ||
import { handleFeatureFlagResult } from '../../../handle-feature-flag-result.js'; | ||
|
||
export default (opts: BaseCommandOptions) => { | ||
const command = new Command('delete'); | ||
command.description('Deletes a feature flag from the control plane.'); | ||
command.argument('<name>', 'The name of the feature flag to delete.'); | ||
command.option('-n, --namespace [string]', 'The namespace of the feature flag.'); | ||
command.option('-f --force', 'Flag to force the deletion (skip confirmation).'); | ||
command.action(async (name, options) => { | ||
if (!options.force) { | ||
const deletionConfirmed = await inquirer.prompt({ | ||
name: 'confirmDeletion', | ||
type: 'confirm', | ||
message: `Are you sure you want to delete the feature flag "${name}"?`, | ||
}); | ||
if (!deletionConfirmed.confirmDeletion) { | ||
process.exit(1); | ||
} | ||
} | ||
|
||
const spinner = ora(`The feature flag "${name}" is being deleted...`).start(); | ||
|
||
const resp = await opts.client.platform.deleteFeatureFlag( | ||
{ | ||
name, | ||
namespace: options.namespace, | ||
}, | ||
{ | ||
headers: getBaseHeaders(), | ||
}, | ||
); | ||
|
||
try { | ||
handleFeatureFlagResult({ | ||
responseCode: resp.response?.code, | ||
responseDetails: resp.response?.details, | ||
compositionErrors: resp.compositionErrors, | ||
deploymentErrors: resp.deploymentErrors, | ||
spinner, | ||
successMessage: `The feature flag "${name}" was deleted successfully.`, | ||
subgraphCompositionBaseErrorMessage: `The feature flag "${name}" was deleted but with composition errors.`, | ||
subgraphCompositionDetailedErrorMessage: | ||
`There were composition errors when composing at least one federated graph related to the` + | ||
` deletion of feature flag "${name}".\nThe router will continue to work with the latest valid schema.` + | ||
`\n${pc.bold('Please check the errors below:')}`, | ||
deploymentErrorMessage: | ||
`The feature flag "${name}" was deleted, but the updated composition could not be deployed.` + | ||
`\nThis means the updated composition is not accessible to the router.` + | ||
`\n${pc.bold('Please check the errors below:')}`, | ||
defaultErrorMessage: `Failed to delete the feature flag "${name}".`, | ||
}); | ||
} catch { | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
return command; | ||
}; |
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,58 @@ | ||
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; | ||
import { Command } from 'commander'; | ||
import ora from 'ora'; | ||
import pc from 'picocolors'; | ||
import Table from 'cli-table3'; | ||
import { getBaseHeaders } from '../../../core/config.js'; | ||
import { BaseCommandOptions } from '../../../core/types/types.js'; | ||
import { handleFeatureFlagResult } from '../../../handle-feature-flag-result.js'; | ||
|
||
export default (opts: BaseCommandOptions) => { | ||
const command = new Command('disable'); | ||
command.description('Disables a feature flag on the control plane.'); | ||
command.argument('<name>', 'The name of the feature flag to disable.'); | ||
command.option('-n, --namespace [string]', 'The namespace of the feature flag.'); | ||
|
||
command.action(async (name, options) => { | ||
const spinner = ora(`The feature flag "${name}" is being disabled...`).start(); | ||
const resp = await opts.client.platform.enableFeatureFlag( | ||
{ | ||
name, | ||
namespace: options.namespace, | ||
enabled: false, | ||
}, | ||
{ | ||
headers: getBaseHeaders(), | ||
}, | ||
); | ||
|
||
try { | ||
handleFeatureFlagResult({ | ||
responseCode: resp.response?.code, | ||
responseDetails: resp.response?.details, | ||
compositionErrors: resp.compositionErrors, | ||
deploymentErrors: resp.deploymentErrors, | ||
spinner, | ||
successMessage: | ||
resp?.hasChanged === false | ||
? `The feature flag "${name}" is already disabled.` | ||
: `The feature flag "${name}" was disabled successfully.`, | ||
subgraphCompositionBaseErrorMessage: `The feature flag "${name}" was disabled but with composition errors.`, | ||
subgraphCompositionDetailedErrorMessage: | ||
`There were composition errors when composing at least one federated graph related to the` + | ||
` disabling of feature flag "${name}".` + | ||
`.\nThe federated graphs will not be updated until the errors are fixed.` + | ||
`\n${pc.bold('Please check the errors below:')}`, | ||
deploymentErrorMessage: | ||
`The feature flag "${name}" was disabled, but the updated composition could not be deployed.` + | ||
`\nThis means the updated composition is not accessible to the router.` + | ||
`\n${pc.bold('Please check the errors below:')}`, | ||
defaultErrorMessage: `Failed to disable the feature flag "${name}".`, | ||
}); | ||
} catch { | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
return command; | ||
}; |
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,58 @@ | ||
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; | ||
import { Command } from 'commander'; | ||
import ora from 'ora'; | ||
import pc from 'picocolors'; | ||
import Table from 'cli-table3'; | ||
import { getBaseHeaders } from '../../../core/config.js'; | ||
import { BaseCommandOptions } from '../../../core/types/types.js'; | ||
import { handleFeatureFlagResult } from '../../../handle-feature-flag-result.js'; | ||
|
||
export default (opts: BaseCommandOptions) => { | ||
const command = new Command('enable'); | ||
command.description('Enables a feature flag on the control plane.'); | ||
command.argument('<name>', 'The name of the feature flag to enable.'); | ||
command.option('-n, --namespace [string]', 'The namespace of the feature flag.'); | ||
|
||
command.action(async (name, options) => { | ||
const spinner = ora(`The feature flag "${name}" is being enabled...`).start(); | ||
const resp = await opts.client.platform.enableFeatureFlag( | ||
{ | ||
name, | ||
namespace: options.namespace, | ||
enabled: true, | ||
}, | ||
{ | ||
headers: getBaseHeaders(), | ||
}, | ||
); | ||
|
||
try { | ||
handleFeatureFlagResult({ | ||
responseCode: resp.response?.code, | ||
responseDetails: resp.response?.details, | ||
compositionErrors: resp.compositionErrors, | ||
deploymentErrors: resp.deploymentErrors, | ||
spinner, | ||
successMessage: | ||
resp?.hasChanged === false | ||
? `The feature flag "${name}" is already enabled.` | ||
: `The feature flag "${name}" was enabled successfully.`, | ||
subgraphCompositionBaseErrorMessage: `The feature flag "${name}" was enabled but with composition errors.`, | ||
subgraphCompositionDetailedErrorMessage: | ||
`There were composition errors when composing at least one federated graph related to the` + | ||
` enabling of feature flag "${name}".` + | ||
`.\nThe federated graphs will not be updated until the errors are fixed.` + | ||
`\n${pc.bold('Please check the errors below:')}`, | ||
deploymentErrorMessage: | ||
`The feature flag "${name}" was enabled, but the updated composition could not be deployed.` + | ||
`\nThis means the updated composition is not accessible to the router.` + | ||
`\n${pc.bold('Please check the errors below:')}`, | ||
defaultErrorMessage: `Failed to enable the feature flag "${name}".`, | ||
}); | ||
} catch { | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
return command; | ||
}; |
Oops, something went wrong.