Socket
Socket
Sign inDemoInstall

graphql-language-service

Package Overview
Dependencies
12
Maintainers
4
Versions
239
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.8 to 0.0.9

18

dist/cli.js

@@ -15,3 +15,3 @@ 'use strict';

var _yargs$usage$help$ali = _yargs2.default.usage('GraphQL Language Service Command-Line Interface.\n' + 'Usage: $0 <command> <file>\n' + ' [-h | --help]\n' + ' [-c | --configDir] {configDir}\n' + ' [-t | --text] {textBuffer}\n' + ' [-f | --file] {filePath}\n' + ' [-s | --schema] {schemaPath}\n' + ' [-p | --port] {port}\n').help('h').alias('h', 'help').demand(1, 'At least one command is required.\n' + 'Commands: "server, validate, autocomplete, outline"\n').option('t', {
var _yargs$usage$help$ali = _yargs2.default.usage('GraphQL Language Service Command-Line Interface.\n' + 'Usage: $0 <command> <file>\n' + ' [-h | --help]\n' + ' [-c | --configDir] {configDir}\n' + ' [-t | --text] {textBuffer}\n' + ' [-f | --file] {filePath}\n' + ' [-s | --schema] {schemaPath}\n' + ' [-m | --method] {method}\n' + ' [-p | --port] {port}\n').help('h').alias('h', 'help').demand(1, 'At least one command is required.\n' + 'Commands: "server, validate, autocomplete, outline"\n').option('t', {
alias: 'text',

@@ -34,2 +34,6 @@ describe: 'Text buffer to perform GraphQL diagnostics on.\n' + 'Will defer to --file option if omitted.\n' + 'Overrides the --file option, if any.\n',

type: 'string'
}).option('m', {
alias: 'method',
describe: 'A IPC communication method between client and server.\n' + 'Can be one of: stream, node, socket.\n' + 'Will default to use a node IPC channel for communication.\n',
type: 'string'
}).option('p', {

@@ -59,6 +63,12 @@ alias: 'port',

var options = {};
if (argv.port) {
options = { port: argv.port };
if (argv && argv.port) {
options.port = argv.port;
}
(0, _graphqlLanguageServiceServer.startServer)(argv.configDir, options);
if (argv && argv.method) {
options.method = argv.method;
}
if (argv && argv.configDir) {
options.configDir = argv.configDir;
}
(0, _graphqlLanguageServiceServer.startServer)(options);
break;

@@ -65,0 +75,0 @@ default:

{
"name": "graphql-language-service",
"repository": "https://github.com/graphql/graphql-language-service",
"version": "0.0.8",
"version": "0.0.9",
"description": "An interface for building GraphQL language services for IDEs",

@@ -44,3 +44,3 @@ "contributors": [

"graphql-language-service-interface": "0.0.7",
"graphql-language-service-server": "0.0.9",
"graphql-language-service-server": "0.0.10",
"graphql-language-service-utils": "0.0.6",

@@ -47,0 +47,0 @@ "yargs": "^7.0.1",

@@ -55,3 +55,3 @@ 'use strict';

function processIPCNotificationMessage(message, writer) {
var method, response, textDocument, uri, text, cachedDocument, diagnostics, contentChanges;
var method, response, textDocument, diagnostics, uri, text, cachedDocument, contentChanges, documentUri;
return regeneratorRuntime.async(function processIPCNotificationMessage$(_context) {

@@ -64,9 +64,10 @@ while (1) {

textDocument = void 0;
diagnostics = void 0;
_context.t0 = method;
_context.next = _context.t0 === 'textDocument/didOpen' ? 6 : _context.t0 === 'textDocument/didSave' ? 6 : _context.t0 === 'textDocument/didChange' ? 18 : _context.t0 === 'textDocument/didClose' ? 24 : _context.t0 === 'exit' ? 29 : 31;
_context.next = _context.t0 === 'textDocument/didOpen' ? 7 : _context.t0 === 'textDocument/didSave' ? 7 : _context.t0 === 'textDocument/didChange' ? 19 : _context.t0 === 'textDocument/didClose' ? 31 : _context.t0 === 'exit' ? 36 : 38;
break;
case 6:
case 7:
if (!(!message.params || !message.params.textDocument)) {
_context.next = 8;
_context.next = 9;
break;

@@ -77,3 +78,3 @@ }

case 8:
case 9:
textDocument = message.params.textDocument;

@@ -98,6 +99,6 @@ uri = textDocument.uri;

_context.next = 14;
_context.next = 15;
return regeneratorRuntime.awrap(provideDiagnosticsMessage(text, uri));
case 14:
case 15:
diagnostics = _context.sent;

@@ -110,7 +111,7 @@

sendMessageIPC(response, writer);
return _context.abrupt('break', 31);
return _context.abrupt('break', 38);
case 18:
case 19:
if (!(!message.params || !message.params.textDocument || !message.params.contentChanges)) {
_context.next = 20;
_context.next = 21;
break;

@@ -121,3 +122,3 @@ }

case 20:
case 21:

@@ -130,8 +131,23 @@ textDocument = message.params.textDocument;

invalidateCache(textDocument, textDocument.uri || message.params.uri, contentChanges[contentChanges.length - 1]);
return _context.abrupt('break', 31);
documentUri = textDocument.uri || message.params.uri;
case 24:
invalidateCache(textDocument, documentUri, contentChanges[contentChanges.length - 1]);
// Send the diagnostics onChange as well
_context.next = 27;
return regeneratorRuntime.awrap(provideDiagnosticsMessage(textDocumentCache.get(documentUri), documentUri));
case 27:
diagnostics = _context.sent;
response = convertToRpcMessage({
method: 'textDocument/publishDiagnostics',
params: { documentUri: documentUri, diagnostics: diagnostics }
});
sendMessageIPC(response, writer);
return _context.abrupt('break', 38);
case 31:
if (!(!message.params || !message.params.textDocument)) {
_context.next = 26;
_context.next = 33;
break;

@@ -142,3 +158,3 @@ }

case 26:
case 33:
textDocument = message.params.textDocument;

@@ -149,9 +165,9 @@

}
return _context.abrupt('break', 31);
return _context.abrupt('break', 38);
case 29:
case 36:
process.exit(0);
return _context.abrupt('break', 31);
return _context.abrupt('break', 38);
case 31:
case 38:
case 'end':

@@ -158,0 +174,0 @@ return _context.stop();

@@ -17,4 +17,4 @@ 'use strict';

exports.default = function startServer(configDir, options) {
var socket, ipcWriter, data;
exports.default = function startServer(options) {
var configDir;
return regeneratorRuntime.async(function startServer$(_context) {

@@ -24,80 +24,31 @@ while (1) {

case 0:
if (options && options.port) {
// Socket protocol support
socket = _net2.default.createServer(function (client) {
client.setEncoding('utf8');
var messageReader = new _vscodeJsonrpc.SocketMessageReader(client);
var messageWriter = new _vscodeJsonrpc.SocketMessageWriter(client);
if (!options || !options.configDir) {
process.stderr.write('--configDir is required!');
process.exit(1);
}
client.on('end', function () {
socket.close();
process.exit(0);
});
configDir = options.configDir;
messageReader.listen(function (message) {
try {
if (message.id != null) {
(0, _MessageProcessor.processIPCRequestMessage)(message, configDir, messageWriter);
} else {
(0, _MessageProcessor.processIPCNotificationMessage)(message, messageWriter);
}
} catch (error) {
// Swallow error silently.
}
});
});
socket.listen(options.port);
if (!(options && options.method)) {
_context.next = 12;
break;
}
// IPC protocol support
// The language server protocol specifies that the client starts sending
// messages when the server starts. Start listening from this point.
ipcWriter = new _vscodeJsonrpc.IPCMessageWriter(process);
_context.t0 = options.method;
_context.next = _context.t0 === 'stream' ? 6 : _context.t0 === 'socket' ? 8 : _context.t0 === 'node' ? 10 : 10;
break;
process.on('message', function (message) {
// TODO: support the header part of the language server protocol
// Recognize the Content-Length header
if (typeof message === 'string' && message.indexOf('Content-Length') === 0) {
return;
}
case 6:
connectWithStream(configDir);
return _context.abrupt('break', 12);
if (message.id != null) {
(0, _MessageProcessor.processIPCRequestMessage)(message, configDir, ipcWriter);
} else {
(0, _MessageProcessor.processIPCNotificationMessage)(message, ipcWriter);
}
});
case 8:
connectWithSocket(configDir, options.port);
return _context.abrupt('break', 12);
// Stream (stdio) protocol support
// Depending on the size of the query, incomplete query strings
// may be streamed in. The below code tries to detect the end of current
// batch of streamed data, splits the batch into appropriate JSON string,
// and calls the function to process those messages.
// This might get tricky since the query string needs to preserve the newline
// characters to ensure the correct Range/Point values gets computed by the
// language service interface methods. The current solution is to flow the
// stream until aggregated data ends with the unescaped newline character,
// pauses the stream and process the messages, and resumes back the stream
// for another batch.
data = '';
case 10:
connectWithNodeIPC(configDir);
return _context.abrupt('break', 12);
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
data += chunk.toString();
// Check if the current buffer contains newline character.
var flagPosition = data.indexOf('\r\n');
if (flagPosition !== -1) {
// There may be more than one message in the buffer.
var messages = data.split('\r\n');
data = messages.pop().trim();
messages.forEach(function (message) {
return (0, _MessageProcessor.processStreamMessage)(message, configDir);
});
}
});
case 6:
case 12:
case 'end':

@@ -116,2 +67,78 @@ return _context.stop();

*
*/
*/
function connectWithSocket(configDir, port) {
var socket = _net2.default.createServer(function (client) {
client.setEncoding('utf8');
var messageReader = new _vscodeJsonrpc.SocketMessageReader(client);
var messageWriter = new _vscodeJsonrpc.SocketMessageWriter(client);
client.on('end', function () {
socket.close();
process.exit(0);
});
messageReader.listen(function (message) {
try {
if (message.id != null) {
(0, _MessageProcessor.processIPCRequestMessage)(message, configDir, messageWriter);
} else {
(0, _MessageProcessor.processIPCNotificationMessage)(message, messageWriter);
}
} catch (error) {
// Swallow error silently.
}
});
});
socket.listen(port);
}
function connectWithNodeIPC(configDir) {
// IPC protocol support
// The language server protocol specifies that the client starts sending
// messages when the server starts. Start listening from this point.
var ipcWriter = new _vscodeJsonrpc.IPCMessageWriter(process);
var ipcReader = new _vscodeJsonrpc.IPCMessageReader(process);
ipcReader.listen(function (message) {
try {
if (message.id != null) {
(0, _MessageProcessor.processIPCRequestMessage)(message, configDir, ipcWriter);
} else {
(0, _MessageProcessor.processIPCNotificationMessage)(message, ipcWriter);
}
} catch (error) {
// Swallow error silently.
}
});
}
function connectWithStream(configDir) {
// Stream (stdio) protocol support
// Depending on the size of the query, incomplete query strings
// may be streamed in. The below code tries to detect the end of current
// batch of streamed data, splits the batch into appropriate JSON string,
// and calls the function to process those messages.
// This might get tricky since the query string needs to preserve the newline
// characters to ensure the correct Range/Point values gets computed by the
// language service interface methods. The current solution is to flow the
// stream until aggregated data ends with the unescaped newline character,
// pauses the stream and process the messages, and resumes back the stream
// for another batch.
var data = '';
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
data += chunk.toString();
// Check if the current buffer contains newline character.
var flagPosition = data.indexOf('\r\n');
if (flagPosition !== -1) {
// There may be more than one message in the buffer.
var messages = data.split('\r\n');
data = messages.pop().trim();
messages.forEach(function (message) {
return (0, _MessageProcessor.processStreamMessage)(message, configDir);
});
}
});
}
{
"name": "graphql-language-service-server",
"repository": "https://github.com/graphql/graphql-language-service",
"version": "0.0.9",
"version": "0.0.10",
"description": "Server process backing the GraphQL Language Service",

@@ -6,0 +6,0 @@ "contributors": [

{
"graphql-language-service": {
"version": "0.0.8"
"version": "0.0.9"
},

@@ -18,3 +18,3 @@ "graphql-language-server": {

"graphql-language-service-server": {
"version": "0.0.9"
"version": "0.0.10"
},

@@ -21,0 +21,0 @@ "graphql-language-service-types": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc