Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/poor-terms-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-language-service-server': patch
---

Add missing `?.` operator in loading config
15 changes: 10 additions & 5 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ import {
LoaderNoResultError,
ProjectNotFoundError,
} from 'graphql-config';
import type { LoadConfigOptions, LocateCommand } from './types';
import type {
GraphQLConfigSettings,
LoadConfigOptions,
LocateCommand,
VSCodeGraphQLSettings,
} from './types';
import {
DEFAULT_SUPPORTED_EXTENSIONS,
SupportedExtensionsEnum,
Expand Down Expand Up @@ -103,7 +108,7 @@ export class MessageProcessor {
private _tmpDirBase: string;
private _loadConfigOptions: LoadConfigOptions;
private _rootPath: string = process.cwd();
private _settings: any;
private _settings!: VSCodeGraphQLSettings & GraphQLConfigSettings;
private _providedConfig?: GraphQLConfig;

constructor({
Expand Down Expand Up @@ -213,8 +218,8 @@ export class MessageProcessor {
// TODO: eventually we will instantiate an instance of this per workspace,
// so rootDir should become that workspace's rootDir
this._settings = { ...settings, ...vscodeSettings };
const rootDir = this._settings?.load?.rootDir.length
? this._settings?.load?.rootDir
const rootDir = this._settings?.load?.rootDir?.length
? this._settings.load.rootDir
: this._rootPath;
if (settings?.dotEnvPath) {
require('dotenv').config({
Expand All @@ -224,7 +229,7 @@ export class MessageProcessor {
this._rootPath = rootDir;
this._loadConfigOptions = {
...Object.keys(this._settings?.load ?? {}).reduce((agg, key) => {
const value = this._settings?.load[key];
const value = (this._settings?.load as Record<string, unknown>)[key];
if (value === undefined || value === null) {
delete agg[key];
}
Expand Down
58 changes: 58 additions & 0 deletions packages/graphql-language-service-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,61 @@ export interface ServerOptions {
*/
debug?: true;
}

/** Settings defined by the vscode-graphql's package.json, starting with `vscode-graphql` */
export interface VSCodeGraphQLSettings {
/**
* Enable debug logs and node debugger for client
*/
debug?: boolean | null;
/**
* Use a cached file output of your graphql-config schema result for definition lookups, symbols, outline, etc. Enabled by default when one or more schema entry is not a local file with SDL in it. Disable if you want to use SDL with a generated schema.
*/
cacheSchemaFileForLookup?: boolean;
/**
* Disables outlining and other expensive operations for files larger than this threshold (in bytes). Defaults to 1000000 (one million).
*/
largeFileThreshold?: number;
/**
* Fail the request on invalid certificate
*/
rejectUnauthorized?: boolean;
/**
* Schema cache ttl in milliseconds - the interval before requesting a fresh schema when caching the local schema file is enabled. Defaults to 30000 (30 seconds).
*/
schemaCacheTTL?: number;
/**
* The transport used between the language server and the client.
*/
transport?: 'ipc' | 'stdio';
}
export interface GraphQLConfigLoadSettings {
/**
* Base dir for graphql config loadConfig(), to look for config files or package.json
*/
rootDir?: string;
/**
* exact filePath for a `graphql-config` file `loadConfig()`
*/
filepath?: string;
/**
* optional <fileName>.{js,ts,toml,yaml,json} in addition to default `graphql.config` `graphql{config,rc}`
*/
fileName?: string;
/**
* optional <configName>.config.{js,ts,toml,yaml,json} & <configName>rc* instead of default `graphql`
*/
configName?: string;
/**
* legacy mode for graphql config v2 config
*/
legacy?: boolean;
}
/** Settings defined by the vscode-graphql's package.json, starting with `graphql-config` */
export interface GraphQLConfigSettings {
load?: GraphQLConfigLoadSettings & Record<string, unknown>;
/**
* optional .env load file path, if not the default. specify a relative path to the .env file to be loaded by dotenv module. you can also import dotenv in the config file.
*/
dotEnvPath?: string;
}