Skip to content

Commit

Permalink
feat: handle creating, publishing, and updating Event-Driven Graphs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Aenimus committed Jun 6, 2024
1 parent 430d5a5 commit fc2a8f2
Show file tree
Hide file tree
Showing 36 changed files with 4,978 additions and 155 deletions.
2 changes: 1 addition & 1 deletion aws-lambda-router/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/akrylysov/algnhsa v1.1.0
github.com/aws/aws-lambda-go v1.43.0
github.com/stretchr/testify v1.9.0
github.com/wundergraph/cosmo/router v0.0.0-20240530184236-089ee20d3f95
github.com/wundergraph/cosmo/router v0.0.0-20240606092735-430d5a5ba4d5
go.uber.org/zap v1.26.0
)

Expand Down
4 changes: 2 additions & 2 deletions aws-lambda-router/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4d
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/vektah/gqlparser/v2 v2.5.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8=
github.com/vektah/gqlparser/v2 v2.5.11/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc=
github.com/wundergraph/cosmo/router v0.0.0-20240530184236-089ee20d3f95 h1:9kFpr9a9icOmeZvuAHknE59KSvgcPFpJiFzBjBSc2PU=
github.com/wundergraph/cosmo/router v0.0.0-20240530184236-089ee20d3f95/go.mod h1:SWxEdofFxORnJKCltuoE/DCIsnGLxgEYBcDrkCsq1KU=
github.com/wundergraph/cosmo/router v0.0.0-20240606092735-430d5a5ba4d5 h1:Luoq0WDWv5MgckFS12o9gq/2+uPyVtTcWuFvs0jg+AY=
github.com/wundergraph/cosmo/router v0.0.0-20240606092735-430d5a5ba4d5/go.mod h1:U2XYwUmQwZGKCMbSR50/2j/cBiVJ76b0pKN51pFknLY=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.46 h1:K+eX3DGftFRYHfiKCOmxeQZImxZXpGIDaxKohb7Aa1s=
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.46/go.mod h1:YCJyt5TSr4luj4YWFGk93ayC/0KwHVEJmhgcNhcfLBc=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
Expand Down
11 changes: 8 additions & 3 deletions cli/src/commands/graph/federated-graph/commands/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export default (opts: BaseCommandOptions) => {

const cosmoSubgraphsConfig: {
name: string;
routing_url: string;
schema: {
file: string;
};
routing_url?: string;
subscription?: {
url: string;
protocol: string;
Expand Down Expand Up @@ -90,15 +90,20 @@ export default (opts: BaseCommandOptions) => {
if (!subgraphSDL) {
continue;
}
/* The config.yaml should not define a routing URL if the subgraph is an EDG.
* The local routingUrl variable is an empty object when the subgraph is an EDG, and a set property otherwise.
* This variable is spread into the push to ensure the routing URL is only defined when necessary.
* */
const routingUrl = subgraph.isEventDrivenGraph ? {} : { routing_url: subgraph.routingURL };
const filePath = join(subgraphPath, `${subgraph.name}.graphql`);
cosmoSubgraphsConfig.push({
name: subgraph.name,
routing_url: subgraph.routingURL,
...routingUrl,
schema: {
file: filePath,
},
subscription:
subgraph.subscriptionURL === ''
subgraph.subscriptionURL === '' || subgraph.isEventDrivenGraph
? undefined
: { url: subgraph.subscriptionURL, protocol: subgraph.subscriptionProtocol },
});
Expand Down
6 changes: 4 additions & 2 deletions cli/src/commands/graph/federated-graph/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
import { Subgraph as ProtoSubgraph } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb';
import { program } from 'commander';
import { BREAK, parse, visit } from 'graphql';
import jwtDecode from 'jwt-decode';
import pc from 'picocolors';
import { Client } from '../../../core/client/client.js';
Expand Down Expand Up @@ -72,6 +72,7 @@ export interface Subgraph {
routingURL: string;
subscriptionURL: string;
subscriptionProtocol: string;
isEventDrivenGraph?: boolean;
isV2Graph?: boolean;
}

Expand Down Expand Up @@ -105,12 +106,13 @@ export const getSubgraphsOfFedGraph = async ({

const subgraphs = await resp.subgraphs;

return subgraphs.map((s) => {
return subgraphs.map((s: ProtoSubgraph) => {
return {
name: s.name,
routingURL: s.routingURL,
subscriptionURL: s.subscriptionUrl,
subscriptionProtocol: s.subscriptionProtocol,
isEventDrivenGraph: s.isEventDrivenGraph,
isV2Graph: s.isV2Graph,
};
});
Expand Down
23 changes: 18 additions & 5 deletions cli/src/commands/subgraph/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,36 @@ export default (opts: BaseCommandOptions) => {
'The name of the subgraph to create. It is usually in the format of <org>.<service.name> and is used to uniquely identify your subgraph.',
);
command.option('-n, --namespace [string]', 'The namespace of the subgraph.');
command.requiredOption(
command.option(
'-r, --routing-url <url>',
'The routing url of your subgraph. This is the url that the subgraph will be accessible at.',
'The routing URL of your subgraph. This is the url at which the subgraph will be accessible.' +
' Required unless the event-driven-graph flag is set.' +
' Returns an error if the event-driven-graph flag is set.',
);
command.option(
'--label [labels...]',
'The labels to apply to the subgraph. The labels are passed in the format <key>=<value> <key>=<value>.',
);
command.option(
'--subscription-url [url]',
'The url used for subscriptions. If empty, it defaults to same url used for routing.',
'The URL used for subscriptions. If empty, it defaults to same url used for routing.' +
' Returns an error if the event-driven-graph flag is set.',
);
command.option(
'--subscription-protocol <protocol>',
'The protocol to use when subscribing to the subgraph. The supported protocols are ws, sse, and sse_post.',
'The protocol to use when subscribing to the subgraph. The supported protocols are ws, sse, and sse_post.' +
' Returns an error if the event-driven-graph flag is set.',
);
command.option(
'--websocket-subprotocol <protocol>',
websocketSubprotocolDescription + ' Returns an error if the event-driven-graph flag is set.',
);
command.option('--websocket-subprotocol <protocol>', websocketSubprotocolDescription);
command.option('--readme <path-to-readme>', 'The markdown file which describes the subgraph.');
command.option(
'-edg, --event-driven-graph',
'Set whether the subgraph is an Event-Driven Graph (EDG).' +
' Errors will be returned for the inclusion of most other parameters if the subgraph is an Event-Driven Graph.',
);
command.action(async (name, options) => {
let readmeFile;
if (options.readme) {
Expand Down Expand Up @@ -75,6 +87,7 @@ export default (opts: BaseCommandOptions) => {
? parseGraphQLWebsocketSubprotocol(options.websocketSubprotocol)
: undefined,
readme: readmeFile ? await readFile(readmeFile, 'utf8') : undefined,
isEventDrivenGraph: !!options.isEventDrivenGraph,
},
{
headers: getBaseHeaders(),
Expand Down
23 changes: 18 additions & 5 deletions cli/src/commands/subgraph/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,35 @@ export default (opts: BaseCommandOptions) => {
command.option('-n, --namespace [string]', 'The namespace of the subgraph.');
command.option(
'-r, --routing-url <url>',
'The routing url of your subgraph. This is the url that the subgraph will be accessible at (Only required to create the subgraph).',
'The routing URL of the subgraph. This is the URL at which the subgraph will be accessible.' +
' This parameter is always ignored if the subgraph has already been created.' +
' Required if the subgraph is not an Event-Driven Graph.' +
' Returns an error if the subgraph is an Event-Driven Graph.',
);
command.option(
'--label [labels...]',
'The labels to apply to the subgraph. The labels are passed in the format <key>=<value> <key>=<value>. Required to create the subgraph. This will overwrite existing labels.',
'The labels to apply to the subgraph. The labels are passed in the format <key>=<value> <key>=<value>.' +
' This parameter is always ignored if the subgraph has already been created.',
[],
);
command.option(
'--subscription-url [url]',
'The url used for subscriptions. If empty, it defaults to same url used for routing.',
'The url used for subscriptions. If empty, it defaults to same url used for routing.' +
' This parameter is always ignored if the subgraph has already been created.' +
' Returns an error if the subgraph is an Event-Driven Graph.',
);
command.option(
'--subscription-protocol <protocol>',
'The protocol to use when subscribing to the subgraph. The supported protocols are ws, sse, and sse_post.',
'The protocol to use when subscribing to the subgraph. The supported protocols are ws, sse, and sse_post.' +
' This parameter is always ignored if the subgraph has already been created.' +
' Returns an error if the subgraph is an Event-Driven Graph.',
);
command.option(
'--websocket-subprotocol <protocol>',
websocketSubprotocolDescription +
' This parameter is always ignored if the subgraph has already been created.' +
' Returns an error if the subgraph is an Event-Driven Graph.',
);
command.option('--websocket-subprotocol <protocol>', websocketSubprotocolDescription);
command.option(
'--fail-on-composition-error',
'If set, the command will fail if the composition of the federated graph fails.',
Expand Down
14 changes: 10 additions & 4 deletions cli/src/commands/subgraph/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default (opts: BaseCommandOptions) => {
command.option('-n, --namespace [string]', 'The namespace of the subgraph.');
command.option(
'-r, --routing-url <url>',
'The routing url of your subgraph. This is the url that the subgraph will be accessible at.',
'The routing URL of the subgraph. This is the URL at which the subgraph will be accessible.' +
' Returns an error if the subgraph is an Event-Driven Graph.',
);
command.option(
'--label [labels...]',
Expand All @@ -35,13 +36,18 @@ export default (opts: BaseCommandOptions) => {
);
command.option(
'--subscription-url <url>',
'The url used for subscriptions. If empty, it defaults to same url used for routing.',
'The url used for subscriptions. If empty, it defaults to same url used for routing.' +
' Returns an error if the subgraph is an Event-Driven Graph.',
);
command.option(
'--subscription-protocol <protocol>',
'The protocol to use when subscribing to the subgraph. The supported protocols are ws, sse, and sse_post.',
'The protocol to use when subscribing to the subgraph. The supported protocols are ws, sse, and sse_post.' +
' Returns an error if the subgraph is an Event-Driven Graph.',
);
command.option(
'--websocket-subprotocol <protocol>',
websocketSubprotocolDescription + ' Returns an error if the subgraph is an Event-Driven Graph.',
);
command.option('--websocket-subprotocol <protocol>', websocketSubprotocolDescription);
command.option('--readme <path-to-readme>', 'The markdown file which describes the subgraph.');

command.action(async (name, options) => {
Expand Down
5 changes: 4 additions & 1 deletion cli/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const websocketSubprotocolDescription =
'The subprotocol to use when subscribing to the subgraph. The supported protocols are auto (default), graphql-ws, and graphql-transport-ws. Should be used only if the subscription protocol is ws. For more information see https://cosmo-docs.wundergraph.com/router/subscriptions/websocket-subprotocols.';
'The subprotocol to use when subscribing to the subgraph.' +
' The supported protocols are auto (default), graphql-ws, and graphql-transport-ws.' +
' Should be used only if the subscription protocol is ws.' +
' For more information see https://cosmo-docs.wundergraph.com/router/subscriptions/websocket-subprotocols.';
Loading

0 comments on commit fc2a8f2

Please sign in to comment.