Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-language-service-utils

Package Overview
Dependencies
Maintainers
8
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-language-service-utils - npm Package Compare versions

Comparing version 2.1.0 to 2.3.0

CHANGELOG.md

79

dist/getASTNodeAtPosition.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getASTNodeAtPosition = getASTNodeAtPosition;
exports.pointToOffset = pointToOffset;
var _Range = require("./Range");
var _graphql = require("graphql");
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
const graphql_1 = require("graphql");
function getASTNodeAtPosition(query, ast, point) {
var offset = pointToOffset(query, point);
var nodeContainingPosition;
(0, _graphql.visit)(ast, {
enter: function enter(node) {
if (node.kind !== 'Name' && // We're usually interested in their parents
node.loc && node.loc.start <= offset && offset <= node.loc.end) {
nodeContainingPosition = node;
} else {
return false;
}
},
leave: function leave(node) {
if (node.loc && node.loc.start <= offset && offset <= node.loc.end) {
return false;
}
}
});
return nodeContainingPosition;
const offset = pointToOffset(query, point);
let nodeContainingPosition;
graphql_1.visit(ast, {
enter(node) {
if (node.kind !== 'Name' &&
node.loc &&
node.loc.start <= offset &&
offset <= node.loc.end) {
nodeContainingPosition = node;
}
else {
return false;
}
},
leave(node) {
if (node.loc && node.loc.start <= offset && offset <= node.loc.end) {
return false;
}
},
});
return nodeContainingPosition;
}
exports.getASTNodeAtPosition = getASTNodeAtPosition;
function pointToOffset(text, point) {
var linesUntilPosition = text.split('\n').slice(0, point.line);
return point.character + linesUntilPosition.map(function (line) {
return line.length + 1;
} // count EOL
).reduce(function (a, b) {
return a + b;
}, 0);
}
const linesUntilPosition = text.split('\n').slice(0, point.line);
return (point.character +
linesUntilPosition
.map(line => line.length + 1)
.reduce((a, b) => a + b, 0));
}
exports.pointToOffset = pointToOffset;
//# sourceMappingURL=getASTNodeAtPosition.js.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getASTNodeAtPosition", {
enumerable: true,
get: function get() {
return _getASTNodeAtPosition.getASTNodeAtPosition;
}
});
Object.defineProperty(exports, "pointToOffset", {
enumerable: true,
get: function get() {
return _getASTNodeAtPosition.pointToOffset;
}
});
Object.defineProperty(exports, "Position", {
enumerable: true,
get: function get() {
return _Range.Position;
}
});
Object.defineProperty(exports, "Range", {
enumerable: true,
get: function get() {
return _Range.Range;
}
});
Object.defineProperty(exports, "locToRange", {
enumerable: true,
get: function get() {
return _Range.locToRange;
}
});
Object.defineProperty(exports, "offsetToPosition", {
enumerable: true,
get: function get() {
return _Range.offsetToPosition;
}
});
Object.defineProperty(exports, "validateWithCustomRules", {
enumerable: true,
get: function get() {
return _validateWithCustomRules.validateWithCustomRules;
}
});
var _getASTNodeAtPosition = require("./getASTNodeAtPosition");
var _Range = require("./Range");
var _validateWithCustomRules = require("./validateWithCustomRules");
Object.defineProperty(exports, "__esModule", { value: true });
var getASTNodeAtPosition_1 = require("./getASTNodeAtPosition");
exports.getASTNodeAtPosition = getASTNodeAtPosition_1.getASTNodeAtPosition;
exports.pointToOffset = getASTNodeAtPosition_1.pointToOffset;
var Range_1 = require("./Range");
exports.Position = Range_1.Position;
exports.Range = Range_1.Range;
exports.locToRange = Range_1.locToRange;
exports.offsetToPosition = Range_1.offsetToPosition;
var validateWithCustomRules_1 = require("./validateWithCustomRules");
exports.validateWithCustomRules = validateWithCustomRules_1.validateWithCustomRules;
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.offsetToPosition = offsetToPosition;
exports.locToRange = locToRange;
exports.Position = exports.Range = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
var Range =
/*#__PURE__*/
function () {
function Range(start, end) {
var _this = this;
_classCallCheck(this, Range);
_defineProperty(this, "start", void 0);
_defineProperty(this, "end", void 0);
_defineProperty(this, "containsPosition", function (position) {
if (_this.start.line === position.line) {
return _this.start.character <= position.character;
} else if (_this.end.line === position.line) {
return _this.end.character >= position.character;
} else {
return _this.start.line <= position.line && _this.end.line >= position.line;
}
});
this.start = start;
this.end = end;
}
_createClass(Range, [{
key: "setStart",
value: function setStart(line, character) {
this.start = new Position(line, character);
Object.defineProperty(exports, "__esModule", { value: true });
class Range {
constructor(start, end) {
this.containsPosition = (position) => {
if (this.start.line === position.line) {
return this.start.character <= position.character;
}
else if (this.end.line === position.line) {
return this.end.character >= position.character;
}
else {
return this.start.line <= position.line && this.end.line >= position.line;
}
};
this.start = start;
this.end = end;
}
}, {
key: "setEnd",
value: function setEnd(line, character) {
this.end = new Position(line, character);
setStart(line, character) {
this.start = new Position(line, character);
}
}]);
return Range;
}();
setEnd(line, character) {
this.end = new Position(line, character);
}
}
exports.Range = Range;
var Position =
/*#__PURE__*/
function () {
function Position(line, character) {
var _this2 = this;
_classCallCheck(this, Position);
_defineProperty(this, "line", void 0);
_defineProperty(this, "character", void 0);
_defineProperty(this, "lessThanOrEqualTo", function (position) {
return _this2.line < position.line || _this2.line === position.line && _this2.character <= position.character;
});
this.line = line;
this.character = character;
}
_createClass(Position, [{
key: "setLine",
value: function setLine(line) {
this.line = line;
class Position {
constructor(line, character) {
this.lessThanOrEqualTo = (position) => this.line < position.line ||
this.line === position.line && this.character <= position.character;
this.line = line;
this.character = character;
}
}, {
key: "setCharacter",
value: function setCharacter(character) {
this.character = character;
setLine(line) {
this.line = line;
}
}]);
return Position;
}();
setCharacter(character) {
this.character = character;
}
}
exports.Position = Position;
function offsetToPosition(text, loc) {
var EOL = '\n';
var buf = text.slice(0, loc);
var lines = buf.split(EOL).length - 1;
var lastLineIndex = buf.lastIndexOf(EOL);
return new Position(lines, loc - lastLineIndex - 1);
const EOL = '\n';
const buf = text.slice(0, loc);
const lines = buf.split(EOL).length - 1;
const lastLineIndex = buf.lastIndexOf(EOL);
return new Position(lines, loc - lastLineIndex - 1);
}
exports.offsetToPosition = offsetToPosition;
function locToRange(text, loc) {
var start = offsetToPosition(text, loc.start);
var end = offsetToPosition(text, loc.end);
return new Range(start, end);
}
const start = offsetToPosition(text, loc.start);
const end = offsetToPosition(text, loc.end);
return new Range(start, end);
}
exports.locToRange = locToRange;
//# sourceMappingURL=Range.js.map
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "__esModule", { value: true });
const graphql_1 = require("graphql");
function validateWithCustomRules(schema, ast, customRules, isRelayCompatMode) {
const { NoUnusedFragments, } = require('graphql/validation/rules/NoUnusedFragments');
const { ExecutableDefinitions, } = require('graphql/validation/rules/ExecutableDefinitions');
const rulesToSkip = [NoUnusedFragments, ExecutableDefinitions];
if (isRelayCompatMode) {
const { KnownFragmentNames, } = require('graphql/validation/rules/KnownFragmentNames');
rulesToSkip.push(KnownFragmentNames);
}
const rules = graphql_1.specifiedRules.filter(rule => !rulesToSkip.some(r => r === rule));
const typeInfo = new graphql_1.TypeInfo(schema);
if (customRules) {
Array.prototype.push.apply(rules, customRules);
}
const errors = graphql_1.validate(schema, ast, rules, typeInfo);
if (errors.length > 0) {
return errors.filter(error => {
if (error.message.indexOf('Unknown directive') === -1) {
return true;
}
if (error.nodes && error.nodes[0]) {
const node = error.nodes[0];
return !(node.name &&
node.name.value === 'arguments' ||
node.name.value === 'argumentDefinitions');
}
});
}
return [];
}
exports.validateWithCustomRules = validateWithCustomRules;
var _graphql = require("graphql");
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
/**
* Validate a GraphQL Document optionally with custom validation rules.
*/
function validateWithCustomRules(schema, ast, customRules, isRelayCompatMode) {
// Because every fragment is considered for determing model subsets that may
// be used anywhere in the codebase they're all technically "used" by clients
// of graphql-data. So we remove this rule from the validators.
var _require = require('graphql/validation/rules/NoUnusedFragments'),
NoUnusedFragments = _require.NoUnusedFragments;
var _require2 = require('graphql/validation/rules/ExecutableDefinitions'),
ExecutableDefinitions = _require2.ExecutableDefinitions;
var rulesToSkip = [NoUnusedFragments, ExecutableDefinitions];
if (isRelayCompatMode) {
var _require3 = require('graphql/validation/rules/KnownFragmentNames'),
KnownFragmentNames = _require3.KnownFragmentNames;
rulesToSkip.push(KnownFragmentNames);
}
var rules = _graphql.specifiedRules.filter(function (rule) {
return !rulesToSkip.some(function (r) {
return r === rule;
});
});
var typeInfo = new _graphql.TypeInfo(schema);
if (customRules) {
Array.prototype.push.apply(rules, customRules);
}
var errors = (0, _graphql.validate)(schema, ast, rules, typeInfo);
if (errors.length > 0) {
return errors.filter(function (error) {
if (error.message.indexOf('Unknown directive') === -1) {
return true;
}
return !(error.nodes && error.nodes[0] && error.nodes[0].name && error.nodes[0].name.value === 'arguments' || error.nodes && error.nodes[0] && error.nodes[0].name && error.nodes[0].name.value && error.nodes[0].name.value === 'argumentDefinitions');
});
}
return [];
}
//# sourceMappingURL=validateWithCustomRules.js.map
{
"name": "graphql-language-service-utils",
"version": "2.1.0",
"version": "2.3.0",
"description": "Utilities to support the GraphQL Language Service",

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

],
"repository": "https://github.com/graphql/graphiql/tree/master/packages/graphql-language-service-utils",
"repository": "http://github.com/graphql/graphiql",
"homepage": "https://github.com/graphql/graphiql/tree/master/packages/graphql-language-service-utils#readme",

@@ -24,6 +24,7 @@ "bugs": {

"main": "dist/index.js",
"types": "src/index.ts",
"scripts": {
"test": "echo 'Please run `npm test` from the root of the repo' && exit 1",
"build": "yarn run build-js && yarn run build-flow",
"build-js": "node ../../resources/buildJs.js",
"test": "node ../../resources/runTests.js",
"build": "yarn run build-ts && yarn run build-flow",
"build-ts": "tsc",
"build-flow": "node ../../resources/buildFlow.js",

@@ -37,4 +38,4 @@ "prepublish": "node ../../resources/prepublish.js"

"graphql-config": "2.2.1",
"graphql-language-service-types": "^1.3.0"
"graphql-language-service-types": "^1.5.0"
}
}

@@ -5,2 +5,2 @@ # graphql-language-service-utils

Utilities to support the [GraphQL Language Service](https://github.com/graphql/graphql-language-service).
Utilities to support the [GraphQL Language Service](https://github.com/graphql/graphiql/tree/master/packages/graphql-language-service).
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc