Skip to content

Commit

Permalink
Better CLI (#6862)
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo authored Apr 19, 2024
1 parent 0af7ade commit 31828ad
Show file tree
Hide file tree
Showing 53 changed files with 594 additions and 607 deletions.
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_compose-cli-6862-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/compose-cli": patch
---
dependencies updates:
- Added dependency [`@commander-js/extra-typings@^12.0.1` ↗︎](https://www.npmjs.com/package/@commander-js/extra-typings/v/12.0.1) (to `dependencies`)
- Added dependency [`commander@^12.0.0` ↗︎](https://www.npmjs.com/package/commander/v/12.0.0) (to `dependencies`)
- Removed dependency [`spinnies@^0.5.1` ↗︎](https://www.npmjs.com/package/spinnies/v/0.5.1) (from `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/@graphql-mesh_serve-cli-6862-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/serve-cli": patch
---
dependencies updates:
- Added dependency [`@commander-js/extra-typings@^12.0.1` ↗︎](https://www.npmjs.com/package/@commander-js/extra-typings/v/12.0.1) (to `dependencies`)
- Added dependency [`@graphql-tools/utils@^10.1.3` ↗︎](https://www.npmjs.com/package/@graphql-tools/utils/v/10.1.3) (to `dependencies`)
- Added dependency [`commander@^12.0.0` ↗︎](https://www.npmjs.com/package/commander/v/12.0.0) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/angry-cows-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/compose-cli": minor
---

Better CLI, supporting arguments and adding help in the shell
33 changes: 33 additions & 0 deletions .changeset/beige-bottles-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
"@graphql-mesh/compose-cli": minor
---

Rename `target` option to `output` in order to be more clear that it's the output file.

```diff
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql';
import { defineConfig } from '@graphql-mesh/compose-cli';

export const composeConfig = defineConfig({
- target: 'fusiongraph.graphql',
+ output: 'fusiongraph.graphql',
subgraphs: [
{
sourceHandler: () => ({
name: 'helloworld',
schema$: new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
hello: {
type: GraphQLString,
resolve: () => 'world',
},
},
}),
}),
}),
},
],
});
```
5 changes: 5 additions & 0 deletions .changeset/long-eagles-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/compose-cli": minor
---

Rename `runComposeCLI` to just `run` and change the supported options
5 changes: 5 additions & 0 deletions .changeset/new-cycles-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/serve-cli": minor
---

Better CLI, supporting arguments and adding help in the shell
5 changes: 5 additions & 0 deletions .changeset/stupid-baboons-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/serve-cli": minor
---

Rename `runServeCLI` to just `run` and change the supported options
6 changes: 3 additions & 3 deletions e2e/auto-type-merging/auto-type-merging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ it.concurrent.each([
`,
},
])('should execute $name', async ({ query }) => {
const { target } = await compose({
target: 'graphql',
const { output } = await compose({
output: 'graphql',
services: [petstore, await service('vaccination')],
});
const { execute } = await serve({ fusiongraph: target });
const { execute } = await serve({ fusiongraph: output });
await expect(execute({ query })).resolves.toMatchSnapshot();
});
23 changes: 2 additions & 21 deletions e2e/auto-type-merging/mesh.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import {
createFilterTransform,
createNamingConventionTransform,
createPrefixTransform,
defineConfig as defineComposeConfig,
defineConfig,
loadGraphQLHTTPSubgraph,
} from '@graphql-mesh/compose-cli';
import { defineConfig as defineServeConfig } from '@graphql-mesh/serve-cli';
import { loadOpenAPISubgraph } from '@omnigraph/openapi';

const args = Args(process.argv);

export const composeConfig = defineComposeConfig({
target: args.get('target'),
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadOpenAPISubgraph('petstore', {
Expand Down Expand Up @@ -45,20 +43,3 @@ export const composeConfig = defineComposeConfig({
},
],
});

export const serveConfig = defineServeConfig({
port: args.getPort(),
fusiongraph: args.get('fusiongraph'),
graphiql: {
defaultQuery: /* GraphQL */ `
query Test {
getPetById(petId: 1) {
__typename
id
name
vaccinated
}
}
`,
},
});
4 changes: 2 additions & 2 deletions e2e/batching-resolver/batching-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ it.concurrent.each([
`,
},
])('should execute $name', async ({ query }) => {
const { target } = await compose({ target: 'graphql', services: [await service('api')] });
const { execute } = await serve({ fusiongraph: target });
const { output } = await compose({ output: 'graphql', services: [await service('api')] });
const { execute } = await serve({ fusiongraph: output });
await expect(execute({ query })).resolves.toMatchSnapshot();
});
11 changes: 2 additions & 9 deletions e2e/batching-resolver/mesh.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Args } from '@e2e/args';
import { defineConfig as defineComposeConfig } from '@graphql-mesh/compose-cli';
import { defineConfig as defineServeConfig } from '@graphql-mesh/serve-cli';
import { defineConfig } from '@graphql-mesh/compose-cli';
import { loadOpenAPISubgraph } from '@omnigraph/openapi';

const args = Args(process.argv);

export const composeConfig = defineComposeConfig({
target: args.get('target'),
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadOpenAPISubgraph('API', {
Expand All @@ -33,8 +31,3 @@ export const composeConfig = defineComposeConfig({
}
`,
});

export const serveConfig = defineServeConfig({
port: args.getPort(),
fusiongraph: args.get('fusiongraph'),
});
15 changes: 3 additions & 12 deletions e2e/cjs-project/mesh.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
const { GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');
const { defineConfig: defineComposeConfig } = require('@graphql-mesh/compose-cli');
const { defineConfig: defineServeConfig } = require('@graphql-mesh/serve-cli');
const { defineConfig } = require('@graphql-mesh/compose-cli');

const args = require('@e2e/args').Args(process.argv);

const serveConfig = defineServeConfig({
port: args.getPort(),
fusiongraph: '',
});

const composeConfig = defineComposeConfig({
port: args.get('target'),
const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: () => ({
Expand All @@ -31,4 +22,4 @@ const composeConfig = defineComposeConfig({
],
});

module.exports = { serveConfig, composeConfig };
module.exports = { composeConfig };
23 changes: 23 additions & 0 deletions e2e/compose-to-output/compose-to-output.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { createTenv } from '@e2e/tenv';

const { compose, fs } = createTenv(__dirname);

it('should write compose output to fusiongraph.graphql', async () => {
const { output } = await compose({ output: 'graphql' });
await expect(fs.read(output)).resolves.toMatchSnapshot();
});

it('should write compose output to fusiongraph.json', async () => {
const { output } = await compose({ output: 'json' });
await expect(fs.read(output)).resolves.toMatchSnapshot();
});

it('should write compose output to fusiongraph.js', async () => {
const { output } = await compose({ output: 'js' });
await expect(fs.read(output)).resolves.toMatchSnapshot();
});

it('should write compose output to fusiongraph.ts', async () => {
const { output } = await compose({ output: 'ts' });
await expect(fs.read(output)).resolves.toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql';
import { Args } from '@e2e/args';
import { defineConfig } from '@graphql-mesh/compose-cli';

export const composeConfig = defineConfig({
target: Args(process.argv).get('target', true),
subgraphs: [
{
sourceHandler: () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@e2e/compose-to-target",
"name": "@e2e/compose-to-output",
"type": "module",
"private": true,
"dependencies": {
Expand Down
23 changes: 0 additions & 23 deletions e2e/compose-to-target/compose-to-target.test.ts

This file was deleted.

14 changes: 2 additions & 12 deletions e2e/esm-config-in-cjs-project/mesh.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql';
import { Args } from '@e2e/args';
import { defineConfig as defineComposeConfig } from '@graphql-mesh/compose-cli';
import { defineConfig as defineServeConfig } from '@graphql-mesh/serve-cli';
import { defineConfig } from '@graphql-mesh/compose-cli';

const args = Args(process.argv);

export const serveConfig = defineServeConfig({
port: args.getPort(),
fusiongraph: '',
});

export const composeConfig = defineComposeConfig({
target: args.get('target'),
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: () => ({
Expand Down
14 changes: 2 additions & 12 deletions e2e/esm-project/mesh.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql';
import { Args } from '@e2e/args';
import { defineConfig as defineComposeConfig } from '@graphql-mesh/compose-cli';
import { defineConfig as defineServeConfig } from '@graphql-mesh/serve-cli';
import { defineConfig } from '@graphql-mesh/compose-cli';

const args = Args(process.argv);

export const serveConfig = defineServeConfig({
port: args.getPort(),
fusiongraph: '',
});

export const composeConfig = defineComposeConfig({
target: args.get('target'),
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: () => ({
Expand Down
9 changes: 0 additions & 9 deletions e2e/federation-example/mesh.config.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ it('should compose the appropriate schema', async () => {
it('should query, mutate and subscribe', async () => {
const servePort = await getAvailablePort();
const api = await service('api', { servePort });
const { target } = await compose({ target: 'graphql', services: [api] });
const { execute } = await serve({ fusiongraph: target, port: servePort });
const { output } = await compose({ output: 'graphql', services: [api] });
const { execute } = await serve({ fusiongraph: output, port: servePort });

await expect(
execute({
Expand Down
4 changes: 1 addition & 3 deletions e2e/json-schema-subscriptions/mesh.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { loadJSONSchemaSubgraph } from '@omnigraph/json-schema';
const args = Args(process.argv);

export const composeConfig = defineComposeConfig({
target: args.get('target'),
subgraphs: [
{
sourceHandler: loadJSONSchemaSubgraph('API', {
Expand Down Expand Up @@ -49,8 +48,7 @@ export const composeConfig = defineComposeConfig({
});

export const serveConfig = defineServeConfig({
port: args.getPort(),
fusiongraph: args.get('fusiongraph'),
fusiongraph: '', // TODO: dont require fusiongraph option since it can be provided from as a CLI arg
pubsub: new PubSub(),
plugins: ctx => [
useWebhooks(ctx),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,3 @@ type Query {
}
"
`;

exports[`should write compose output to stdout and logs to stderr 2`] = `
"- Starting Mesh Compose CLI
- Starting Mesh Compose CLI
- Loading Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Starting Mesh Compose CLI
- Loaded Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Starting Mesh Compose CLI
- Loaded Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Loading subgraph helloworld
- Starting Mesh Compose CLI
- Loaded Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Loaded subgraph helloworld
- Starting Mesh Compose CLI
- Loaded Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Loaded subgraph helloworld
- Composing fusiongraph
- Starting Mesh Compose CLI
- Loaded Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Loaded subgraph helloworld
- Composed fusiongraph
- Starting Mesh Compose CLI
- Loaded Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Loaded subgraph helloworld
- Composed fusiongraph
- Writing Fusiongraph
- Starting Mesh Compose CLI
- Loaded Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Loaded subgraph helloworld
- Composed fusiongraph
- Written fusiongraph to stdout
- Finished Mesh Compose CLI
- Loaded Mesh Compose CLI Config from e2e/logs-to-stderr-results-to-stdout/mesh.config.ts
- Loaded subgraph helloworld
- Composed fusiongraph
- Written fusiongraph to stdout
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ it('should write serve logs to stderr', async () => {
await dispose();

expect(getStd('out')).toBeFalsy();
expect(getStd('err')).toContain('Started server on');
expect(getStd('err')).toContain('Starting server on');
});

it('should write compose output to stdout and logs to stderr', async () => {
const { getStd } = await compose();

expect(getStd('out')).toMatchSnapshot();
expect(getStd('err')).toMatchSnapshot();
expect(getStd('err')).toContain('Done!');
});
Loading

0 comments on commit 31828ad

Please sign in to comment.