forked from wundergraph/cosmo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: monograph support (wundergraph#623)
Co-authored-by: Dustin Deus <deusdustin@gmail.com>
- Loading branch information
1 parent
3317c07
commit a255f74
Showing
93 changed files
with
8,106 additions
and
1,228 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,30 @@ | ||
import { Command } from 'commander'; | ||
import { BaseCommandOptions } from '../../../core/types/types.js'; | ||
import { checkAPIKey } from '../../../utils.js'; | ||
import FetchFederatedGraphCommand from '../common/fetch.js'; | ||
import GetFederatedGraphChangelog from '../common/changelog.js'; | ||
import ListFederatedGraphs from './commands/list.js'; | ||
import CheckFederatedGraphCommand from './commands/check.js'; | ||
import CreateFederatedGraphCommand from './commands/create.js'; | ||
import DeleteFederatedGraphCommand from './commands/delete.js'; | ||
import UpdateFederatedGraphCommand from './commands/update.js'; | ||
import MoveFederatedGraph from './commands/move.js'; | ||
|
||
export default (opts: BaseCommandOptions) => { | ||
const command = new Command('federated-graph'); | ||
command.description('Provides commands for creating and managing a federated graph'); | ||
command.addCommand(CreateFederatedGraphCommand(opts)); | ||
command.addCommand(FetchFederatedGraphCommand(opts)); | ||
command.addCommand(DeleteFederatedGraphCommand(opts)); | ||
command.addCommand(UpdateFederatedGraphCommand(opts)); | ||
command.addCommand(CheckFederatedGraphCommand(opts)); | ||
command.addCommand(ListFederatedGraphs(opts)); | ||
command.addCommand(GetFederatedGraphChangelog(opts)); | ||
command.addCommand(MoveFederatedGraph(opts)); | ||
|
||
command.hook('preAction', () => { | ||
checkAPIKey(); | ||
}); | ||
|
||
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,77 @@ | ||
import { existsSync } from 'node:fs'; | ||
import { readFile } from 'node:fs/promises'; | ||
import { PartialMessage } from '@bufbuild/protobuf'; | ||
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; | ||
import { GitInfo } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb'; | ||
import { Command, program } from 'commander'; | ||
import { resolve } from 'pathe'; | ||
import pc from 'picocolors'; | ||
import { baseHeaders, config } from '../../../../core/config.js'; | ||
import { BaseCommandOptions } from '../../../../core/types/types.js'; | ||
import { verifyGitHubIntegration } from '../../../../github.js'; | ||
import { handleCheckResult } from '../../../../handle-check-result.js'; | ||
|
||
export default (opts: BaseCommandOptions) => { | ||
const command = new Command('check'); | ||
command.description('Checks for breaking changes and errors.'); | ||
command.argument('<name>', 'The name of the monograph on which the check operation is to be performed.'); | ||
command.option('-n, --namespace [string]', 'The namespace of the monograph.'); | ||
command.option('--schema <path-to-schema>', 'The path of the new schema file.'); | ||
|
||
command.action(async (name, options) => { | ||
const schemaFile = resolve(process.cwd(), options.schema); | ||
|
||
if (!existsSync(schemaFile)) { | ||
console.log( | ||
pc.red( | ||
pc.bold(`The schema file '${pc.bold(schemaFile)}' does not exist. Please check the path and try again.`), | ||
), | ||
); | ||
return; | ||
} | ||
|
||
const { gitInfo, ignoreErrorsDueToGitHubIntegration } = await verifyGitHubIntegration(opts.client); | ||
|
||
const graphResp = await opts.client.platform.getFederatedGraphByName( | ||
{ | ||
name, | ||
namespace: options.namespace, | ||
includeMetrics: false, | ||
}, | ||
{ | ||
headers: baseHeaders, | ||
}, | ||
); | ||
|
||
if (graphResp.response?.code !== EnumStatusCode.OK) { | ||
program.error(pc.red(`Could not perform check. ${graphResp.response?.details}`)); | ||
} | ||
|
||
if (graphResp.subgraphs.length === 0) { | ||
program.error(pc.red(`Could not perform check. No subgraph found.`)); | ||
} | ||
|
||
const subgraph = graphResp.subgraphs[0]; | ||
|
||
const resp = await opts.client.platform.checkSubgraphSchema( | ||
{ | ||
subgraphName: subgraph.name, | ||
namespace: subgraph.namespace, | ||
schema: await readFile(schemaFile), | ||
gitInfo, | ||
delete: false, | ||
}, | ||
{ | ||
headers: baseHeaders, | ||
}, | ||
); | ||
|
||
const success = handleCheckResult(resp); | ||
|
||
if (!success && !ignoreErrorsDueToGitHubIntegration) { | ||
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,78 @@ | ||
import { readFile } from 'node:fs/promises'; | ||
import { existsSync } from 'node:fs'; | ||
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb'; | ||
import { Command, program } from 'commander'; | ||
import { resolve } from 'pathe'; | ||
import pc from 'picocolors'; | ||
import { parseGraphQLSubscriptionProtocol } from '@wundergraph/cosmo-shared'; | ||
import ora from 'ora'; | ||
import { baseHeaders } from '../../../../core/config.js'; | ||
import { BaseCommandOptions } from '../../../../core/types/types.js'; | ||
|
||
export default (opts: BaseCommandOptions) => { | ||
const command = new Command('create'); | ||
command.description('Creates a monograph on the control plane.'); | ||
command.argument('<name>', 'The name of the graph to create. It is used to uniquely identify your graph.'); | ||
command.option('-n, --namespace [string]', 'The namespace of the graph.'); | ||
command.requiredOption( | ||
'-r, --routing-url <url>', | ||
'The routing url of your router. This is the url that the router will be accessible at.', | ||
); | ||
command.requiredOption('-u, --graph-url <url>', 'The url of your GraphQL server that is accessible from the router.'); | ||
command.option('--subscription-url [url]', 'The url used for subscriptions. If empty, it defaults to graph url.'); | ||
command.option( | ||
'--subscription-protocol <protocol>', | ||
'The protocol to use when subscribing to the graph. The supported protocols are ws, sse, and sse_post.', | ||
); | ||
command.option( | ||
'--admission-webhook-url <url>', | ||
'The admission webhook url. This is the url that the controlplane will use to implement admission control for the monograph. This is optional.', | ||
[], | ||
); | ||
command.option('--readme <path-to-readme>', 'The markdown file which describes the graph.'); | ||
command.action(async (name, options) => { | ||
let readmeFile; | ||
if (options.readme) { | ||
readmeFile = resolve(process.cwd(), options.readme); | ||
if (!existsSync(readmeFile)) { | ||
program.error( | ||
pc.red( | ||
pc.bold(`The readme file '${pc.bold(readmeFile)}' does not exist. Please check the path and try again.`), | ||
), | ||
); | ||
} | ||
} | ||
|
||
const spinner = ora('Federated Graph is being created...').start(); | ||
|
||
const resp = await opts.client.platform.createMonograph( | ||
{ | ||
name, | ||
namespace: options.namespace, | ||
routingUrl: options.routingUrl, | ||
readme: readmeFile ? await readFile(readmeFile, 'utf8') : undefined, | ||
graphUrl: options.graphUrl, | ||
subscriptionUrl: options.subscriptionUrl === true ? '' : options.subscriptionUrl, | ||
subscriptionProtocol: options.subscriptionProtocol | ||
? parseGraphQLSubscriptionProtocol(options.subscriptionProtocol) | ||
: undefined, | ||
admissionWebhookURL: options.admissionWebhookUrl, | ||
}, | ||
{ | ||
headers: baseHeaders, | ||
}, | ||
); | ||
|
||
if (resp.response?.code === EnumStatusCode.OK) { | ||
spinner.succeed('Monograph was created successfully.'); | ||
} else { | ||
spinner.fail(`Failed to create monograph.`); | ||
if (resp.response?.details) { | ||
console.log(pc.red(pc.bold(resp.response?.details))); | ||
} | ||
process.exit(1); | ||
} | ||
}); | ||
|
||
return command; | ||
}; |
Oops, something went wrong.