Socket
Socket
Sign inDemoInstall

codemirror-graphql

Package Overview
Dependencies
Maintainers
5
Versions
248
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

codemirror-graphql - npm Package Compare versions

Comparing version 0.8.3 to 0.9.0

results/__tests__/mode-test.js

47

hint.js

@@ -1,10 +0,17 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _graphqlLanguageServiceInterface = require("graphql-language-service-interface");
var _graphqlLanguageServiceInterface = require('graphql-language-service-interface');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

@@ -28,13 +35,5 @@ /**

*/
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
_codemirror["default"].registerHelper('hint', 'graphql', function (editor, options) {
var schema = options.schema;
_codemirror2.default.registerHelper('hint', 'graphql', function (editor, options) {
var schema = options.schema;
if (!schema) {

@@ -62,2 +61,3 @@ return;

*/
var tokenStart = token.type !== null && /"|\w/.test(token.string[0]) ? token.start : token.end;

@@ -74,10 +74,17 @@ var results = {

}),
from: { line: cur.line, column: tokenStart },
to: { line: cur.line, column: token.end }
from: {
line: cur.line,
column: tokenStart
},
to: {
line: cur.line,
column: token.end
}
};
if (results && results.list && results.list.length > 0) {
results.from = _codemirror2.default.Pos(results.from.line, results.from.column);
results.to = _codemirror2.default.Pos(results.to.line, results.to.column);
_codemirror2.default.signal(editor, 'hasCompletion', editor, results, token);
results.from = _codemirror["default"].Pos(results.from.line, results.from.column);
results.to = _codemirror["default"].Pos(results.to.line, results.to.column);
_codemirror["default"].signal(editor, 'hasCompletion', editor, results, token);
}

@@ -84,0 +91,0 @@

@@ -1,19 +0,24 @@

'use strict';
"use strict";
var _graphql = require('graphql');
var _graphql = require("graphql");
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _getTypeInfo = _interopRequireDefault(require("./utils/getTypeInfo"));
var _getTypeInfo = require('./utils/getTypeInfo');
var _SchemaReference = require("./utils/SchemaReference");
var _getTypeInfo2 = _interopRequireDefault(_getTypeInfo);
require("./utils/info-addon");
var _SchemaReference = require('./utils/SchemaReference');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
require('./utils/info-addon');
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -33,3 +38,3 @@ * Registers GraphQL "info" tooltips for CodeMirror.

*/
_codemirror2.default.registerHelper('info', 'graphql', function (token, options) {
_codemirror["default"].registerHelper('info', 'graphql', function (token, options) {
if (!options.schema || !token.state) {

@@ -42,7 +47,6 @@ return;

var step = state.step;
var typeInfo = (0, _getTypeInfo2.default)(options.schema, token.state);
// Given a Schema and a Token, produce the contents of an info tooltip.
var typeInfo = (0, _getTypeInfo["default"])(options.schema, token.state); // Given a Schema and a Token, produce the contents of an info tooltip.
// To do this, create a div element that we will render "into" and then pass
// it to various rendering functions.
if (kind === 'Field' && step === 0 && typeInfo.fieldDef || kind === 'AliasedField' && step === 2 && typeInfo.fieldDef) {

@@ -55,2 +59,3 @@ var into = document.createElement('div');

var _into = document.createElement('div');
renderDirective(_into, typeInfo, options);

@@ -61,2 +66,3 @@ renderDescription(_into, options, typeInfo.directiveDef);

var _into2 = document.createElement('div');
renderArg(_into2, typeInfo, options);

@@ -67,2 +73,3 @@ renderDescription(_into2, options, typeInfo.argDef);

var _into3 = document.createElement('div');
renderEnumValue(_into3, typeInfo, options);

@@ -73,2 +80,3 @@ renderDescription(_into3, options, typeInfo.enumValue);

var _into4 = document.createElement('div');
renderType(_into4, typeInfo, options, typeInfo.type);

@@ -79,10 +87,2 @@ renderDescription(_into4, options, typeInfo.type);

});
/**
* Copyright (c) 2017, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

@@ -96,2 +96,3 @@ function renderField(into, typeInfo, options) {

var fieldName = typeInfo.fieldDef.name;
if (fieldName.slice(0, 2) !== '__') {

@@ -101,2 +102,3 @@ renderType(into, typeInfo, options, typeInfo.parentType);

}
text(into, fieldName, 'field-name', options, (0, _SchemaReference.getFieldReference)(typeInfo));

@@ -151,5 +153,7 @@ }

var description = def.description;
if (description) {
var descriptionDiv = document.createElement('div');
descriptionDiv.className = 'info-description';
if (options.renderDescription) {

@@ -160,2 +164,3 @@ descriptionDiv.innerHTML = options.renderDescription(description);

}
into.appendChild(descriptionDiv);

@@ -169,5 +174,7 @@ }

var reason = def.deprecationReason;
if (reason) {
var deprecationDiv = document.createElement('div');
deprecationDiv.className = 'info-deprecation';
if (options.renderDescription) {

@@ -178,2 +185,3 @@ deprecationDiv.innerHTML = options.renderDescription(reason);

}
var label = document.createElement('span');

@@ -187,14 +195,25 @@ label.className = 'info-deprecation-label';

function text(into, content, className, options, ref) {
function text(into, content, className) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
onClick: null
};
var ref = arguments.length > 4 ? arguments[4] : undefined;
if (className) {
var onClick = options.onClick;
var node = document.createElement(onClick ? 'a' : 'span');
var node;
if (onClick) {
// Providing a href forces proper a tag behavior, though we don't actually
node = document.createElement('a'); // Providing a href forces proper a tag behavior, though we don't actually
// want clicking the node to navigate anywhere.
node.href = 'javascript:void 0'; // eslint-disable-line no-script-url
node.addEventListener('click', function (e) {
onClick(ref, e);
});
} else {
node = document.createElement('span');
}
node.className = className;

@@ -201,0 +220,0 @@ node.appendChild(document.createTextNode(content));

@@ -1,17 +0,25 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _getTypeInfo = _interopRequireDefault(require("./utils/getTypeInfo"));
var _getTypeInfo = require('./utils/getTypeInfo');
var _SchemaReference = require("./utils/SchemaReference");
var _getTypeInfo2 = _interopRequireDefault(_getTypeInfo);
require("./utils/jump-addon");
var _SchemaReference = require('./utils/SchemaReference');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
require('./utils/jump-addon');
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*
*/
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -29,24 +37,14 @@ * Registers GraphQL "jump" links for CodeMirror.

*/
/**
* Copyright (c) 2017, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
_codemirror2.default.registerHelper('jump', 'graphql', function (token, options) {
_codemirror["default"].registerHelper('jump', 'graphql', function (token, options) {
if (!options.schema || !options.onClick || !token.state) {
return;
}
// Given a Schema and a Token, produce a "SchemaReference" which refers to
} // Given a Schema and a Token, produce a "SchemaReference" which refers to
// the particular artifact from the schema (such as a type, field, argument,
// or directive) that token references.
var state = token.state;
var kind = state.kind;
var step = state.step;
var typeInfo = (0, _getTypeInfo2.default)(options.schema, state);
var typeInfo = (0, _getTypeInfo["default"])(options.schema, state);

@@ -53,0 +51,0 @@ if (kind === 'Field' && step === 0 && typeInfo.fieldDef || kind === 'AliasedField' && step === 2 && typeInfo.fieldDef) {

@@ -1,13 +0,11 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _graphqlLanguageServiceInterface = require("graphql-language-service-interface");
var _graphqlLanguageServiceInterface = require('graphql-language-service-interface');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2015, Facebook, Inc.
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.

@@ -19,3 +17,2 @@ *

*/
var SEVERITY = ['error', 'warning', 'information', 'hint'];

@@ -27,3 +24,2 @@ var TYPE = {

};
/**

@@ -43,6 +39,6 @@ * Registers a "lint" helper for CodeMirror.

*/
_codemirror2.default.registerHelper('lint', 'graphql', function (text, options) {
_codemirror["default"].registerHelper('lint', 'graphql', function (text, options) {
var schema = options.schema;
var rawResults = (0, _graphqlLanguageServiceInterface.getDiagnostics)(text, schema);
var results = rawResults.map(function (error) {

@@ -53,8 +49,7 @@ return {

type: TYPE[error.source],
from: _codemirror2.default.Pos(error.range.start.line, error.range.start.character),
to: _codemirror2.default.Pos(error.range.end.line, error.range.end.character)
from: _codemirror["default"].Pos(error.range.start.line, error.range.start.character),
to: _codemirror["default"].Pos(error.range.end.line, error.range.end.character)
};
});
return results;
});

@@ -1,10 +0,17 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _graphqlLanguageServiceParser = require("graphql-language-service-parser");
var _graphqlLanguageServiceParser = require('graphql-language-service-parser');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

@@ -31,12 +38,3 @@ /**

*/
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
_codemirror2.default.defineMode('graphql', function (config) {
_codemirror["default"].defineMode('graphql', function (config) {
var parser = (0, _graphqlLanguageServiceParser.onlineParser)({

@@ -48,5 +46,6 @@ eatWhitespace: function eatWhitespace(stream) {

parseRules: _graphqlLanguageServiceParser.ParseRules,
editorConfig: { tabSize: config.tabSize }
editorConfig: {
tabSize: config.tabSize
}
});
return {

@@ -68,7 +67,7 @@ config: config,

function indent(state, textAfter) {
var levels = state.levels;
// If there is no stack of levels, use the current level.
var levels = state.levels; // If there is no stack of levels, use the current level.
// Otherwise, use the top level, pre-emptively dedenting for close braces.
var level = !levels || levels.length === 0 ? state.indentLevel : levels[levels.length - 1] - (this.electricInput.test(textAfter) ? 1 : 0);
return level * this.config.indentUnit;
}
{
"name": "codemirror-graphql",
"version": "0.8.3",
"version": "0.9.0",
"description": "GraphQL mode and helpers for CodeMirror.",

@@ -10,11 +10,8 @@ "contributors": [

],
"homepage": "https://github.com/graphql/codemirror-graphql",
"homepage": "https://github.com/graphql/graphiql/tree/master/packages/codemirror-graphql#readme",
"repository": "https://github.com/graphql/graphiql/tree/master/packages/codemirror-graphql",
"bugs": {
"url": "https://github.com/graphql/codemirror-graphql/issues"
"url": "https://github.com/graphql/graphiql/issues?q=issue+label:codemirror-graphql"
},
"repository": {
"type": "git",
"url": "http://github.com/graphql/codemirror-graphql.git"
},
"license": "BSD-3-Clause",
"license": "MIT",
"files": [

@@ -32,64 +29,29 @@ "hint.js",

],
"options": {
"mocha": "--full-trace --require resources/mocha-bootload src/**/__tests__/**/*-test.js",
"mocha_tdd": "--full-trace --watch --require resources/mocha-bootload src/**/__tests__/**/*-test.js"
},
"scripts": {
"test": "npm run lint && npm run pretty-check && npm run testonly",
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
"testwatch": "babel-node --inspect ./node_modules/.bin/_mocha $npm_package_options_mocha_tdd",
"lint": "eslint src",
"check": "flow check",
"build": "babel src --ignore __tests__ --out-dir .",
"build": "babel src --root-mode upward --ignore __tests__ --out-dir .",
"build-js": "node ../../resources/buildJs.js",
"build-flow": "node ../../resources/buildFlow.js",
"watch": "babel --optional runtime resources/watch.js | node",
"pretty": "node resources/pretty.js",
"pretty-check": "node resources/pretty.js --check",
"preversion": ". ./resources/checkgit.sh && npm test",
"prepublish": ". ./resources/prepublish.sh"
"preversion": ". ./resources/checkgit.sh && yarn test",
"prepublish": "node ../../resources/prepublish"
},
"peerDependencies": {
"codemirror": "^5.26.0",
"graphql": "^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0"
},
"dependencies": {
"graphql-language-service-interface": "^1.3.2",
"graphql-language-service-parser": "^1.2.2"
"graphql-language-service-interface": "^2.1.0",
"graphql-language-service-parser": "^1.3.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "7.2.3",
"babel-plugin-check-es2015-constants": "^6.22.0",
"babel-plugin-syntax-async-functions": "6.13.0",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.22.0",
"babel-plugin-transform-es2015-block-scoping": "^6.26.0",
"babel-plugin-transform-es2015-classes": "6.24.1",
"babel-plugin-transform-es2015-computed-properties": "6.24.1",
"babel-plugin-transform-es2015-destructuring": "6.23.0",
"babel-plugin-transform-es2015-duplicate-keys": "6.24.1",
"babel-plugin-transform-es2015-function-name": "6.24.1",
"babel-plugin-transform-es2015-literals": "^6.22.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-es2015-object-super": "6.24.1",
"babel-plugin-transform-es2015-parameters": "6.24.1",
"babel-plugin-transform-es2015-shorthand-properties": "6.24.1",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-es2015-template-literals": "6.22.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"chai": "4.1.1",
"chai-subset": "1.5.0",
"codemirror": "^5.28.0",
"eslint": "^4.5.0",
"eslint-plugin-babel": "4.1.2",
"eslint-plugin-flowtype": "2.35.0",
"flow-bin": "^0.56.0",
"graphql": "^14.0.2",
"jsdom": "^11.2.0",
"mocha": "3.5.0",
"prettier": "^1.4.4",
"sane": "2.0.0"
}
}
GraphQL mode for CodeMirror
===========================
[![NPM](https://img.shields.io/npm/v/codemirror-graphql.svg?style=flat-square)](https://npmjs.com/codemirror-graphql)
[![License](https://img.shields.io/npm/l/codemirror-graphql.svg?style=flat-square)](LICENSE)
[![Build Status](https://travis-ci.org/graphql/codemirror-graphql.svg?branch=master)](https://travis-ci.org/graphql/codemirror-graphql)
Provides CodeMirror with a parser mode for GraphQL along with a live linter and
typeahead hinter powered by your GraphQL Schema.
![](resources/example.gif)
![Demo .gif of GraphQL Codemirror Mode](resources/example.gif)

@@ -11,0 +11,0 @@ ### Getting Started

@@ -1,17 +0,11 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _graphqlLanguageServiceParser = require("graphql-language-service-parser");
var _graphqlLanguageServiceParser = require('graphql-language-service-parser');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* This mode defines JSON, but provides a data-laden parser state to enable
* better code intelligence.
*/
/**
* Copyright (c) 2015, Facebook, Inc.
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.

@@ -24,3 +18,7 @@ *

_codemirror2.default.defineMode('graphql-results', function (config) {
/**
* This mode defines JSON, but provides a data-laden parser state to enable
* better code intelligence.
*/
_codemirror["default"].defineMode('graphql-results', function (config) {
var parser = (0, _graphqlLanguageServiceParser.onlineParser)({

@@ -32,5 +30,6 @@ eatWhitespace: function eatWhitespace(stream) {

parseRules: ParseRules,
editorConfig: { tabSize: config.tabSize }
editorConfig: {
tabSize: config.tabSize
}
});
return {

@@ -51,29 +50,27 @@ config: config,

function indent(state, textAfter) {
var levels = state.levels;
// If there is no stack of levels, use the current level.
var levels = state.levels; // If there is no stack of levels, use the current level.
// Otherwise, use the top level, pre-emptively dedenting for close braces.
var level = !levels || levels.length === 0 ? state.indentLevel : levels[levels.length - 1] - (this.electricInput.test(textAfter) ? 1 : 0);
return level * this.config.indentUnit;
}
/**
* The lexer rules. These are exactly as described by the spec.
*/
var LexRules = {
// All Punctuation used in JSON.
Punctuation: /^\[|]|\{|\}|:|,/,
// JSON Number.
Number: /^-?(?:0|(?:[1-9][0-9]*))(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?/,
// JSON String.
String: /^"(?:[^"\\]|\\(?:"|\/|\\|b|f|n|r|t|u[0-9a-fA-F]{4}))*"?/,
// JSON literal keywords.
Keyword: /^true|false|null/
};
/**
* The parser rules for JSON.
*/
var ParseRules = {

@@ -86,4 +83,6 @@ Document: [(0, _graphqlLanguageServiceParser.p)('{'), (0, _graphqlLanguageServiceParser.list)('Entry', (0, _graphqlLanguageServiceParser.p)(',')), (0, _graphqlLanguageServiceParser.p)('}')],

return 'NumberValue';
case 'String':
return 'StringValue';
case 'Punctuation':

@@ -93,6 +92,9 @@ switch (token.value) {

return 'ListValue';
case '{':
return 'ObjectValue';
}
return null;
case 'Keyword':

@@ -103,9 +105,10 @@ switch (token.value) {

return 'BooleanValue';
case 'null':
return 'NullValue';
}
return null;
}
},
NumberValue: [(0, _graphqlLanguageServiceParser.t)('Number', 'number')],

@@ -112,0 +115,0 @@ StringValue: [(0, _graphqlLanguageServiceParser.t)('String', 'string')],

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,7 +6,16 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = collectVariables;
exports["default"] = collectVariables;
var _graphql = require('graphql');
var _graphql = require("graphql");
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/**
* Provided a schema and a document, produces a `variableToType` Object.

@@ -19,2 +28,3 @@ */

var variableDefinitions = definition.variableDefinitions;
if (variableDefinitions) {

@@ -24,4 +34,4 @@ variableDefinitions.forEach(function (_ref) {

type = _ref.type;
var inputType = (0, _graphql.typeFromAST)(schema, type);
var inputType = (0, _graphql.typeFromAST)(schema, type);
if (inputType) {

@@ -35,9 +45,2 @@ variableToType[variable.name.value] = inputType;

return variableToType;
} /**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
}

@@ -6,5 +6,6 @@ "use strict";

});
exports.default = forEachState;
exports["default"] = forEachState;
/**
* Copyright (c) 2015, Facebook, Inc.
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.

@@ -16,3 +17,2 @@ *

*/
// Utility for iterating through a CodeMirror parse state stack bottom-up.

@@ -22,2 +22,3 @@ function forEachState(stack, fn) {

var state = stack;
while (state && state.kind) {

@@ -27,2 +28,3 @@ reverseStateStack.push(state);

}
for (var i = reverseStateStack.length - 1; i >= 0; i--) {

@@ -29,0 +31,0 @@ fn(reverseStateStack[i]);

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,13 +6,20 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = getTypeInfo;
exports["default"] = getTypeInfo;
var _graphql = require('graphql');
var _graphql = require("graphql");
var _introspection = require('graphql/type/introspection');
var _introspection = require("graphql/type/introspection");
var _forEachState = require('./forEachState');
var _forEachState = _interopRequireDefault(require("./forEachState"));
var _forEachState2 = _interopRequireDefault(_forEachState);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

@@ -35,4 +42,3 @@ /**

};
(0, _forEachState2.default)(tokenState, function (state) {
(0, _forEachState["default"])(tokenState, function (state) {
switch (state.kind) {

@@ -43,8 +49,11 @@ case 'Query':

break;
case 'Mutation':
info.type = schema.getMutationType();
break;
case 'Subscription':
info.type = schema.getSubscriptionType();
break;
case 'InlineFragment':

@@ -55,3 +64,5 @@ case 'FragmentDefinition':

}
break;
case 'Field':

@@ -62,8 +73,11 @@ case 'AliasedField':

break;
case 'SelectionSet':
info.parentType = (0, _graphql.getNamedType)(info.type);
break;
case 'Directive':
info.directiveDef = state.name && schema.getDirective(state.name);
break;
case 'Arguments':

@@ -73,4 +87,6 @@ var parentDef = state.prevState.kind === 'Field' ? info.fieldDef : state.prevState.kind === 'Directive' ? info.directiveDef : state.prevState.kind === 'AliasedField' ? state.prevState.name && getFieldDef(schema, info.parentType, state.prevState.name) : null;

break;
case 'Argument':
info.argDef = null;
if (info.argDefs) {

@@ -84,4 +100,6 @@ for (var i = 0; i < info.argDefs.length; i++) {

}
info.inputType = info.argDef && info.argDef.type;
break;
case 'EnumValue':

@@ -93,2 +111,3 @@ var enumType = (0, _graphql.getNamedType)(info.inputType);

break;
case 'ListValue':

@@ -98,2 +117,3 @@ var nullableType = (0, _graphql.getNullableType)(info.inputType);

break;
case 'ObjectValue':

@@ -103,2 +123,3 @@ var objectType = (0, _graphql.getNamedType)(info.inputType);

break;
case 'ObjectField':

@@ -108,2 +129,3 @@ var objectField = state.name && info.objectFieldDefs ? info.objectFieldDefs[state.name] : null;

break;
case 'NamedType':

@@ -114,15 +136,5 @@ info.type = schema.getType(state.name);

});
return info;
}
} // Gets the field definition given a type and field name
// Gets the field definition given a type and field name
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

@@ -133,14 +145,17 @@ function getFieldDef(schema, type, fieldName) {

}
if (fieldName === _introspection.TypeMetaFieldDef.name && schema.getQueryType() === type) {
return _introspection.TypeMetaFieldDef;
}
if (fieldName === _introspection.TypeNameMetaFieldDef.name && (0, _graphql.isCompositeType)(type)) {
return _introspection.TypeNameMetaFieldDef;
}
if (type.getFields) {
return type.getFields()[fieldName];
}
}
} // Returns the first item in the array which causes predicate to return truthy.
// Returns the first item in the array which causes predicate to return truthy.
function find(array, predicate) {

@@ -147,0 +162,0 @@ for (var i = 0; i < array.length; i++) {

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,6 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = hintList;
exports["default"] = hintList;
/**
* Copyright (c) 2015, Facebook, Inc.
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.

@@ -16,6 +17,6 @@ *

*/
// Create the expected hint response given a possible list and a token
function hintList(cursor, token, list) {
var hints = filterAndSortList(list, normalizeText(token.string));
if (!hints) {

@@ -26,12 +27,17 @@ return;

var tokenStart = token.type !== null && /"|\w/.test(token.string[0]) ? token.start : token.end;
return {
list: hints,
from: { line: cursor.line, column: tokenStart },
to: { line: cursor.line, column: token.end }
from: {
line: cursor.line,
column: tokenStart
},
to: {
line: cursor.line,
column: token.end
}
};
}
} // Given a list of hint entries and currently typed text, sort and filter to
// provide a concise list.
// Given a list of hint entries and currently typed text, sort and filter to
// provide a concise list.
function filterAndSortList(list, text) {

@@ -50,3 +56,2 @@ if (!text) {

});
var conciseMatches = filterNonEmpty(filterNonEmpty(byProximity, function (pair) {

@@ -57,14 +62,12 @@ return pair.proximity <= 2;

});
var sortedMatches = conciseMatches.sort(function (a, b) {
return (a.entry.isDeprecated ? 1 : 0) - (b.entry.isDeprecated ? 1 : 0) || a.proximity - b.proximity || a.entry.text.length - b.entry.text.length;
});
return sortedMatches.map(function (pair) {
return pair.entry;
});
}
} // Filters the array by the predicate, unless it results in an empty array,
// in which case return the original array.
// Filters the array by the predicate, unless it results in an empty array,
// in which case return the original array.
function filterNonEmpty(array, predicate) {

@@ -77,17 +80,18 @@ var filtered = array.filter(predicate);

return text.toLowerCase().replace(/\W/g, '');
}
} // Determine a numeric proximity for a suggestion based on current text.
// Determine a numeric proximity for a suggestion based on current text.
function getProximity(suggestion, text) {
// start with lexical distance
var proximity = lexicalDistance(text, suggestion);
if (suggestion.length > text.length) {
// do not penalize long suggestions.
proximity -= suggestion.length - text.length - 1;
// penalize suggestions not starting with this phrase
proximity -= suggestion.length - text.length - 1; // penalize suggestions not starting with this phrase
proximity += suggestion.indexOf(text) === 0 ? 0 : 0.5;
}
return proximity;
}
/**

@@ -107,5 +111,7 @@ * Computes the lexical distance between strings A and B.

*/
function lexicalDistance(a, b) {
var i = void 0;
var j = void 0;
var i;
var j;
var d = [];

@@ -126,3 +132,2 @@ var aLength = a.length;

var cost = a[i - 1] === b[j - 1] ? 0 : 1;
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);

@@ -129,0 +134,0 @@

@@ -1,13 +0,21 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
_codemirror["default"].defineOption('info', false, function (cm, options, old) {
if (old && old !== _codemirror["default"].Init) {
var oldOnMouseOver = cm.state.info.onMouseOver;
_codemirror2.default.defineOption('info', false, function (cm, options, old) {
if (old && old !== _codemirror2.default.Init) {
var oldOnMouseOver = cm.state.info.onMouseOver;
_codemirror2.default.off(cm.getWrapperElement(), 'mouseover', oldOnMouseOver);
_codemirror["default"].off(cm.getWrapperElement(), 'mouseover', oldOnMouseOver);
clearTimeout(cm.state.info.hoverTimeout);

@@ -20,16 +28,12 @@ delete cm.state.info;

state.onMouseOver = onMouseOver.bind(null, cm);
_codemirror2.default.on(cm.getWrapperElement(), 'mouseover', state.onMouseOver);
_codemirror["default"].on(cm.getWrapperElement(), 'mouseover', state.onMouseOver);
}
}); /**
* Copyright (c) 2017, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
});
function createState(options) {
return {
options: options instanceof Function ? { render: options } : options === true ? {} : options
options: options instanceof Function ? {
render: options
} : options === true ? {} : options
};

@@ -45,4 +49,4 @@ }

var state = cm.state.info;
var target = e.target || e.srcElement;
var target = e.target || e.srcElement;
if (target.nodeName !== 'SPAN' || state.hoverTimeout !== undefined) {

@@ -53,3 +57,2 @@ return;

var box = target.getBoundingClientRect();
var hoverTime = getHoverTime(cm);

@@ -64,4 +67,6 @@ state.hoverTimeout = setTimeout(onHover, hoverTime);

var onMouseOut = function onMouseOut() {
_codemirror2.default.off(document, 'mousemove', onMouseMove);
_codemirror2.default.off(cm.getWrapperElement(), 'mouseout', onMouseOut);
_codemirror["default"].off(document, 'mousemove', onMouseMove);
_codemirror["default"].off(cm.getWrapperElement(), 'mouseout', onMouseOut);
clearTimeout(state.hoverTimeout);

@@ -72,4 +77,6 @@ state.hoverTimeout = undefined;

var onHover = function onHover() {
_codemirror2.default.off(document, 'mousemove', onMouseMove);
_codemirror2.default.off(cm.getWrapperElement(), 'mouseout', onMouseOut);
_codemirror["default"].off(document, 'mousemove', onMouseMove);
_codemirror["default"].off(cm.getWrapperElement(), 'mouseout', onMouseOut);
state.hoverTimeout = undefined;

@@ -79,4 +86,5 @@ onMouseHover(cm, box);

_codemirror2.default.on(document, 'mousemove', onMouseMove);
_codemirror2.default.on(cm.getWrapperElement(), 'mouseout', onMouseOut);
_codemirror["default"].on(document, 'mousemove', onMouseMove);
_codemirror["default"].on(cm.getWrapperElement(), 'mouseout', onMouseOut);
}

@@ -89,10 +97,12 @@

});
var state = cm.state.info;
var options = state.options;
var render = options.render || cm.getHelper(pos, 'info');
if (render) {
var token = cm.getTokenAt(pos, true);
if (token) {
var info = render(token, options, cm, pos);
if (info) {

@@ -110,3 +120,2 @@ showPopup(cm, box, info);

document.body.appendChild(popup);
var popupBox = popup.getBoundingClientRect();

@@ -116,4 +125,4 @@ var popupStyle = popup.currentStyle || window.getComputedStyle(popup);

var popupHeight = popupBox.bottom - popupBox.top + parseFloat(popupStyle.marginTop) + parseFloat(popupStyle.marginBottom);
var topPos = box.bottom;
var topPos = box.bottom;
if (popupHeight > window.innerHeight - box.bottom - 15 && box.top > window.innerHeight - box.bottom) {

@@ -128,2 +137,3 @@ topPos = box.top - popupHeight;

var leftPos = Math.max(0, window.innerWidth - popupWidth - 15);
if (leftPos > box.left) {

@@ -136,5 +146,4 @@ leftPos = box.left;

popup.style.left = leftPos + 'px';
var popupTimeout;
var popupTimeout = void 0;
var onMouseOverPopup = function onMouseOverPopup() {

@@ -150,6 +159,8 @@ clearTimeout(popupTimeout);

var hidePopup = function hidePopup() {
_codemirror2.default.off(popup, 'mouseover', onMouseOverPopup);
_codemirror2.default.off(popup, 'mouseout', onMouseOut);
_codemirror2.default.off(cm.getWrapperElement(), 'mouseout', onMouseOut);
_codemirror["default"].off(popup, 'mouseover', onMouseOverPopup);
_codemirror["default"].off(popup, 'mouseout', onMouseOut);
_codemirror["default"].off(cm.getWrapperElement(), 'mouseout', onMouseOut);
if (popup.style.opacity) {

@@ -167,5 +178,7 @@ popup.style.opacity = 0;

_codemirror2.default.on(popup, 'mouseover', onMouseOverPopup);
_codemirror2.default.on(popup, 'mouseout', onMouseOut);
_codemirror2.default.on(cm.getWrapperElement(), 'mouseout', onMouseOut);
_codemirror["default"].on(popup, 'mouseover', onMouseOverPopup);
_codemirror["default"].on(popup, 'mouseout', onMouseOut);
_codemirror["default"].on(cm.getWrapperElement(), 'mouseout', onMouseOut);
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,5 +6,6 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = jsonParse;
exports["default"] = jsonParse;
/**
* Copyright (c) 2015, Facebook, Inc.
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.

@@ -40,9 +41,9 @@ *

var string = void 0;
var strLen = void 0;
var start = void 0;
var end = void 0;
var lastEnd = void 0;
var code = void 0;
var kind = void 0;
var string;
var strLen;
var start;
var end;
var lastEnd;
var code;
var kind;

@@ -53,2 +54,3 @@ function parseObj() {

expect('{');
if (!skip('}')) {

@@ -58,4 +60,6 @@ do {

} while (skip(','));
expect('}');
}
return {

@@ -88,2 +92,3 @@ kind: 'Object',

expect('[');
if (!skip(']')) {

@@ -93,4 +98,6 @@ do {

} while (skip(','));
expect(']');
}
return {

@@ -108,4 +115,6 @@ kind: 'Array',

return parseArr();
case '{':
return parseObj();
case 'String':

@@ -119,2 +128,3 @@ case 'Number':

}
return expect('Value');

@@ -124,3 +134,8 @@ }

function curToken() {
return { kind: kind, start: start, end: end, value: JSON.parse(string.slice(start, end)) };
return {
kind: kind,
start: start,
end: end,
value: JSON.parse(string.slice(start, end))
};
}

@@ -134,3 +149,4 @@

var found = void 0;
var found;
if (kind === 'EOF') {

@@ -145,7 +161,11 @@ found = '[end of file]';

throw syntaxError('Expected ' + str + ' but found ' + found + '.');
throw syntaxError("Expected ".concat(str, " but found ").concat(found, "."));
}
function syntaxError(message) {
return { message: message, start: start, end: end };
return {
message: message,
start: start,
end: end
};
}

@@ -187,2 +207,3 @@

// -, 0-9
case 45:

@@ -202,2 +223,3 @@ case 48:

// f
case 102:

@@ -207,8 +229,9 @@ if (string.slice(start, start + 5) !== 'false') {

}
end += 4;
ch();
kind = 'Boolean';
return;
// n
case 110:

@@ -218,8 +241,9 @@ if (string.slice(start, start + 4) !== 'null') {

}
end += 3;
ch();
kind = 'Null';
return;
// t
case 116:

@@ -229,5 +253,5 @@ if (string.slice(start, start + 4) !== 'true') {

}
end += 3;
ch();
kind = 'Boolean';

@@ -243,2 +267,3 @@ return;

ch();
while (code !== 34 && code > 31) {

@@ -248,10 +273,18 @@ if (code === 92) {

ch();
switch (code) {
case 34: // "
case 47: // /
case 92: // \
case 98: // b
case 102: // f
case 110: // n
case 114: // r
case 116:

@@ -261,2 +294,3 @@ // t

break;
case 117:

@@ -270,2 +304,3 @@ // u

break;
default:

@@ -296,2 +331,3 @@ throw syntaxError('Bad character escape sequence.');

}
throw syntaxError('Expected hexadecimal digit.');

@@ -322,2 +358,3 @@ }

ch();
if (code === 43 || code === 45) {

@@ -327,2 +364,3 @@ // + -

}
readDigits();

@@ -337,5 +375,7 @@ }

}
do {
ch();
} while (code >= 48 && code <= 57); // 0 - 9
}

@@ -1,16 +0,27 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
_codemirror["default"].defineOption('jump', false, function (cm, options, old) {
if (old && old !== _codemirror["default"].Init) {
var oldOnMouseOver = cm.state.jump.onMouseOver;
_codemirror2.default.defineOption('jump', false, function (cm, options, old) {
if (old && old !== _codemirror2.default.Init) {
var oldOnMouseOver = cm.state.jump.onMouseOver;
_codemirror2.default.off(cm.getWrapperElement(), 'mouseover', oldOnMouseOver);
_codemirror["default"].off(cm.getWrapperElement(), 'mouseover', oldOnMouseOver);
var oldOnMouseOut = cm.state.jump.onMouseOut;
_codemirror2.default.off(cm.getWrapperElement(), 'mouseout', oldOnMouseOut);
_codemirror2.default.off(document, 'keydown', cm.state.jump.onKeyDown);
_codemirror["default"].off(cm.getWrapperElement(), 'mouseout', oldOnMouseOut);
_codemirror["default"].off(document, 'keydown', cm.state.jump.onKeyDown);
delete cm.state.jump;

@@ -27,17 +38,13 @@ }

_codemirror2.default.on(cm.getWrapperElement(), 'mouseover', state.onMouseOver);
_codemirror2.default.on(cm.getWrapperElement(), 'mouseout', state.onMouseOut);
_codemirror2.default.on(document, 'keydown', state.onKeyDown);
_codemirror["default"].on(cm.getWrapperElement(), 'mouseover', state.onMouseOver);
_codemirror["default"].on(cm.getWrapperElement(), 'mouseout', state.onMouseOut);
_codemirror["default"].on(document, 'keydown', state.onKeyDown);
}
}); /**
* Copyright (c) 2017, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
});
function onMouseOver(cm, event) {
var target = event.target || event.srcElement;
if (target.nodeName !== 'SPAN') {

@@ -52,3 +59,2 @@ return;

};
cm.state.jump.cursor = cursor;

@@ -94,4 +100,6 @@

_codemirror2.default.off(document, 'keyup', onKeyUp);
_codemirror2.default.off(document, 'click', onClick);
_codemirror["default"].off(document, 'keyup', onKeyUp);
_codemirror["default"].off(document, 'click', onClick);
cm.off('mousedown', onMouseDown);

@@ -102,2 +110,3 @@ };

var destination = cm.state.jump.destination;
if (destination) {

@@ -114,4 +123,6 @@ cm.state.jump.options.onClick(destination, clickEvent);

_codemirror2.default.on(document, 'keyup', onKeyUp);
_codemirror2.default.on(document, 'click', onClick);
_codemirror["default"].on(document, 'keyup', onKeyUp);
_codemirror["default"].on(document, 'click', onClick);
cm.on('mousedown', onMouseDown);

@@ -134,10 +145,18 @@ }

var token = cm.getTokenAt(pos, true);
var options = cm.state.jump.options;
var getDestination = options.getDestination || cm.getHelper(pos, 'jump');
if (getDestination) {
var destination = getDestination(token, options, cm);
if (destination) {
var marker = cm.markText({ line: pos.line, ch: token.start }, { line: pos.line, ch: token.end }, { className: 'CodeMirror-jump-token' });
var marker = cm.markText({
line: pos.line,
ch: token.start
}, {
line: pos.line,
ch: token.end
}, {
className: 'CodeMirror-jump-token'
});
cm.state.jump.marker = marker;

@@ -153,4 +172,3 @@ cm.state.jump.destination = destination;

cm.state.jump.destination = null;
marker.clear();
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,6 +6,14 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = runParser;
exports["default"] = runParser;
var _graphqlLanguageServiceParser = require('graphql-language-service-parser');
var _graphqlLanguageServiceParser = require("graphql-language-service-parser");
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function runParser(sourceText, parserOptions, callbackFn) {

@@ -15,5 +23,5 @@ var parser = (0, _graphqlLanguageServiceParser.onlineParser)(parserOptions);

var lines = sourceText.split('\n');
lines.forEach(function (line) {
var stream = new _graphqlLanguageServiceParser.CharacterStream(line);
while (!stream.eol()) {

@@ -24,9 +32,2 @@ var style = parser.token(stream, state);

});
} /**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
}

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -12,4 +12,12 @@ Object.defineProperty(exports, "__esModule", {

var _graphql = require('graphql');
var _graphql = require("graphql");
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function getFieldReference(typeInfo) {

@@ -23,10 +31,2 @@ return {

}
/**
* Copyright (c), Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

@@ -60,8 +60,9 @@ function getDirectiveReference(typeInfo) {

value: typeInfo.enumValue,
// $FlowFixMe
type: (0, _graphql.getNamedType)(typeInfo.inputType)
};
}
} // Note: for reusability, getTypeReference can produce a reference to any type,
// though it defaults to the current type.
// Note: for reusability, getTypeReference can produce a reference to any type,
// though it defaults to the current type.
function getTypeReference(typeInfo, type) {

@@ -68,0 +69,0 @@ return {

@@ -1,19 +0,22 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _graphql = require("graphql");
var _graphql = require('graphql');
var _forEachState = _interopRequireDefault(require("../utils/forEachState"));
var _forEachState = require('../utils/forEachState');
var _hintList = _interopRequireDefault(require("../utils/hintList"));
var _forEachState2 = _interopRequireDefault(_forEachState);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _hintList = require('../utils/hintList');
/**
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var _hintList2 = _interopRequireDefault(_hintList);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -36,20 +39,12 @@ * Registers a "hint" helper for CodeMirror.

*/
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
_codemirror2.default.registerHelper('hint', 'graphql-variables', function (editor, options) {
_codemirror["default"].registerHelper('hint', 'graphql-variables', function (editor, options) {
var cur = editor.getCursor();
var token = editor.getTokenAt(cur);
var results = getVariablesHint(cur, token, options);
var results = getVariablesHint(cur, token, options);
if (results && results.list && results.list.length > 0) {
results.from = _codemirror2.default.Pos(results.from.line, results.from.column);
results.to = _codemirror2.default.Pos(results.to.line, results.to.column);
_codemirror2.default.signal(editor, 'hasCompletion', editor, results, token);
results.from = _codemirror["default"].Pos(results.from.line, results.from.column);
results.to = _codemirror["default"].Pos(results.to.line, results.to.column);
_codemirror["default"].signal(editor, 'hasCompletion', editor, results, token);
}

@@ -63,12 +58,13 @@

var state = token.state.kind === 'Invalid' ? token.state.prevState : token.state;
var kind = state.kind;
var step = state.step;
var step = state.step; // Variables can only be an object literal.
// Variables can only be an object literal.
if (kind === 'Document' && step === 0) {
return (0, _hintList2.default)(cur, token, [{ text: '{' }]);
return (0, _hintList["default"])(cur, token, [{
text: '{'
}]);
}
var variableToType = options.variableToType;
if (!variableToType) {

@@ -78,16 +74,15 @@ return;

var typeInfo = getTypeInfo(variableToType, token.state);
var typeInfo = getTypeInfo(variableToType, token.state); // Top level should typeahead possible variables.
// Top level should typeahead possible variables.
if (kind === 'Document' || kind === 'Variable' && step === 0) {
var variableNames = Object.keys(variableToType);
return (0, _hintList2.default)(cur, token, variableNames.map(function (name) {
return (0, _hintList["default"])(cur, token, variableNames.map(function (name) {
return {
text: '"' + name + '": ',
text: "\"".concat(name, "\": "),
type: variableToType[name]
};
}));
}
} // Input Object fields
// Input Object fields
if (kind === 'ObjectValue' || kind === 'ObjectField' && step === 0) {

@@ -98,5 +93,5 @@ if (typeInfo.fields) {

});
return (0, _hintList2.default)(cur, token, inputFields.map(function (field) {
return (0, _hintList["default"])(cur, token, inputFields.map(function (field) {
return {
text: '"' + field.name + '": ',
text: "\"".concat(field.name, "\": "),
type: field.type,

@@ -107,9 +102,12 @@ description: field.description

}
}
} // Input values.
// Input values.
if (kind === 'StringValue' || kind === 'NumberValue' || kind === 'BooleanValue' || kind === 'NullValue' || kind === 'ListValue' && step === 1 || kind === 'ObjectField' && step === 2 || kind === 'Variable' && step === 2) {
var namedInputType = (0, _graphql.getNamedType)(typeInfo.type);
if (namedInputType instanceof _graphql.GraphQLInputObjectType) {
return (0, _hintList2.default)(cur, token, [{ text: '{' }]);
return (0, _hintList["default"])(cur, token, [{
text: '{'
}]);
} else if (namedInputType instanceof _graphql.GraphQLEnumType) {

@@ -120,5 +118,5 @@ var valueMap = namedInputType.getValues();

});
return (0, _hintList2.default)(cur, token, values.map(function (value) {
return (0, _hintList["default"])(cur, token, values.map(function (value) {
return {
text: '"' + value.name + '"',
text: "\"".concat(value.name, "\""),
type: namedInputType,

@@ -129,9 +127,17 @@ description: value.description

} else if (namedInputType === _graphql.GraphQLBoolean) {
return (0, _hintList2.default)(cur, token, [{ text: 'true', type: _graphql.GraphQLBoolean, description: 'Not false.' }, { text: 'false', type: _graphql.GraphQLBoolean, description: 'Not true.' }]);
return (0, _hintList["default"])(cur, token, [{
text: 'true',
type: _graphql.GraphQLBoolean,
description: 'Not false.'
}, {
text: 'false',
type: _graphql.GraphQLBoolean,
description: 'Not true.'
}]);
}
}
}
} // Utility for collecting rich type information given any token's state
// from the graphql-variables-mode parser.
// Utility for collecting rich type information given any token's state
// from the graphql-variables-mode parser.
function getTypeInfo(variableToType, tokenState) {

@@ -142,4 +148,3 @@ var info = {

};
(0, _forEachState2.default)(tokenState, function (state) {
(0, _forEachState["default"])(tokenState, function (state) {
if (state.kind === 'Variable') {

@@ -158,4 +163,3 @@ info.type = variableToType[state.name];

});
return info;
}

@@ -1,15 +0,19 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _graphql = require("graphql");
var _graphql = require('graphql');
var _jsonParse = _interopRequireDefault(require("../utils/jsonParse"));
var _jsonParse = require('../utils/jsonParse');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _jsonParse2 = _interopRequireDefault(_jsonParse);
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**

@@ -27,12 +31,13 @@ * Registers a "lint" helper for CodeMirror.

*/
_codemirror2.default.registerHelper('lint', 'graphql-variables', function (text, options, editor) {
_codemirror["default"].registerHelper('lint', 'graphql-variables', function (text, options, editor) {
// If there's no text, do nothing.
if (!text) {
return [];
}
} // First, linter needs to determine if there are any parsing errors.
// First, linter needs to determine if there are any parsing errors.
var ast = void 0;
var ast;
try {
ast = (0, _jsonParse2.default)(text);
ast = (0, _jsonParse["default"])(text);
} catch (syntaxError) {

@@ -42,39 +47,32 @@ if (syntaxError.stack) {

}
return [lintError(editor, syntaxError, syntaxError.message)];
}
} // If there are not yet known variables, do nothing.
// If there are not yet known variables, do nothing.
var variableToType = options.variableToType;
if (!variableToType) {
return [];
}
} // Then highlight any issues with the provided variables.
// Then highlight any issues with the provided variables.
return validateVariables(editor, variableToType, ast);
});
// Given a variableToType object, a source text, and a JSON AST, produces a
}); // Given a variableToType object, a source text, and a JSON AST, produces a
// list of CodeMirror annotations for any variable validation errors.
/* eslint-disable max-len */
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function validateVariables(editor, variableToType, variablesAST) {
var errors = [];
variablesAST.members.forEach(function (member) {
var variableName = member.key.value;
var type = variableToType[variableName];
if (!type) {
errors.push(lintError(editor, member.key, 'Variable "$' + variableName + '" does not appear in any GraphQL query.'));
errors.push(lintError(editor, member.key, "Variable \"$".concat(variableName, "\" does not appear in any GraphQL query.")));
} else {
validateValue(type, member.value).forEach(function (_ref) {
var node = _ref[0],
message = _ref[1];
var _ref2 = _slicedToArray(_ref, 2),
node = _ref2[0],
message = _ref2[1];

@@ -85,7 +83,6 @@ errors.push(lintError(editor, node, message));

});
return errors;
}
} // Returns a list of validation errors in the form Array<[Node, String]>.
// Returns a list of validation errors in the form Array<[Node, String]>.
function validateValue(type, valueAST) {

@@ -95,4 +92,5 @@ // Validate non-nullable values.

if (valueAST.kind === 'Null') {
return [[valueAST, 'Type "' + type + '" is non-nullable and cannot be null.']];
return [[valueAST, "Type \"".concat(type, "\" is non-nullable and cannot be null.")]];
}
return validateValue(type.ofType, valueAST);

@@ -103,7 +101,8 @@ }

return [];
}
} // Validate lists of values, accepting a non-list as a list of one.
// Validate lists of values, accepting a non-list as a list of one.
if (type instanceof _graphql.GraphQLList) {
var itemType = type.ofType;
if (valueAST.kind === 'Array') {

@@ -114,12 +113,13 @@ return mapCat(valueAST.values, function (item) {

}
return validateValue(itemType, valueAST);
}
} // Validate input objects.
// Validate input objects.
if (type instanceof _graphql.GraphQLInputObjectType) {
if (valueAST.kind !== 'Object') {
return [[valueAST, 'Type "' + type + '" must be an Object.']];
}
return [[valueAST, "Type \"".concat(type, "\" must be an Object.")]];
} // Validate each field in the input object.
// Validate each field in the input object.
var providedFields = Object.create(null);

@@ -130,31 +130,32 @@ var fieldErrors = mapCat(valueAST.members, function (member) {

var inputField = type.getFields()[fieldName];
if (!inputField) {
return [[member.key, 'Type "' + type + '" does not have a field "' + fieldName + '".']];
return [[member.key, "Type \"".concat(type, "\" does not have a field \"").concat(fieldName, "\".")]];
}
var fieldType = inputField ? inputField.type : undefined;
return validateValue(fieldType, member.value);
});
}); // Look for missing non-nullable fields.
// Look for missing non-nullable fields.
Object.keys(type.getFields()).forEach(function (fieldName) {
if (!providedFields[fieldName]) {
var fieldType = type.getFields()[fieldName].type;
if (fieldType instanceof _graphql.GraphQLNonNull) {
fieldErrors.push([valueAST, 'Object of type "' + type + '" is missing required field "' + fieldName + '".']);
fieldErrors.push([valueAST, "Object of type \"".concat(type, "\" is missing required field \"").concat(fieldName, "\".")]);
}
}
});
return fieldErrors;
}
} // Validate common scalars.
// Validate common scalars.
if (type.name === 'Boolean' && valueAST.kind !== 'Boolean' || type.name === 'String' && valueAST.kind !== 'String' || type.name === 'ID' && valueAST.kind !== 'Number' && valueAST.kind !== 'String' || type.name === 'Float' && valueAST.kind !== 'Number' || type.name === 'Int' && (valueAST.kind !== 'Number' || (valueAST.value | 0) !== valueAST.value)) {
return [[valueAST, 'Expected value of type "' + type + '".']];
}
return [[valueAST, "Expected value of type \"".concat(type, "\".")]];
} // Validate enums and custom scalars.
// Validate enums and custom scalars.
if (type instanceof _graphql.GraphQLEnumType || type instanceof _graphql.GraphQLScalarType) {
if (valueAST.kind !== 'String' && valueAST.kind !== 'Number' && valueAST.kind !== 'Boolean' && valueAST.kind !== 'Null' || isNullish(type.parseValue(valueAST.value))) {
return [[valueAST, 'Expected value of type "' + type + '".']];
return [[valueAST, "Expected value of type \"".concat(type, "\".")]];
}

@@ -164,6 +165,6 @@ }

return [];
}
} // Give a parent text, an AST node with location, and a message, produces a
// CodeMirror annotation object.
// Give a parent text, an AST node with location, and a message, produces a
// CodeMirror annotation object.
function lintError(editor, node, message) {

@@ -170,0 +171,0 @@ return {

@@ -1,17 +0,11 @@

'use strict';
"use strict";
var _codemirror = require('codemirror');
var _codemirror = _interopRequireDefault(require("codemirror"));
var _codemirror2 = _interopRequireDefault(_codemirror);
var _graphqlLanguageServiceParser = require("graphql-language-service-parser");
var _graphqlLanguageServiceParser = require('graphql-language-service-parser');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* This mode defines JSON, but provides a data-laden parser state to enable
* better code intelligence.
*/
/**
* Copyright (c) 2015, Facebook, Inc.
* Copyright (c) 2019 GraphQL Contributors
* All rights reserved.

@@ -24,3 +18,7 @@ *

_codemirror2.default.defineMode('graphql-variables', function (config) {
/**
* This mode defines JSON, but provides a data-laden parser state to enable
* better code intelligence.
*/
_codemirror["default"].defineMode('graphql-variables', function (config) {
var parser = (0, _graphqlLanguageServiceParser.onlineParser)({

@@ -32,5 +30,6 @@ eatWhitespace: function eatWhitespace(stream) {

parseRules: ParseRules,
editorConfig: { tabSize: config.tabSize }
editorConfig: {
tabSize: config.tabSize
}
});
return {

@@ -51,29 +50,27 @@ config: config,

function indent(state, textAfter) {
var levels = state.levels;
// If there is no stack of levels, use the current level.
var levels = state.levels; // If there is no stack of levels, use the current level.
// Otherwise, use the top level, pre-emptively dedenting for close braces.
var level = !levels || levels.length === 0 ? state.indentLevel : levels[levels.length - 1] - (this.electricInput.test(textAfter) ? 1 : 0);
return level * this.config.indentUnit;
}
/**
* The lexer rules. These are exactly as described by the spec.
*/
var LexRules = {
// All Punctuation used in JSON.
Punctuation: /^\[|]|\{|\}|:|,/,
// JSON Number.
Number: /^-?(?:0|(?:[1-9][0-9]*))(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?/,
// JSON String.
String: /^"(?:[^"\\]|\\(?:"|\/|\\|b|f|n|r|t|u[0-9a-fA-F]{4}))*"?/,
// JSON literal keywords.
Keyword: /^true|false|null/
};
/**
* The parser rules for JSON.
*/
var ParseRules = {

@@ -86,4 +83,6 @@ Document: [(0, _graphqlLanguageServiceParser.p)('{'), (0, _graphqlLanguageServiceParser.list)('Variable', (0, _graphqlLanguageServiceParser.opt)((0, _graphqlLanguageServiceParser.p)(','))), (0, _graphqlLanguageServiceParser.p)('}')],

return 'NumberValue';
case 'String':
return 'StringValue';
case 'Punctuation':

@@ -93,6 +92,9 @@ switch (token.value) {

return 'ListValue';
case '{':
return 'ObjectValue';
}
return null;
case 'Keyword':

@@ -103,9 +105,10 @@ switch (token.value) {

return 'BooleanValue';
case 'null':
return 'NullValue';
}
return null;
}
},
NumberValue: [(0, _graphqlLanguageServiceParser.t)('Number', 'number')],

@@ -118,5 +121,4 @@ StringValue: [(0, _graphqlLanguageServiceParser.t)('String', 'string')],

ObjectField: [namedKey('attribute'), (0, _graphqlLanguageServiceParser.p)(':'), 'Value']
};
}; // A namedKey Token which will decorate the state with a `name`
// A namedKey Token which will decorate the state with a `name`
function namedKey(style) {

@@ -123,0 +125,0 @@ return {

Sorry, the diff of this file is not supported yet

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