Skip to content

Commit

Permalink
fix: recursively write tmp directories, write schema async (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Aug 12, 2020
1 parent 6288caa commit cd0061e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 17 deletions.
8 changes: 5 additions & 3 deletions packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"main": "dist/index.js",
"module": "esm/index.js",
"typings": "dist/index.d.ts",
"typings": "esm/index.d.ts",
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0"
},
Expand All @@ -36,9 +36,11 @@
"graphql-language-service-utils": "^2.4.1",
"nullthrows": "^1.0.0",
"vscode-jsonrpc": "^5.0.1",
"vscode-languageserver": "^6.1.1"
"vscode-languageserver": "^6.1.1",
"mkdirp": "^1.0.4"
},
"devDependencies": {
"cross-env": "^7.0.2"
"cross-env": "^7.0.2",
"@types/mkdirp": "^1.0.1"
}
}
30 changes: 18 additions & 12 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* LICENSE file in the root directory of this source tree.
*
*/
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';

import mkdirp from 'mkdirp';
import { readFileSync, existsSync, writeFileSync, writeFile } from 'fs';
import { URL } from 'url';
import * as path from 'path';
import {
Expand Down Expand Up @@ -62,6 +64,9 @@ import { printSchema } from 'graphql';
import { tmpdir } from 'os';
import { GraphQLExtensionDeclaration } from 'graphql-config';
import type { LoadConfigOptions } from './types';
import { promisify } from 'util';

const writeFileAsync = promisify(writeFile);

type CachedDocumentType = {
version: number;
Expand Down Expand Up @@ -122,7 +127,7 @@ export class MessageProcessor {
}

if (!existsSync(this._tmpDirBase)) {
mkdirSync(this._tmpDirBase);
mkdirp(this._tmpDirBase);
}
}

Expand Down Expand Up @@ -731,17 +736,17 @@ export class MessageProcessor {
const baseDir = this._graphQLCache.getGraphQLConfig().dirpath;
const baseName = path.basename(baseDir);
const basePath = path.join(this._tmpDirBase, baseName);
if (!existsSync(basePath)) {
mkdirSync(basePath);
mkdirSync(path.join(basePath, 'projects'));
}
const projectTmpPath = path.resolve(
path.join(basePath, 'projects', project.name, appendPath || ''),
);
let projectTmpPath = path.join(basePath, 'projects', project.name);
if (!existsSync(projectTmpPath)) {
mkdirSync(projectTmpPath);
mkdirp(projectTmpPath);
}
return prependWithProtocol ? 'file://' + projectTmpPath : projectTmpPath;
if (appendPath) {
projectTmpPath = path.join(projectTmpPath, appendPath);
}
if (prependWithProtocol) {
projectTmpPath = `file://${projectTmpPath}`;
}
return projectTmpPath;
}
async _cacheSchemaFilesForProject(project: GraphQLProjectConfig) {
const schema = project?.schema;
Expand Down Expand Up @@ -800,7 +805,8 @@ export class MessageProcessor {
const cachedSchemaDoc = this._getCachedDocument(uri);

if (!cachedSchemaDoc) {
writeFileSync(fsPath, schemaText, {
console.log({ fsPath });
await writeFileAsync(fsPath, schemaText, {
encoding: 'utf-8',
});
await this._cacheSchemaText(uri, schemaText, 1);
Expand Down
43 changes: 41 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3964,6 +3964,13 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/mkdirp@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-1.0.1.tgz#0930b948914a78587de35458b86c907b6e98bbf6"
integrity sha512-HkGSK7CGAXncr8Qn/0VqNtExEE+PHMWb+qlR1faHMao7ng6P3tAaoWWBMdva0gL5h4zprjIO89GJOLXsMcDm1Q==
dependencies:
"@types/node" "*"

"@types/mocha@5.2.7":
version "5.2.7"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
Expand Down Expand Up @@ -10257,7 +10264,7 @@ grapheme-breaker@^0.3.2:
unicode-trie "^0.3.1"

"graphiql@file:packages/graphiql":
version "2.0.0-alpha.1"
version "2.0.0-alpha.2"
dependencies:
"@emotion/core" "^10.0.28"
"@mdx-js/react" "^1.5.2"
Expand All @@ -10270,7 +10277,7 @@ grapheme-breaker@^0.3.2:
i18next-browser-languagedetector "^4.1.1"
markdown-it "^10.0.0"
monaco-editor "^0.20.0"
monaco-graphql "^0.3.0"
monaco-graphql "^0.3.1-alpha.0"
react-i18next "^11.4.0"
theme-ui "^0.3.1"

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

graphql-language-service-interface@^2.4.0-alpha.7, graphql-language-service-interface@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/graphql-language-service-interface/-/graphql-language-service-interface-2.4.1.tgz#62aca7880469d0f9079aec22a9b297cf78994f52"
integrity sha512-cKT0ia7xNVpkLlI0vuwxVpPVIXwy02ah4I+N6s4mxFKVgo+lPlX9r933EWX6t1P1vzGJmNf+dip2dK3gHg2bBw==
dependencies:
graphql-language-service-parser "^1.6.1"
graphql-language-service-types "^1.6.1"
graphql-language-service-utils "^2.4.1"
vscode-languageserver-types "^3.15.1"

graphql-language-service-server@^2.4.0-alpha.7:
version "2.4.1"
resolved "https://registry.yarnpkg.com/graphql-language-service-server/-/graphql-language-service-server-2.4.1.tgz#1baea9095e92109dd51beb2126b5053664039ee2"
integrity sha512-fA4ZBB0hfERwCDA9p49Z325Zm5kafyW8PyAeDhoJ3tdSiwY8MRzK52d0HLUx6+AZmEVyYOkVjKhXeD4V6IV6Sg==
dependencies:
"@babel/parser" "^7.9.0"
glob "^7.1.2"
graphql-config "^3.0.2"
graphql-language-service "^3.0.1"
graphql-language-service-utils "^2.4.1"
nullthrows "^1.0.0"
vscode-jsonrpc "^5.0.1"
vscode-languageserver "^6.1.1"

graphql-language-service@^2.4.0-alpha.7:
version "2.4.0-alpha.7"
resolved "https://registry.yarnpkg.com/graphql-language-service/-/graphql-language-service-2.4.0-alpha.7.tgz#cd7eef87f7a89426c30d34534e6206e2d78d42ad"
Expand All @@ -10301,6 +10332,14 @@ graphql-language-service@^2.4.0-alpha.7:
graphql-language-service-utils "^2.4.0-alpha.6"
yargs "^15.3.1"

graphql-language-service@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/graphql-language-service/-/graphql-language-service-3.0.1.tgz#1253a5cb3affe7c272bbcfadd89c1f0eb78ece2f"
integrity sha512-79EGvEECgn1HIX0VBh3pXqetqgdtRHfkNTws0mcirCtFowwqt+QZAKKBNKVLY2vMya9wNVLDWUvzl0FF5wbBTA==
dependencies:
graphql-language-service-interface "^2.4.1"
graphql-language-service-types "^1.6.1"

graphql@14.6.0:
version "14.6.0"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.6.0.tgz#57822297111e874ea12f5cd4419616930cd83e49"
Expand Down

0 comments on commit cd0061e

Please sign in to comment.