graphql-language-service-cli 4.0.0-rc.2 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/cli.js +6 -2
- package/dist/cli.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/index.test.ts +79 -6
- package/src/cli.ts +6 -2
package/README.md
CHANGED
|
@@ -40,7 +40,8 @@ the server.
|
|
|
40
40
|
**DROPPED**: GraphQL Language Service no longer depends on
|
|
41
41
|
[Watchman](https://facebook.github.io/watchman/)
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Install this package with npm or yarn. Its runtime requirements also depend on
|
|
44
|
+
the selected GraphQL version and language-service dependencies.
|
|
44
45
|
|
|
45
46
|
### Installation
|
|
46
47
|
|
package/dist/cli.js
CHANGED
|
@@ -4,9 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const yargs_1 = __importDefault(require("yargs"));
|
|
7
|
+
const helpers_1 = require("yargs/helpers");
|
|
7
8
|
const client_1 = __importDefault(require("./client"));
|
|
9
|
+
const package_json_1 = require("../package.json");
|
|
8
10
|
const graphql_language_service_server_1 = require("graphql-language-service-server");
|
|
9
|
-
const
|
|
11
|
+
const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
12
|
+
.version(package_json_1.version)
|
|
10
13
|
.usage('GraphQL Language Service Command-Line Interface.\n' +
|
|
11
14
|
'Usage: graphql-lsp <command> <file>\n' +
|
|
12
15
|
' [-h | --help]\n' +
|
|
@@ -80,7 +83,8 @@ const { argv } = yargs_1.default
|
|
|
80
83
|
alias: 'schemaPath',
|
|
81
84
|
describe: 'a path to schema DSL file\n',
|
|
82
85
|
type: 'string',
|
|
83
|
-
})
|
|
86
|
+
})
|
|
87
|
+
.parse();
|
|
84
88
|
const command = argv._.pop();
|
|
85
89
|
if (!command) {
|
|
86
90
|
process.stdout.write('no command supplied');
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AASA,kDAA0B;AAC1B,sDAA8B;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AASA,kDAA0B;AAC1B,2CAAwC;AACxC,sDAA8B;AAC9B,kDAA0C;AAE1C,qFAA8D;AAE9D,MAAM,IAAI,GAAG,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACtC,OAAO,CAAC,sBAAO,CAAC;KAChB,KAAK,CACJ,oDAAoD;IAClD,uCAAuC;IACvC,qBAAqB;IACrB,sCAAsC;IACtC,kCAAkC;IAClC,gCAAgC;IAChC,oCAAoC;IACpC,gCAAgC;IAChC,4BAA4B;IAC5B,2CAA2C,CAC9C;KACA,IAAI,CAAC,GAAG,CAAC;KACT,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC;KAClB,MAAM,EAAE;KACR,iBAAiB,EAAE;KACnB,aAAa,CACZ,CAAC,EACD,qCAAqC;IACnC,uDAAuD,CAC1D;KACA,OAAO,CAAC,QAAQ,EAAE,iCAAiC,CAAC;KACpD,OAAO,CAAC,UAAU,EAAE,qBAAqB,CAAC;KAC1C,OAAO,CAAC,cAAc,EAAE,8BAA8B,CAAC;KACvD,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC;KACjC,MAAM,CAAC,GAAG,EAAE;IACX,KAAK,EAAE,MAAM;IACb,QAAQ,EACN,kDAAkD;QAClD,2CAA2C;QAC3C,wCAAwC;IAC1C,IAAI,EAAE,QAAQ;CACf,CAAC;KACD,MAAM,CAAC,GAAG,EAAE;IACX,KAAK,EAAE,MAAM;IACb,QAAQ,EACN,gDAAgD;QAChD,iDAAiD;IACnD,IAAI,EAAE,QAAQ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M,CAAC,KAAK,CAClB,qDAAqD,GAAG,MAAM,CAAC,KAAK,CAAC,CACtE,CAAC;IAGJ,CAAC,CAAC,CAAC;IAEH,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IAC3B,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,CAAC;IACD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IACrC,CAAC;IAED,IAAA,6CAAW,EAAC,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACjC,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,qDAAqD,GAAG,MAAM,CAAC,KAAK,CAAC,CACtE,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;KAAM,CAAC;IACN,IAAA,gBAAM,EAAC,OAAiB,EAAE,IAA8B,CAAC,CAAC;AAC5D,CAAC;AAGD,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;IAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-language-service-cli",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "An interface for building GraphQL language services for IDEs",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Hyohyeon Jeong <asiandrummer@fb.com>",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"graphql": "^16.11.0 || ^17.0.0"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"
|
|
39
|
-
"graphql-language-service": "^
|
|
40
|
-
"
|
|
41
|
-
"yargs": "^16.2.0"
|
|
38
|
+
"graphql-language-service": "^6.0.1",
|
|
39
|
+
"graphql-language-service-server": "^3.0.1",
|
|
40
|
+
"yargs": "^16.2.2"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
45
|
-
"graphql": "^17.0.2"
|
|
44
|
+
"graphql": "^17.0.2",
|
|
45
|
+
"@types/yargs": "^16.0.11"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.esm.json",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
1
3
|
import { describe, it, expect } from 'vitest';
|
|
2
4
|
/**
|
|
3
5
|
* Copyright (c) 2021 GraphQL Contributors
|
|
@@ -6,12 +8,83 @@ import { describe, it, expect } from 'vitest';
|
|
|
6
8
|
* This source code is licensed under the license found in the
|
|
7
9
|
* LICENSE file in the root directory of this source tree.
|
|
8
10
|
*/
|
|
11
|
+
import packageJSON from '../../package.json' with { type: 'json' };
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const cliPath = fileURLToPath(new URL('../../bin/graphql.js', import.meta.url));
|
|
14
|
+
|
|
15
|
+
function run(...args: string[]) {
|
|
16
|
+
return spawnSync(process.execPath, [cliPath, ...args], {
|
|
17
|
+
encoding: 'utf8',
|
|
18
|
+
timeout: 10_000,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('command-line arguments', { timeout: 15_000 }, () => {
|
|
23
|
+
it('shows commands and options in help', () => {
|
|
24
|
+
const result = run('--help');
|
|
25
|
+
expect(result.status).toBe(0);
|
|
26
|
+
expect(result.stderr).toBe('');
|
|
27
|
+
for (const command of ['server', 'validate', 'autocomplete', 'outline']) {
|
|
28
|
+
expect(result.stdout).toContain(command);
|
|
29
|
+
}
|
|
30
|
+
for (const option of [
|
|
31
|
+
'--configDir',
|
|
32
|
+
'--text',
|
|
33
|
+
'--file',
|
|
34
|
+
'--method',
|
|
35
|
+
'--port',
|
|
36
|
+
]) {
|
|
37
|
+
expect(result.stdout).toContain(option);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('shows the package version', () => {
|
|
42
|
+
const result = run('--version');
|
|
43
|
+
expect(result.status).toBe(0);
|
|
44
|
+
expect(result.stdout.trim()).toBe(packageJSON.version);
|
|
45
|
+
expect(result.stderr).toBe('');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it.each([
|
|
49
|
+
{ args: [], message: 'At least one command is required.' },
|
|
50
|
+
{ args: ['validte'], message: 'Did you mean validate?' }, // cspell:ignore validte
|
|
51
|
+
{ args: ['validate', '--unknown'], message: 'Unknown argument: unknown' },
|
|
52
|
+
])('rejects $args with a useful error', ({ args, message }) => {
|
|
53
|
+
const result = run(...args);
|
|
54
|
+
expect(result.status).toBe(1);
|
|
55
|
+
expect(result.stderr).toContain(message);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('accepts aliases and gives text precedence over the file', () => {
|
|
59
|
+
const result = run(
|
|
60
|
+
'validate',
|
|
61
|
+
'-f',
|
|
62
|
+
'/does/not/exist',
|
|
63
|
+
'-t',
|
|
64
|
+
'{ __typename }',
|
|
65
|
+
);
|
|
66
|
+
expect(result.status).toBe(0);
|
|
67
|
+
expect(result.stdout).toBe('{}');
|
|
68
|
+
expect(result.stderr).toBe('');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('preserves client error output and exit status', () => {
|
|
72
|
+
const result = run(
|
|
73
|
+
'autocomplete',
|
|
74
|
+
'--text',
|
|
75
|
+
'{',
|
|
76
|
+
'--schemaPath',
|
|
77
|
+
'/does/not/exist.graphql',
|
|
78
|
+
);
|
|
79
|
+
expect(result.status).toBe(1);
|
|
80
|
+
expect(result.stderr).toContain('ENOENT');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('passes the selected transport to the server', () => {
|
|
84
|
+
const result = run('server', '--method', 'socket');
|
|
85
|
+
expect(result.status).toBe(1);
|
|
86
|
+
expect(result.stderr).toBe(
|
|
87
|
+
'--port is required to establish socket connection.',
|
|
88
|
+
);
|
|
16
89
|
});
|
|
17
90
|
});
|
package/src/cli.ts
CHANGED
|
@@ -8,11 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import yargs from 'yargs';
|
|
11
|
+
import { hideBin } from 'yargs/helpers';
|
|
11
12
|
import client from './client';
|
|
13
|
+
import { version } from '../package.json';
|
|
12
14
|
|
|
13
15
|
import { startServer } from 'graphql-language-service-server';
|
|
14
16
|
|
|
15
|
-
const
|
|
17
|
+
const argv = yargs(hideBin(process.argv))
|
|
18
|
+
.version(version)
|
|
16
19
|
.usage(
|
|
17
20
|
'GraphQL Language Service Command-Line Interface.\n' +
|
|
18
21
|
'Usage: graphql-lsp <command> <file>\n' +
|
|
@@ -98,7 +101,8 @@ const { argv } = yargs
|
|
|
98
101
|
alias: 'schemaPath',
|
|
99
102
|
describe: 'a path to schema DSL file\n',
|
|
100
103
|
type: 'string',
|
|
101
|
-
})
|
|
104
|
+
})
|
|
105
|
+
.parse();
|
|
102
106
|
|
|
103
107
|
const command = argv._.pop();
|
|
104
108
|
|