diff --git a/.changeset/poor-terms-greet.md b/.changeset/poor-terms-greet.md new file mode 100644 index 00000000000..1b92d890d0a --- /dev/null +++ b/.changeset/poor-terms-greet.md @@ -0,0 +1,5 @@ +--- +'graphql-language-service-server': patch +--- + +Add missing `?.` operator in loading config diff --git a/packages/graphql-language-service-server/src/MessageProcessor.ts b/packages/graphql-language-service-server/src/MessageProcessor.ts index 3c616548ce2..41549a3425c 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.ts +++ b/packages/graphql-language-service-server/src/MessageProcessor.ts @@ -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, @@ -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({ @@ -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({ @@ -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)[key]; if (value === undefined || value === null) { delete agg[key]; } diff --git a/packages/graphql-language-service-server/src/types.ts b/packages/graphql-language-service-server/src/types.ts index 08e4d704afd..e482334d1c2 100644 --- a/packages/graphql-language-service-server/src/types.ts +++ b/packages/graphql-language-service-server/src/types.ts @@ -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 .{js,ts,toml,yaml,json} in addition to default `graphql.config` `graphql{config,rc}` + */ + fileName?: string; + /** + * optional .config.{js,ts,toml,yaml,json} & 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; + /** + * 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; +}