Skip to content

Commit

Permalink
fix exec and the dreaded code file loader bug (#3266)
Browse files Browse the repository at this point in the history
* fix exec and the dreaded code file loader bug
* fix: allow passing in additional extensions
* fix: eslint extension bundling externals
  • Loading branch information
acao authored Jun 24, 2023
1 parent ae4ef39 commit 01daed1
Show file tree
Hide file tree
Showing 20 changed files with 681 additions and 407 deletions.
9 changes: 9 additions & 0 deletions .changeset/sixty-grapes-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'graphql-language-service': minor
'graphql-language-service-server': minor
'vscode-graphql-execution': minor
'graphql-language-service-cli': minor
'vscode-graphql': minor
---

Fix code file loader, upgrade graphql-config!
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ coverage/
.nyc_output
dist/
esm/
packages/*/out/
out/
*.vsix
*.tsbuildinfo

Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-graphql-execution"
],
"outFiles": [
"${workspaceFolder}/packages/vscode-graphql-execution/dist/extension.js"
"${workspaceFolder}/packages/vscode-graphql-execution/out/extension.js"
],
"sourceMaps": true,
"preLaunchTask": "watch-vscode-exec"
Expand Down
6 changes: 1 addition & 5 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"addWords": true
}
],
"ignorePaths": [
"**/CHANGELOG.md",
"**/package.json",
"packages/vscode-graphql/esbuild.js"
],
"ignorePaths": ["**/CHANGELOG.md", "**/package.json", "**/esbuild.js"],
"files": ["**/*.{js,cjs,mjs,ts,jsx,tsx,md,mdx,html,json,css,toml,yaml,yml}"]
}
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"build:packages": "yarn tsc",
"build:watch": "yarn tsc --watch",
"watch": "yarn build:watch",
"watch-vscode": "concurrently --raw \"yarn tsc && yarn build:watch\" \"yarn workspace vscode-graphql run compile --watch\"",
"watch-vscode-exec": "yarn build:watch",
"watch-vscode": "yarn workspace vscode-graphql run compile",
"watch-vscode-exec": "yarn workspace vscode-graphql-execution run compile",
"check": "yarn tsc --noEmit",
"cypress-open": "yarn workspace graphiql cypress-open",
"dev-graphiql": "yarn workspace graphiql dev",
Expand Down Expand Up @@ -138,8 +138,5 @@
"typedoc": "^0.19.2",
"typescript": "^4.6.3",
"wsrun": "^5.2.4"
},
"resolutions": {
"graphql-config": "4.3.0"
}
}
9 changes: 6 additions & 3 deletions packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,23 @@
"dependencies": {
"@babel/parser": "^7.21.2",
"@babel/types": "^7.21.2",
"@graphql-tools/load": "^7.5.3",
"@graphql-tools/code-file-loader": "8.0.1",
"@vue/compiler-sfc": "^3.2.41",
"dotenv": "8.2.0",
"fast-glob": "^3.2.7",
"glob": "^7.2.0",
"graphql-config": "4.3.0",
"graphql-config": "5.0.2",
"graphql-language-service": "^5.1.7-alpha.0",
"mkdirp": "^1.0.4",
"node-abort-controller": "^3.0.1",
"nullthrows": "^1.0.0",
"vscode-jsonrpc": "^8.0.1",
"vscode-languageserver": "^8.0.1",
"vscode-languageserver-types": "^3.17.2",
"vscode-uri": "^3.0.2"
"vscode-uri": "^3.0.2",
"svelte2tsx": "^0.6.16",
"svelte": "^4.0.0",
"cosmiconfig-toml-loader": "^1.0.0"
},
"devDependencies": {
"@types/mkdirp": "^1.0.1",
Expand Down
21 changes: 20 additions & 1 deletion packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
loadConfig,
GraphQLConfig,
GraphQLProjectConfig,
GraphQLExtensionDeclaration,
} from 'graphql-config';

import type { UnnormalizedTypeDefPointer } from '@graphql-tools/load';
Expand All @@ -42,6 +43,16 @@ import stringToHash from './stringToHash';
import glob from 'glob';
import { LoadConfigOptions } from './types';
import { URI } from 'vscode-uri';
import { CodeFileLoader } from '@graphql-tools/code-file-loader';

const LanguageServiceExtension: GraphQLExtensionDeclaration = api => {
// For schema
api.loaders.schema.register(new CodeFileLoader());
// For documents
api.loaders.documents.register(new CodeFileLoader());

return { name: 'languageService' };
};

// Maximum files to read when processing GraphQL files.
const MAX_READS = 200;
Expand All @@ -57,7 +68,15 @@ export async function getGraphQLCache({
loadConfigOptions: LoadConfigOptions;
config?: GraphQLConfig;
}): Promise<GraphQLCache> {
const graphQLConfig = config || (await loadConfig(loadConfigOptions));
const graphQLConfig =
config ||
(await loadConfig({
...loadConfigOptions,
extensions: [
...(loadConfigOptions?.extensions ?? []),
LanguageServiceExtension,
],
}));
return new GraphQLCache({
configDir: loadConfigOptions.rootDir!,
config: graphQLConfig!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class GraphQLLanguageService {

output.push({
// @ts-ignore
name: tree.representativeName,
name: tree.representativeName ?? 'Anonymous',
kind: getKind(tree),
location: {
uri: filePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ import {
import { GraphQLCache, getGraphQLCache } from '../GraphQLCache';
import { parseDocument } from '../parseDocument';
import type { FragmentInfo, ObjectTypeInfo } from 'graphql-language-service';
import { NoopLogger } from '../Logger';

function withoutASTNode(definition: any) {
const result = { ...definition };
delete result.astNode;
return result;
}

const logger = new NoopLogger();
describe('GraphQLCache', () => {
const configDir = __dirname;
let graphQLRC;
let cache = new GraphQLCache({
configDir,
config: graphQLRC,
parser: parseDocument,
logger,
});

beforeEach(async () => {
Expand All @@ -54,6 +57,7 @@ describe('GraphQLCache', () => {
configDir,
config: graphQLRC,
parser: parseDocument,
logger,
});
});

Expand All @@ -72,6 +76,7 @@ describe('GraphQLCache', () => {
const cacheWithExtensions = await getGraphQLCache({
loadConfigOptions: { rootDir: configDir, extensions },
parser: parseDocument,
logger,
});
const config = cacheWithExtensions.getGraphQLConfig();
expect('extensions' in config).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@types/json-schema": "7.0.9",
"benchmark": "^2.1.4",
"graphql": "^16.4.0",
"graphql-config": "4.3.0",
"graphql-config": "5.0.2",
"lodash": "^4.17.15",
"platform": "^1.3.5",
"ts-node": "^8.10.2",
Expand Down
40 changes: 39 additions & 1 deletion packages/vscode-graphql-execution/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,45 @@ build({
minify: arg === '--minify',
platform: 'node',
outdir: 'out/',
external: ['vscode', 'ts-node', 'tslib'],
external: [
'squirrelly',
'teacup',
'coffee-script',
'marko',
'slm',
'vash',
'plates',
'babel-core',
'htmling',
'ractive',
'mote',
'eco',
'jqtpl',
'hamljs',
'jazz',
'hamlet',
'whiskers',
'haml-coffee',
'hogan.js',
'templayed',
'walrus',
'mustache',
'just',
'ect',
'toffee',
'twing',
'dot',
'bracket-template',
'vscode',
'velocityjs',
'dustjs-linkedin',
'atpl',
'liquor',
'twig',
'cosmiconfig',
'graphql-config',
'graphql',
],
format: 'cjs',
sourcemap: true,
watch: isWatchMode,
Expand Down
39 changes: 13 additions & 26 deletions packages/vscode-graphql-execution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"engines": {
"vscode": "^1.63.0"
},
"main": "./dist/extension.js",
"main": "./out/extension.js",
"icon": "assets/images/logo.png",
"contributors": [
{
Expand All @@ -25,14 +25,12 @@
"Programming Languages"
],
"activationEvents": [
"onCommand:vscode-graphql-execution.contentProvider.isDebugging",
"onCommand:vscode-graphql-execution.contentProvidergit.contentProvider",
"workspaceContains:**/.graphqlrc",
"workspaceContains:**/.graphqlconfig",
"workspaceContains:**/.graphqlrc.{json,yaml,yml,js,ts,toml}",
"workspaceContains:**/graphql.config.{json,yaml,yml,js,ts,toml}",
"workspaceContains:**/package.json",
"onCommand:vscode-graphql-execution.isDebugging",
"onCommand:vscode-graphql-execution.contentProvider",
"onLanguage:graphql"
"workspaceContains:**/package.json"
],
"contributes": {
"commands": [
Expand Down Expand Up @@ -84,7 +82,8 @@
},
"homepage": "https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-execution/README.md",
"scripts": {
"vsce:package": "vsce package --yarn",
"compile": "node esbuild.js",
"vsce:package": "yarn compile && vsce package --yarn",
"vsce:prepublish": "npm run vsce:package",
"vsce:publish": "vsce publish --yarn",
"open-vsx:publish": "ovsx publish --yarn -i . --pat $OVSX_PAT",
Expand All @@ -105,29 +104,17 @@
"@urql/core": "2.6.1",
"capitalize": "2.0.4",
"dotenv": "10.0.0",
"graphql-config": "4.3.0",
"graphql-config": "5.0.2",
"graphql-tag": "2.12.6",
"graphql-ws": "5.10.0",
"@whatwg-node/fetch": "0.2.8",
"ws": "8.8.1",
"graphql": "16.6.0",
"nullthrows": "1.1.1"
},
"resolutions": {
"cosmiconfig": "^5.0.1"
},
"workspaces": {
"nohoist": [
"graphql",
"graphql-config",
"dotenv",
"graphql-ws",
"graphql-tag",
"@urql/core",
"ws",
"nullthrows",
"capitalize",
"@whatwg-node/fetch"
]
"nullthrows": "1.1.1",
"@graphql-tools/code-file-loader": "8.0.1",
"cosmiconfig": "8.2.0",
"svelte2tsx": "^0.6.16",
"svelte": "^4.0.0",
"cosmiconfig-toml-loader": "^1.0.0"
}
}
Loading

0 comments on commit 01daed1

Please sign in to comment.