Skip to content

Commit cd0061e

Browse files
authored
fix: recursively write tmp directories, write schema async (#1641)
1 parent 6288caa commit cd0061e

File tree

3 files changed

+64
-17
lines changed

3 files changed

+64
-17
lines changed

packages/graphql-language-service-server/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
],
2525
"main": "dist/index.js",
2626
"module": "esm/index.js",
27-
"typings": "dist/index.d.ts",
27+
"typings": "esm/index.d.ts",
2828
"peerDependencies": {
2929
"graphql": "^14.0.0 || ^15.0.0"
3030
},
@@ -36,9 +36,11 @@
3636
"graphql-language-service-utils": "^2.4.1",
3737
"nullthrows": "^1.0.0",
3838
"vscode-jsonrpc": "^5.0.1",
39-
"vscode-languageserver": "^6.1.1"
39+
"vscode-languageserver": "^6.1.1",
40+
"mkdirp": "^1.0.4"
4041
},
4142
"devDependencies": {
42-
"cross-env": "^7.0.2"
43+
"cross-env": "^7.0.2",
44+
"@types/mkdirp": "^1.0.1"
4345
}
4446
}

packages/graphql-language-service-server/src/MessageProcessor.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*
88
*/
9-
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
9+
10+
import mkdirp from 'mkdirp';
11+
import { readFileSync, existsSync, writeFileSync, writeFile } from 'fs';
1012
import { URL } from 'url';
1113
import * as path from 'path';
1214
import {
@@ -62,6 +64,9 @@ import { printSchema } from 'graphql';
6264
import { tmpdir } from 'os';
6365
import { GraphQLExtensionDeclaration } from 'graphql-config';
6466
import type { LoadConfigOptions } from './types';
67+
import { promisify } from 'util';
68+
69+
const writeFileAsync = promisify(writeFile);
6570

6671
type CachedDocumentType = {
6772
version: number;
@@ -122,7 +127,7 @@ export class MessageProcessor {
122127
}
123128

124129
if (!existsSync(this._tmpDirBase)) {
125-
mkdirSync(this._tmpDirBase);
130+
mkdirp(this._tmpDirBase);
126131
}
127132
}
128133

@@ -731,17 +736,17 @@ export class MessageProcessor {
731736
const baseDir = this._graphQLCache.getGraphQLConfig().dirpath;
732737
const baseName = path.basename(baseDir);
733738
const basePath = path.join(this._tmpDirBase, baseName);
734-
if (!existsSync(basePath)) {
735-
mkdirSync(basePath);
736-
mkdirSync(path.join(basePath, 'projects'));
737-
}
738-
const projectTmpPath = path.resolve(
739-
path.join(basePath, 'projects', project.name, appendPath || ''),
740-
);
739+
let projectTmpPath = path.join(basePath, 'projects', project.name);
741740
if (!existsSync(projectTmpPath)) {
742-
mkdirSync(projectTmpPath);
741+
mkdirp(projectTmpPath);
743742
}
744-
return prependWithProtocol ? 'file://' + projectTmpPath : projectTmpPath;
743+
if (appendPath) {
744+
projectTmpPath = path.join(projectTmpPath, appendPath);
745+
}
746+
if (prependWithProtocol) {
747+
projectTmpPath = `file://${projectTmpPath}`;
748+
}
749+
return projectTmpPath;
745750
}
746751
async _cacheSchemaFilesForProject(project: GraphQLProjectConfig) {
747752
const schema = project?.schema;
@@ -800,7 +805,8 @@ export class MessageProcessor {
800805
const cachedSchemaDoc = this._getCachedDocument(uri);
801806

802807
if (!cachedSchemaDoc) {
803-
writeFileSync(fsPath, schemaText, {
808+
console.log({ fsPath });
809+
await writeFileAsync(fsPath, schemaText, {
804810
encoding: 'utf-8',
805811
});
806812
await this._cacheSchemaText(uri, schemaText, 1);

yarn.lock

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,6 +3964,13 @@
39643964
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
39653965
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
39663966

3967+
"@types/mkdirp@^1.0.1":
3968+
version "1.0.1"
3969+
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-1.0.1.tgz#0930b948914a78587de35458b86c907b6e98bbf6"
3970+
integrity sha512-HkGSK7CGAXncr8Qn/0VqNtExEE+PHMWb+qlR1faHMao7ng6P3tAaoWWBMdva0gL5h4zprjIO89GJOLXsMcDm1Q==
3971+
dependencies:
3972+
"@types/node" "*"
3973+
39673974
39683975
version "5.2.7"
39693976
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
@@ -10257,7 +10264,7 @@ grapheme-breaker@^0.3.2:
1025710264
unicode-trie "^0.3.1"
1025810265

1025910266
"graphiql@file:packages/graphiql":
10260-
version "2.0.0-alpha.1"
10267+
version "2.0.0-alpha.2"
1026110268
dependencies:
1026210269
"@emotion/core" "^10.0.28"
1026310270
"@mdx-js/react" "^1.5.2"
@@ -10270,7 +10277,7 @@ grapheme-breaker@^0.3.2:
1027010277
i18next-browser-languagedetector "^4.1.1"
1027110278
markdown-it "^10.0.0"
1027210279
monaco-editor "^0.20.0"
10273-
monaco-graphql "^0.3.0"
10280+
monaco-graphql "^0.3.1-alpha.0"
1027410281
react-i18next "^11.4.0"
1027510282
theme-ui "^0.3.1"
1027610283

@@ -10290,6 +10297,30 @@ graphql-config@^3.0.2, graphql-config@^3.0.3:
1029010297
string-env-interpolation "1.0.1"
1029110298
tslib "^2.0.0"
1029210299

10300+
graphql-language-service-interface@^2.4.0-alpha.7, graphql-language-service-interface@^2.4.1:
10301+
version "2.4.1"
10302+
resolved "https://registry.yarnpkg.com/graphql-language-service-interface/-/graphql-language-service-interface-2.4.1.tgz#62aca7880469d0f9079aec22a9b297cf78994f52"
10303+
integrity sha512-cKT0ia7xNVpkLlI0vuwxVpPVIXwy02ah4I+N6s4mxFKVgo+lPlX9r933EWX6t1P1vzGJmNf+dip2dK3gHg2bBw==
10304+
dependencies:
10305+
graphql-language-service-parser "^1.6.1"
10306+
graphql-language-service-types "^1.6.1"
10307+
graphql-language-service-utils "^2.4.1"
10308+
vscode-languageserver-types "^3.15.1"
10309+
10310+
graphql-language-service-server@^2.4.0-alpha.7:
10311+
version "2.4.1"
10312+
resolved "https://registry.yarnpkg.com/graphql-language-service-server/-/graphql-language-service-server-2.4.1.tgz#1baea9095e92109dd51beb2126b5053664039ee2"
10313+
integrity sha512-fA4ZBB0hfERwCDA9p49Z325Zm5kafyW8PyAeDhoJ3tdSiwY8MRzK52d0HLUx6+AZmEVyYOkVjKhXeD4V6IV6Sg==
10314+
dependencies:
10315+
"@babel/parser" "^7.9.0"
10316+
glob "^7.1.2"
10317+
graphql-config "^3.0.2"
10318+
graphql-language-service "^3.0.1"
10319+
graphql-language-service-utils "^2.4.1"
10320+
nullthrows "^1.0.0"
10321+
vscode-jsonrpc "^5.0.1"
10322+
vscode-languageserver "^6.1.1"
10323+
1029310324
graphql-language-service@^2.4.0-alpha.7:
1029410325
version "2.4.0-alpha.7"
1029510326
resolved "https://registry.yarnpkg.com/graphql-language-service/-/graphql-language-service-2.4.0-alpha.7.tgz#cd7eef87f7a89426c30d34534e6206e2d78d42ad"
@@ -10301,6 +10332,14 @@ graphql-language-service@^2.4.0-alpha.7:
1030110332
graphql-language-service-utils "^2.4.0-alpha.6"
1030210333
yargs "^15.3.1"
1030310334

10335+
graphql-language-service@^3.0.1:
10336+
version "3.0.1"
10337+
resolved "https://registry.yarnpkg.com/graphql-language-service/-/graphql-language-service-3.0.1.tgz#1253a5cb3affe7c272bbcfadd89c1f0eb78ece2f"
10338+
integrity sha512-79EGvEECgn1HIX0VBh3pXqetqgdtRHfkNTws0mcirCtFowwqt+QZAKKBNKVLY2vMya9wNVLDWUvzl0FF5wbBTA==
10339+
dependencies:
10340+
graphql-language-service-interface "^2.4.1"
10341+
graphql-language-service-types "^1.6.1"
10342+
1030410343
1030510344
version "14.6.0"
1030610345
resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.6.0.tgz#57822297111e874ea12f5cd4419616930cd83e49"

0 commit comments

Comments
 (0)