Skip to content

LSP Rewrite Step 2: refactor for @graphql-tools #3556

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

Draft
wants to merge 49 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
65bcc4d
test after coverage for recent features/changes 😬
acao Jan 27, 2024
54658f8
fix schema file cacheing, cache by default
acao Jan 27, 2024
2686b3f
more cleanup, glob if present
acao Jan 27, 2024
9d37093
begin seperating out specs from unit tests
acao Jan 27, 2024
283561e
more unit coverage
acao Jan 27, 2024
8737a89
more unit coverage
acao Jan 27, 2024
d83a7bf
spelling error
acao Jan 27, 2024
a9d0491
test empty cases
acao Jan 28, 2024
d4ede8e
config error handling
acao Feb 1, 2024
7da3b6d
add integration spec coverage for cacheing the schema file!
acao Feb 4, 2024
5ce0741
really exciting spec coverage
acao Feb 4, 2024
12e94f5
more improvements and coverage
acao Feb 4, 2024
0243ae2
refactor the whole integration suite
acao Feb 5, 2024
ee087b2
get set up for a local schema lifecycle
acao Feb 11, 2024
fc04f7c
position job correctly
acao Feb 11, 2024
671df2f
avoid changed schema for now
acao Feb 12, 2024
432e5b9
expose a slightly changed dev server
acao Feb 12, 2024
f74a280
tests not running seperately
acao Feb 12, 2024
b7f905c
fix workflow deps
acao Feb 16, 2024
b5bd0a4
fix eslint
acao Feb 16, 2024
935cb6f
attempt to fix CI only test bug
acao Feb 16, 2024
36242cd
codecov config
acao Feb 16, 2024
8ab3c70
revert test schema change
acao Feb 16, 2024
8913d80
revert config change, restore coverage
acao Feb 18, 2024
bb98420
revert config change, restore coverage
acao Feb 18, 2024
98efb74
cleanup
acao Feb 18, 2024
1a99235
migrate over the wire tests to use local schema instance
acao Feb 18, 2024
7611f2c
test script
acao Feb 18, 2024
c35a156
try to fix this test
acao Feb 18, 2024
128ac4a
fix a few more things related to type cacheing
acao Feb 18, 2024
1910049
fix embedded fragment definition offset bug!
acao Feb 20, 2024
f025e72
spelling bug
acao Feb 20, 2024
0395e64
cleanup
acao Feb 20, 2024
ba7fd81
fix: cleanup, potentially fix project name cache key bug?
acao Feb 27, 2024
0b7115b
fix: delete the unused method
acao Feb 27, 2024
833a727
add comments
acao Feb 27, 2024
525c569
cleanup
acao Feb 27, 2024
cf4536b
feat: lazy initialization on watched file changes
acao Mar 2, 2024
867714c
fix even MORE bugs
acao Mar 3, 2024
9b6304c
fix object field completion, add tests for the missing cases
acao Mar 3, 2024
c1053fd
fix log level, keep things relevant
acao Mar 3, 2024
0036c7f
fix: logger tests, simple re-instantiation on settings change
acao Mar 3, 2024
2d1cbbb
add changeset
acao Mar 3, 2024
479203c
fix: env, timeout
acao Mar 8, 2024
61d91a7
docs: pluck some docs improvements from the next phase
acao Mar 17, 2024
18ab496
fix: refactor for graphql-tools
acao Mar 12, 2024
4216bd6
fix: further ts refinements
acao Mar 17, 2024
310048b
fix: more cleanup
acao Mar 17, 2024
7839f79
only 3 spec errors left!
acao Mar 17, 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
Prev Previous commit
Next Next commit
add integration spec coverage for cacheing the schema file!
  • Loading branch information
acao committed Mar 8, 2024
commit 7da3b6d6c52ba65215b808b79b84182fd1b6571a
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*
*/

import mkdirp from 'mkdirp';
import { readFileSync, existsSync, writeFileSync } from 'node:fs';
import { readFileSync, existsSync, writeFileSync, mkdirSync } from 'node:fs';
import { readFile, writeFile } from 'node:fs/promises';
import * as path from 'node:path';
import { URI } from 'vscode-uri';
Expand Down Expand Up @@ -147,7 +146,7 @@ export class MessageProcessor {
}

if (!existsSync(this._tmpDirBase)) {
void mkdirp(this._tmpDirBase);
mkdirSync(this._tmpDirBase);
}
}
get connection(): Connection {
Expand Down Expand Up @@ -972,7 +971,9 @@ export class MessageProcessor {
const basePath = path.join(this._tmpDirBase, workspaceName);
let projectTmpPath = path.join(basePath, 'projects', project.name);
if (!existsSync(projectTmpPath)) {
void mkdirp(projectTmpPath);
mkdirSync(projectTmpPath, {
recursive: true,
});
}
if (appendPath) {
projectTmpPath = path.join(projectTmpPath, appendPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ jest.mock('../Logger');
import { NoopLogger } from '../Logger';
import mockfs from 'mock-fs';
import { join } from 'node:path';
import { MockLogger, MockProject } from './__utils__/MockProject';
import { readFileSync, readdirSync } from 'node:fs';

describe('MessageProcessor with no config', () => {
let messageProcessor: MessageProcessor;
Expand Down Expand Up @@ -165,3 +167,69 @@ describe('MessageProcessor with no config', () => {
// );
});
});

describe.only('project with simple config', () => {
afterEach(() => {
mockfs.restore();
});
it('caches files and schema with .graphql file config', async () => {
const project = new MockProject({
files: [
['graphql.config.json', '{ "schema": "./schema.graphql" }'],
[
'schema.graphql',
'type Query { foo: Foo }\n\ntype Foo { bar: String }',
],
['query.graphql', 'query { bar }'],
],
});
await project.lsp.handleInitializeRequest({
rootPath: project.root,
rootUri: project.root,
capabilities: {},
processId: 200,
workspaceFolders: null,
});
await project.lsp.handleDidOpenOrSaveNotification({
textDocument: { uri: project.uri('query.graphql') },
});
expect(project.lsp._logger.error).not.toHaveBeenCalled();
// console.log(project.lsp._graphQLCache.getSchema('schema.graphql'));
expect(await project.lsp._graphQLCache.getSchema()).toBeDefined();
expect(Array.from(project.lsp._textDocumentCache)).toEqual([]);
});
it('caches files and schema with a URL config', async () => {
const project = new MockProject({
files: [
[
'graphql.config.json',
'{ "schema": "https://rickandmortyapi.com/graphql" }',
],
[
'schema.graphql',
'type Query { foo: Foo }\n\ntype Foo { bar: String }',
],
['query.graphql', 'query { bar }'],
],
});
await project.lsp.handleInitializeRequest({
rootPath: project.root,
rootUri: project.root,
capabilities: {},
processId: 200,
workspaceFolders: null,
});
await project.lsp.handleDidOpenOrSaveNotification({
textDocument: { uri: project.uri('query.graphql') },
});
expect(project.lsp._logger.error).not.toHaveBeenCalled();
// console.log(project.lsp._graphQLCache.getSchema('schema.graphql'));
expect(await project.lsp._graphQLCache.getSchema()).toBeDefined();
const file = readFileSync(
join(
'/tmp/graphql-language-service/test/projects/default/generated-schema.graphql',
),
);
expect(file.toString('utf-8').length).toBeGreaterThan(0);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import mockfs from 'mock-fs';
import { MessageProcessor } from '../../MessageProcessor';
import { Logger as VSCodeLogger } from 'vscode-jsonrpc';
import { URI } from 'vscode-uri';

export class MockLogger implements VSCodeLogger {
error = jest.fn();
warn = jest.fn();
info = jest.fn();
log = jest.fn();
}

const defaultMocks = {
'node_modules/parse-json': mockfs.load('node_modules/parse-json'),
'node_modules/error-ex': mockfs.load('node_modules/error-ex'),
'node_modules/is-arrayish': mockfs.load('node_modules/is-arrayish'),
'node_modules/json-parse-even-better-errors': mockfs.load(
'node_modules/json-parse-even-better-errors',
),
'node_modules/lines-and-columns': mockfs.load(
'node_modules/lines-and-columns',
),
'node_modules/@babel/code-frame': mockfs.load(
'node_modules/@babel/code-frame',
),
'node_modules/@babel/highlight': mockfs.load('node_modules/@babel/highlight'),
'/tmp/graphql-language-service/test/projects': mockfs.directory({
mode: 0o777,
}),
};

export class MockProject {
private root: string;
private messageProcessor: MessageProcessor;
constructor({
files = [],
root = '/tmp/test',
settings,
}: {
files: [filename: string, text: string][];
root?: string;
settings?: [name: string, vale: any][];
}) {
this.root = root;
const mockFiles = { ...defaultMocks };
files.map(([filename, text]) => {
mockFiles[this.filePath(filename)] = text;
});
mockfs(mockFiles);
this.messageProcessor = new MessageProcessor({
connection: {
get workspace() {
return {
async getConfiguration() {
return settings;
},
};
},
},
logger: new MockLogger(),
loadConfigOptions: { rootDir: root },
});
}
public filePath(filename: string) {
return `${this.root}/${filename}`;
}
public uri(filename: string) {
return URI.file(this.filePath(filename)).toString();
}
changeFile(filename: string, text: string) {
mockfs({
[this.filePath(filename)]: text,
});
}
get lsp() {
return this.messageProcessor;
}
}