Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@graphql-hive/cli): json output #6122

Draft
wants to merge 129 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
7dc21e7
feat(@graphql-hive/cli): json flag for json output
jasonkuhrt Dec 12, 2024
de6c0dc
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 13, 2024
b5f78b4
work
jasonkuhrt Dec 13, 2024
31eb025
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 13, 2024
27e8811
not this PR
jasonkuhrt Dec 13, 2024
195e466
not this pr
jasonkuhrt Dec 13, 2024
3328e20
not this pr
jasonkuhrt Dec 13, 2024
f81c69c
undo
jasonkuhrt Dec 13, 2024
2423a50
unused
jasonkuhrt Dec 13, 2024
d4bd1bf
progress, introduce envelope
jasonkuhrt Dec 13, 2024
35da5f6
more commands
jasonkuhrt Dec 13, 2024
fbc286e
refactor
jasonkuhrt Dec 13, 2024
6a4a46b
clarify log methods
jasonkuhrt Dec 13, 2024
1e3c14f
validate
jasonkuhrt Dec 13, 2024
8f68b79
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 13, 2024
c9628bb
feedback: remove unused command
jasonkuhrt Dec 16, 2024
528bad9
feedback: remove unused command reset
jasonkuhrt Dec 16, 2024
e8b65ec
feedback: remove unused commands get, delete
jasonkuhrt Dec 16, 2024
fe15732
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 16, 2024
0d5d33f
feedback: switch to typebox
jasonkuhrt Dec 16, 2024
333095c
doc
jasonkuhrt Dec 16, 2024
79f7763
refactor
jasonkuhrt Dec 16, 2024
1fbbcc7
todo
jasonkuhrt Dec 16, 2024
cf6074c
todo
jasonkuhrt Dec 16, 2024
f8986a6
work
jasonkuhrt Dec 16, 2024
754526c
fix
jasonkuhrt Dec 16, 2024
321325d
lint
jasonkuhrt Dec 16, 2024
923c422
remove command-wide try-catch
jasonkuhrt Dec 16, 2024
032ff42
fixes
jasonkuhrt Dec 16, 2024
ba14c2d
refactor
jasonkuhrt Dec 16, 2024
ad7e65c
finish check
jasonkuhrt Dec 16, 2024
d4f1b88
fix err msg
jasonkuhrt Dec 16, 2024
392ad0f
lint
jasonkuhrt Dec 16, 2024
6b9aba5
fix
jasonkuhrt Dec 16, 2024
af8721b
start tackling failures
jasonkuhrt Dec 16, 2024
def2053
single output
jasonkuhrt Dec 17, 2024
d631f8b
refactor
jasonkuhrt Dec 17, 2024
219faf5
refactor
jasonkuhrt Dec 17, 2024
58b62b8
progress
jasonkuhrt Dec 17, 2024
dee2049
build updates
jasonkuhrt Dec 17, 2024
2221fa0
fix import paths
jasonkuhrt Dec 17, 2024
6d498eb
lint
jasonkuhrt Dec 17, 2024
b258db2
no ci check for now
jasonkuhrt Dec 17, 2024
97c46dd
prettier
jasonkuhrt Dec 17, 2024
9439aa7
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 17, 2024
612aaa4
schema to own dir
jasonkuhrt Dec 17, 2024
7c1823e
refactor
jasonkuhrt Dec 17, 2024
3ccd617
look at fragments
jasonkuhrt Dec 17, 2024
a45f5d6
output helper
jasonkuhrt Dec 17, 2024
84833da
try schema match hive
jasonkuhrt Dec 17, 2024
2b8c7a8
more
jasonkuhrt Dec 17, 2024
888657a
work
jasonkuhrt Dec 17, 2024
87fe7c7
file
jasonkuhrt Dec 17, 2024
4d5644f
publish command
jasonkuhrt Dec 17, 2024
7dffe2e
helper methods for data only
jasonkuhrt Dec 18, 2024
b33e865
runResult all
jasonkuhrt Dec 18, 2024
5796094
refacotr
jasonkuhrt Dec 18, 2024
247cf5c
prettier
jasonkuhrt Dec 18, 2024
35efce1
improve jsdoc
jasonkuhrt Dec 18, 2024
b0e966e
rename
jasonkuhrt Dec 18, 2024
45af397
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 18, 2024
e15c9cf
work
jasonkuhrt Dec 18, 2024
4861b9e
fix
jasonkuhrt Dec 18, 2024
eb0b1e1
no only
jasonkuhrt Dec 18, 2024
609d286
refactor
jasonkuhrt Dec 18, 2024
1fa5079
no only
jasonkuhrt Dec 18, 2024
4b3675f
titles
jasonkuhrt Dec 18, 2024
3010a25
refactor
jasonkuhrt Dec 18, 2024
58d3c70
lint
jasonkuhrt Dec 18, 2024
9d0fc87
refactor cli tests to use inferred hive cli library
jasonkuhrt Dec 18, 2024
31cdc7c
lint
jasonkuhrt Dec 18, 2024
76eb192
no empty
jasonkuhrt Dec 18, 2024
5489204
support multi flags
jasonkuhrt Dec 19, 2024
8b23d0e
do not repeat dev interface
jasonkuhrt Dec 19, 2024
77db99a
rename
jasonkuhrt Dec 19, 2024
59b066c
rest
jasonkuhrt Dec 19, 2024
2e675fd
undo test refactors
jasonkuhrt Dec 19, 2024
438941c
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 19, 2024
ee1dcc7
vitest fixtures return
jasonkuhrt Dec 19, 2024
044835a
type fix
jasonkuhrt Dec 19, 2024
ba94eea
tmpfile util
jasonkuhrt Dec 19, 2024
cd30c27
wire up json
jasonkuhrt Dec 19, 2024
90afcf7
snapshot system
jasonkuhrt Dec 19, 2024
d9b114d
all tests snapping
jasonkuhrt Dec 19, 2024
728af1f
clean
jasonkuhrt Dec 19, 2024
8cf2893
no ansi
jasonkuhrt Dec 19, 2024
764fb20
first pass of json output
jasonkuhrt Dec 19, 2024
64d60d8
json error output
jasonkuhrt Dec 19, 2024
028cfde
more json error output
jasonkuhrt Dec 19, 2024
4fb7f07
simplify
jasonkuhrt Dec 19, 2024
07fa446
optional
jasonkuhrt Dec 19, 2024
5d62044
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 19, 2024
a503c12
no stacks
jasonkuhrt Dec 19, 2024
35e299e
type failure or success
jasonkuhrt Dec 19, 2024
fd1a85c
no __typename
jasonkuhrt Dec 19, 2024
c35833d
Merge branch 'main' into feat/cli-json-flag
jasonkuhrt Dec 19, 2024
07b9f97
encode type field
jasonkuhrt Dec 19, 2024
5049eb3
simplify test
jasonkuhrt Dec 19, 2024
b774dcf
try fix
jasonkuhrt Dec 19, 2024
b3b63d2
try fix
jasonkuhrt Dec 20, 2024
f7e3ef0
reduce methods
jasonkuhrt Dec 20, 2024
5444780
unused
jasonkuhrt Dec 20, 2024
af41791
try again
jasonkuhrt Dec 20, 2024
48973fb
try again
jasonkuhrt Dec 20, 2024
f1f6b9f
try one more thing
jasonkuhrt Dec 20, 2024
7943697
no parameters stuff
jasonkuhrt Dec 20, 2024
f6b12a4
format
jasonkuhrt Dec 20, 2024
c7c629e
try quick cli tests in ci
jasonkuhrt Dec 20, 2024
1cd5734
try ci run again
jasonkuhrt Dec 20, 2024
ada91d0
log settings
jasonkuhrt Dec 20, 2024
ade8ad3
pnpm pach fml
jasonkuhrt Dec 20, 2024
ad3024b
repatch
jasonkuhrt Dec 20, 2024
1f2f2eb
repatch
jasonkuhrt Dec 20, 2024
c8dbfaf
repatch
jasonkuhrt Dec 20, 2024
ed962e7
repatch
jasonkuhrt Dec 20, 2024
3d6b2e7
repatch
jasonkuhrt Dec 20, 2024
ae88819
repatch
jasonkuhrt Dec 20, 2024
66d174c
repatch
jasonkuhrt Dec 20, 2024
d2bfa72
more debug
jasonkuhrt Dec 20, 2024
dae187d
repatch
jasonkuhrt Dec 20, 2024
6663144
repatch
jasonkuhrt Dec 20, 2024
45362ae
found it?
jasonkuhrt Dec 20, 2024
71d1bd0
restore
jasonkuhrt Dec 20, 2024
bda183b
restore
jasonkuhrt Dec 20, 2024
33e5025
lint
jasonkuhrt Dec 20, 2024
aaf34ac
update vitest for no flicker watch mode
jasonkuhrt Dec 20, 2024
2457c33
restore old patch
jasonkuhrt Dec 20, 2024
c5be266
rename types
jasonkuhrt Dec 21, 2024
0b7aff4
lockfile
jasonkuhrt Dec 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
["cn\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"],
["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
]
],
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
jasonkuhrt marked this conversation as resolved.
Show resolved Hide resolved
}
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Welcome

> [!IMPORTANT]
>
> This guide extends the
> [core Guild contributing guide](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md).
> If you haven't read it yet or recently (e.g. past year), please read it first.

## Setup

1. `corepack enable`
2. `pnpm install`
3. `pnpm build:libraries`
4. `pnpm build:services`
4. `pnpm build`
2 changes: 1 addition & 1 deletion packages/libraries/apollo/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.36.2';
export const version = '0.36.3';
6 changes: 2 additions & 4 deletions packages/libraries/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ A CLI util to manage and control your Hive.
If you are running a JavaScript/NodeJS project, you can install Hive CLI from the `npm` registry:

```
pnpm install -D @graphql-hive/cli
yarn add -D @graphql-hive/cli
npm install -D @graphql-hive/cli
npm add -D @graphql-hive/cli
```

> We recommend installing Hive CLI as part of your project, under `devDependencies`, instead of
> [!NOTE] We recommend installing Hive CLI as part of your project, under `devDependencies`, instead of
> using a global installation.

### Binary
Expand Down
71 changes: 60 additions & 11 deletions packages/libraries/cli/src/base-command.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import colors from 'colors';
import { print, type GraphQLError } from 'graphql';
import type { ExecutionResult } from 'graphql';
import { z, ZodUnion } from 'zod';

Check failure on line 4 in packages/libraries/cli/src/base-command.ts

View workflow job for this annotation

GitHub Actions / code-style / eslint-and-prettier

'ZodUnion' is defined but never used. Allowed unused vars must match /^_/u
import { http } from '@graphql-hive/core';
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
import { Command, Errors, Flags, Interfaces } from '@oclif/core';
import { PrettyPrintableError } from '@oclif/core/lib/interfaces';

Check failure on line 8 in packages/libraries/cli/src/base-command.ts

View workflow job for this annotation

GitHub Actions / code-style / eslint-and-prettier

'PrettyPrintableError' is defined but never used. Allowed unused vars must match /^_/u
import { Config, GetConfigurationValueType, ValidConfigurationKeys } from './helpers/config';

export type Flags<T extends typeof Command> = Interfaces.InferredFlags<
(typeof BaseCommand)['baseFlags'] & T['flags']
>;
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
export default abstract class BaseCommand<$Command extends typeof Command> extends Command {
jasonkuhrt marked this conversation as resolved.
Show resolved Hide resolved
public static enableJsonFlag = true;

type OmitNever<T> = { [K in keyof T as T[K] extends never ? never : K]: T[K] };
/**
* The data type returned by this command when successfully executed.
*
* Used by the {@link BaseCommand.successData} method.
*/
public static successDataSchema: OptionalSuccessSchema = undefined;

/**
* Whether to validate the data returned by the {@link BaseCommand.successData} method.
*
* @defaultValue `true`
*/
public successDataValidateEnabled: boolean = true;

export default abstract class BaseCommand<T extends typeof Command> extends Command {
protected _userConfig: Config | undefined;

static baseFlags = {
Expand All @@ -23,8 +34,9 @@
}),
};

protected flags!: Flags<T>;
protected args!: Args<T>;
protected flags!: Flags<$Command>;

protected args!: Args<$Command>;

protected get userConfig(): Config {
if (!this._userConfig) {
Expand All @@ -33,7 +45,7 @@
return this._userConfig!;
}

public async init(): Promise<void> {
async init(): Promise<void> {
await super.init();

this._userConfig = new Config({
Expand All @@ -48,8 +60,22 @@
args: this.ctor.args,
strict: this.ctor.strict,
});
this.flags = flags as Flags<T>;
this.args = args as Args<T>;
this.flags = flags as Flags<$Command>;
this.args = args as Args<$Command>;
}

/**
* Helper function that accepts the type of this command's {@link BaseCommand.successDataSchema}.
*
* If {@link BaseCommand.successDataValidateEnabled} is `true`, the data will be runtime-validated too.
* Otherwise this is just an identity function, convenient for static type checking.
*/
successData<$Data extends InferConstraintSuccessData<$Command>>(data: $Data): $Data {
// this['successDataSchema']
// TODO apply the zod schema for runtime validation. This would guarantee that
// only valid data is ever returned. If the validation fails, we should throw an oclif cli error or whatever
// and maybe also attempt to send some telemetry data about the error so that our team can fix the issue.
return data;
}

success(...args: any[]) {
Expand Down Expand Up @@ -304,6 +330,29 @@
}
}

export type Flags<T extends typeof Command> = Interfaces.InferredFlags<
(typeof BaseCommand)['baseFlags'] & T['flags']
>;

export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;

type OmitNever<T> = { [K in keyof T as T[K] extends never ? never : K]: T[K] };

type InferConstraintSuccessData<$CommandClass extends typeof Command> =
'successDataSchema' extends keyof $CommandClass
? $CommandClass['successDataSchema'] extends SuccessSchema
? z.infer<$CommandClass['successDataSchema']>
: 'Error: Missing `static successDataSchema = ...` on your command.'
: 'Error: Missing `static successDataSchema = ...` on your command.';

type OptionalSuccessSchema = undefined | SuccessSchema;

type SuccessSchema =
| z.SomeZodObject
| z.ZodUnion<[z.SomeZodObject, z.SomeZodObject]>
| z.ZodUnion<[z.SomeZodObject, z.SomeZodObject, z.SomeZodObject]>
| z.ZodUnion<[z.SomeZodObject, z.SomeZodObject, z.SomeZodObject, z.SomeZodObject]>;

function isClientError(error: Error): error is ClientError {
return error instanceof ClientError;
}
21 changes: 20 additions & 1 deletion packages/libraries/cli/src/commands/introspect.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { writeFileSync } from 'node:fs';
import { extname, resolve } from 'node:path';
import { buildSchema, GraphQLError, introspectionFromSchema } from 'graphql';
import { z } from 'zod';
import { Args, Flags } from '@oclif/core';
import Command from '../base-command';
import { loadSchema } from '../helpers/schema';

export default class Introspect extends Command<typeof Introspect> {
static successDataSchema = z.union([
z.object({
type: z.literal('file'),
path: z.string(),
}),
z.object({
type: z.literal('stdout'),
schema: z.string(),
}),
]);

static description = 'introspects a GraphQL Schema';
static flags = {
write: Flags.string({
Expand Down Expand Up @@ -63,7 +75,10 @@ export default class Introspect extends Command<typeof Introspect> {

if (!flags.write) {
this.log(schema);
return;
return this.successData({
type: 'stdout',
schema,
});
}

if (flags.write) {
Expand Down Expand Up @@ -94,6 +109,10 @@ export default class Introspect extends Command<typeof Introspect> {
}

this.success(`Saved to ${filepath}`);
return this.successData({
type: 'file',
path: filepath,
});
}
}
}
26 changes: 26 additions & 0 deletions packages/libraries/cli/src/commands/whoami.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import colors from 'colors';
import { z } from 'zod';
import { Flags } from '@oclif/core';
import Command from '../base-command';
import { graphql } from '../gql';
Expand Down Expand Up @@ -33,6 +34,18 @@
`);

export default class WhoAmI extends Command<typeof WhoAmI> {
static successDataSchema = z.object({
tokenName: z.string(),
organization: z.string(),
project: z.string(),
target: z.string(),
authorization: z.object({
schema: z.object({
publish: z.boolean(),
check: z.boolean(),
}),
}),
});
static description = 'shows information about the current token';
static flags = {
'registry.endpoint': Flags.string({
Expand Down Expand Up @@ -109,7 +122,20 @@
});

this.log(print());

return this.successData({
tokenName: tokenInfo.token.name,
organization: organization.slug,
project: project.slug,
target: target.slug,
authorization: {
schema: {
publish: tokenInfo.canPublishSchema,
check: tokenInfo.canCheckSchema,
},
},
});
} else if (result.tokenInfo.__typename === 'TokenNotFoundError') {

Check failure on line 138 in packages/libraries/cli/src/commands/whoami.ts

View workflow job for this annotation

GitHub Actions / code-style / eslint-and-prettier

Unnecessary 'else' after 'return'
this.error(`Token not found. Reason: ${result.tokenInfo.message}`, {
exit: 0,
suggestions: [`How to create a token? https://docs.graphql-hive.com/features/tokens`],
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion packages/libraries/envelop/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.33.10';
export const version = '0.33.11';
2 changes: 1 addition & 1 deletion packages/libraries/yoga/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.39.0';
export const version = '0.39.1';
Loading