Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
): Promise {
const serverCapabilities = {
capabilities: {
completionProvider: {resolveProvider: true},
definitionProvider: true,
textDocumentSync: 1,
},
};
const configDir = findGraphQLConfigDir(rootPath);
if (!configDir) {
return null;
}
graphQLCache = await getGraphQLCache(configDir);
languageService = new GraphQLLanguageService(graphQLCache);
return serverCapabilities;
}
const rootPath = dirname(
findGraphQLConfigFile(configDir ? configDir.trim() : params.rootPath)
);
if (!rootPath) {
throw new Error(
'`--configDir` option or `rootPath` argument is required.'
);
}
this._graphQLCache = await getGraphQLCache(rootPath);
const config = getGraphQLConfig(rootPath);
if (this._watchmanClient) {
this._subcribeWatchman(config, this._watchmanClient);
}
this._languageService = new GraphQLLanguageService(this._graphQLCache);
if (!serverCapabilities) {
throw new Error('GraphQL Language Server is not initialized.');
}
this._isInitialized = true;
this._logger.log(
JSON.stringify({
type: 'usage',
messageType: 'initialize',
})
);
return serverCapabilities;
}
if (!graphQLConfigDir) {
process.stdout.write(JSON.stringify(
convertToRpcMessage({
id: '-1',
error: {
code: ERROR_CODES.SERVER_NOT_INITIALIZED,
message: '.graphqlrc not found',
},
}),
));
return;
}
graphQLCache = await getGraphQLCache(graphQLConfigDir);
}
if (!languageService) {
languageService = new GraphQLLanguageService(graphQLCache);
}
let json;
try {
json = JSON.parse(message);
} catch (error) {
process.stdout.write(JSON.stringify(
convertToRpcMessage({
id: '-1',
error: {
code: ERROR_CODES.PARSE_ERROR,
message: 'Request contains incorrect JSON format',
},
}),
));