Socket
Socket
Sign inDemoInstall

codemirror-graphql

Package Overview
Dependencies
1
Maintainers
10
Versions
243
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

2

esm/hint.js

@@ -5,3 +5,3 @@ import CodeMirror from 'codemirror';

CodeMirror.registerHelper('hint', 'graphql', (editor, options) => {
const schema = options.schema;
const { schema } = options;
if (!schema) {

@@ -8,0 +8,0 @@ return;

@@ -10,5 +10,3 @@ import { GraphQLList, GraphQLNonNull, } from 'graphql';

}
const state = token.state;
const kind = state.kind;
const step = state.step;
const { kind, step } = token.state;
const typeInfo = getTypeInfo(options.schema, token.state);

@@ -25,3 +23,3 @@ if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||

}
else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
const header = document.createElement('div');

@@ -35,3 +33,3 @@ header.className = 'CodeMirror-info-header';

}
else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
const header = document.createElement('div');

@@ -45,3 +43,3 @@ header.className = 'CodeMirror-info-header';

}
else if (kind === 'EnumValue' &&
if (kind === 'EnumValue' &&
typeInfo.enumValue &&

@@ -57,3 +55,3 @@ typeInfo.enumValue.description) {

}
else if (kind === 'NamedType' &&
if (kind === 'NamedType' &&
typeInfo.type &&

@@ -129,3 +127,3 @@ typeInfo.type.description) {

function renderDescription(into, options, def) {
const description = def.description;
const { description } = def;
if (description) {

@@ -167,3 +165,3 @@ const descriptionDiv = document.createElement('div');

if (className) {
const onClick = options.onClick;
const { onClick } = options;
let node;

@@ -170,0 +168,0 @@ if (onClick) {

@@ -9,5 +9,4 @@ import CodeMirror from 'codemirror';

}
const state = token.state;
const kind = state.kind;
const step = state.step;
const { state } = token;
const { kind, step } = state;
const typeInfo = getTypeInfo(options.schema, state);

@@ -18,12 +17,12 @@ if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||

}
else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
return getDirectiveReference(typeInfo);
}
else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
return getArgumentReference(typeInfo);
}
else if (kind === 'EnumValue' && typeInfo.enumValue) {
if (kind === 'EnumValue' && typeInfo.enumValue) {
return getEnumValueReference(typeInfo);
}
else if (kind === 'NamedType' && typeInfo.type) {
if (kind === 'NamedType' && typeInfo.type) {
return getTypeReference(typeInfo);

@@ -30,0 +29,0 @@ }

@@ -10,3 +10,3 @@ import CodeMirror from 'codemirror';

CodeMirror.registerHelper('lint', 'graphql', (text, options) => {
const schema = options.schema;
const { schema } = options;
const rawResults = getDiagnostics(text, schema, options.validationRules, undefined, options.externalFragments);

@@ -13,0 +13,0 @@ const results = rawResults.map(error => ({

@@ -25,3 +25,3 @@ import CodeMirror from 'codemirror';

var _a, _b;
const levels = state.levels;
const { levels } = state;
const level = !levels || levels.length === 0

@@ -28,0 +28,0 @@ ? state.indentLevel

@@ -6,3 +6,3 @@ import { typeFromAST, } from 'graphql';

if (definition.kind === 'OperationDefinition') {
const variableDefinitions = definition.variableDefinitions;
const { variableDefinitions } = definition;
if (variableDefinitions) {

@@ -9,0 +9,0 @@ variableDefinitions.forEach(({ variable, type }) => {

@@ -25,3 +25,3 @@ import CodeMirror from 'codemirror';

function getHoverTime(cm) {
const options = cm.state.info.options;
const { options } = cm.state.info;
return (options === null || options === void 0 ? void 0 : options.hoverTime) || 500;

@@ -66,3 +66,3 @@ }

const state = cm.state.info;
const options = state.options;
const { options } = state;
const render = options.render || cm.getHelper(pos, 'info');

@@ -69,0 +69,0 @@ if (render) {

@@ -71,3 +71,3 @@ import CodeMirror from 'codemirror';

const onClick = (clickEvent) => {
const destination = cm.state.jump.destination;
const { destination } = cm.state.jump;
if (destination) {

@@ -88,3 +88,3 @@ cm.state.jump.options.onClick(destination, clickEvent);

navigator &&
navigator.appVersion.indexOf('Mac') !== -1;
navigator.appVersion.includes('Mac');
function isJumpModifier(key) {

@@ -97,6 +97,5 @@ return key === (isMac ? 'Meta' : 'Control');

}
const cursor = cm.state.jump.cursor;
const { cursor, options } = cm.state.jump;
const pos = cm.coordsChar(cursor);
const token = cm.getTokenAt(pos, true);
const options = cm.state.jump.options;
const getDestination = options.getDestination || cm.getHelper(pos, 'jump');

@@ -113,3 +112,3 @@ if (getDestination) {

function disableJumpMode(cm) {
const marker = cm.state.jump.marker;
const { marker } = cm.state.jump;
cm.state.jump.marker = null;

@@ -116,0 +115,0 @@ cm.state.jump.destination = null;

export default function indent(state, textAfter) {
var _a, _b;
const levels = state.levels;
const { levels } = state;
const level = !levels || levels.length === 0

@@ -5,0 +5,0 @@ ? state.indentLevel

@@ -18,8 +18,7 @@ import CodeMirror from 'codemirror';

const state = token.state.kind === 'Invalid' ? token.state.prevState : token.state;
const kind = state.kind;
const step = state.step;
const { kind, step } = state;
if (kind === 'Document' && step === 0) {
return hintList(cur, token, [{ text: '{' }]);
}
const variableToType = options.variableToType;
const { variableToType } = options;
if (!variableToType) {

@@ -36,11 +35,10 @@ return;

}
if (kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) {
if (typeInfo.fields) {
const inputFields = Object.keys(typeInfo.fields).map(fieldName => typeInfo.fields[fieldName]);
return hintList(cur, token, inputFields.map(field => ({
text: `"${field.name}": `,
type: field.type,
description: field.description,
})));
}
if ((kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) &&
typeInfo.fields) {
const inputFields = Object.keys(typeInfo.fields).map(fieldName => typeInfo.fields[fieldName]);
return hintList(cur, token, inputFields.map(field => ({
text: `"${field.name}": `,
type: field.type,
description: field.description,
})));
}

@@ -60,3 +58,3 @@ if (kind === 'StringValue' ||

}
else if (namedInputType instanceof GraphQLEnumType) {
if (namedInputType instanceof GraphQLEnumType) {
const values = namedInputType.getValues();

@@ -69,3 +67,3 @@ return hintList(cur, token, values.map(value => ({

}
else if (namedInputType === GraphQLBoolean) {
if (namedInputType === GraphQLBoolean) {
return hintList(cur, token, [

@@ -72,0 +70,0 @@ { text: 'true', type: GraphQLBoolean, description: 'Not false.' },

@@ -18,3 +18,3 @@ import CodeMirror from 'codemirror';

}
const variableToType = options.variableToType;
const { variableToType } = options;
if (!variableToType) {

@@ -32,6 +32,3 @@ return [];

const type = variableToType[variableName];
if (!type) {
errors.push(lintError(editor, member.key, `Variable "$${variableName}" does not appear in any GraphQL query.`));
}
else {
if (type) {
validateValue(type, member.value).forEach(([node, message]) => {

@@ -41,2 +38,5 @@ errors.push(lintError(editor, node, message));

}
else {
errors.push(lintError(editor, member.key, `Variable "$${variableName}" does not appear in any GraphQL query.`));
}
}

@@ -90,9 +90,9 @@ });

const field = type.getFields()[fieldName];
if (!providedFields[fieldName]) {
if (field.type instanceof GraphQLNonNull && !field.defaultValue) {
fieldErrors.push([
valueAST,
`Object of type "${type}" is missing required field "${fieldName}".`,
]);
}
if (!providedFields[fieldName] &&
field.type instanceof GraphQLNonNull &&
!field.defaultValue) {
fieldErrors.push([
valueAST,
`Object of type "${type}" is missing required field "${fieldName}".`,
]);
}

@@ -112,10 +112,9 @@ });

}
if (type instanceof GraphQLEnumType || type instanceof GraphQLScalarType) {
if ((valueAST.kind !== 'String' &&
if ((type instanceof GraphQLEnumType || type instanceof GraphQLScalarType) &&
((valueAST.kind !== 'String' &&
valueAST.kind !== 'Number' &&
valueAST.kind !== 'Boolean' &&
valueAST.kind !== 'Null') ||
isNullish(type.parseValue(valueAST.value))) {
return [[valueAST, `Expected value of type "${type}".`]];
}
isNullish(type.parseValue(valueAST.value)))) {
return [[valueAST, `Expected value of type "${type}".`]];
}

@@ -122,0 +121,0 @@ return [];

@@ -25,3 +25,3 @@ import CodeMirror from 'codemirror';

var _a, _b;
const levels = state.levels;
const { levels } = state;
const level = !levels || levels.length === 0

@@ -28,0 +28,0 @@ ? state.indentLevel

@@ -5,3 +5,3 @@ import CodeMirror from 'codemirror';

CodeMirror.registerHelper('hint', 'graphql', (editor, options) => {
const schema = options.schema;
const { schema } = options;
if (!schema) {

@@ -8,0 +8,0 @@ return;

@@ -10,5 +10,3 @@ import { GraphQLList, GraphQLNonNull, } from 'graphql';

}
const state = token.state;
const kind = state.kind;
const step = state.step;
const { kind, step } = token.state;
const typeInfo = getTypeInfo(options.schema, token.state);

@@ -25,3 +23,3 @@ if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||

}
else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
const header = document.createElement('div');

@@ -35,3 +33,3 @@ header.className = 'CodeMirror-info-header';

}
else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
const header = document.createElement('div');

@@ -45,3 +43,3 @@ header.className = 'CodeMirror-info-header';

}
else if (kind === 'EnumValue' &&
if (kind === 'EnumValue' &&
typeInfo.enumValue &&

@@ -57,3 +55,3 @@ typeInfo.enumValue.description) {

}
else if (kind === 'NamedType' &&
if (kind === 'NamedType' &&
typeInfo.type &&

@@ -129,3 +127,3 @@ typeInfo.type.description) {

function renderDescription(into, options, def) {
const description = def.description;
const { description } = def;
if (description) {

@@ -167,3 +165,3 @@ const descriptionDiv = document.createElement('div');

if (className) {
const onClick = options.onClick;
const { onClick } = options;
let node;

@@ -170,0 +168,0 @@ if (onClick) {

@@ -15,5 +15,3 @@ "use strict";

}
var state = token.state;
var kind = state.kind;
var step = state.step;
var _a = token.state, kind = _a.kind, step = _a.step;
var typeInfo = (0, getTypeInfo_1.default)(options.schema, token.state);

@@ -30,3 +28,3 @@ if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||

}
else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
var header = document.createElement('div');

@@ -40,3 +38,3 @@ header.className = 'CodeMirror-info-header';

}
else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
var header = document.createElement('div');

@@ -50,3 +48,3 @@ header.className = 'CodeMirror-info-header';

}
else if (kind === 'EnumValue' &&
if (kind === 'EnumValue' &&
typeInfo.enumValue &&

@@ -62,3 +60,3 @@ typeInfo.enumValue.description) {

}
else if (kind === 'NamedType' &&
if (kind === 'NamedType' &&
typeInfo.type &&

@@ -65,0 +63,0 @@ typeInfo.type.description) {

@@ -9,5 +9,4 @@ import CodeMirror from 'codemirror';

}
const state = token.state;
const kind = state.kind;
const step = state.step;
const { state } = token;
const { kind, step } = state;
const typeInfo = getTypeInfo(options.schema, state);

@@ -18,12 +17,12 @@ if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||

}
else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
return getDirectiveReference(typeInfo);
}
else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
return getArgumentReference(typeInfo);
}
else if (kind === 'EnumValue' && typeInfo.enumValue) {
if (kind === 'EnumValue' && typeInfo.enumValue) {
return getEnumValueReference(typeInfo);
}
else if (kind === 'NamedType' && typeInfo.type) {
if (kind === 'NamedType' && typeInfo.type) {
return getTypeReference(typeInfo);

@@ -30,0 +29,0 @@ }

@@ -15,4 +15,3 @@ "use strict";

var state = token.state;
var kind = state.kind;
var step = state.step;
var kind = state.kind, step = state.step;
var typeInfo = (0, getTypeInfo_1.default)(options.schema, state);

@@ -23,12 +22,12 @@ if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||

}
else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
return (0, SchemaReference_1.getDirectiveReference)(typeInfo);
}
else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
return (0, SchemaReference_1.getArgumentReference)(typeInfo);
}
else if (kind === 'EnumValue' && typeInfo.enumValue) {
if (kind === 'EnumValue' && typeInfo.enumValue) {
return (0, SchemaReference_1.getEnumValueReference)(typeInfo);
}
else if (kind === 'NamedType' && typeInfo.type) {
if (kind === 'NamedType' && typeInfo.type) {
return (0, SchemaReference_1.getTypeReference)(typeInfo);

@@ -35,0 +34,0 @@ }

@@ -10,3 +10,3 @@ import CodeMirror from 'codemirror';

CodeMirror.registerHelper('lint', 'graphql', (text, options) => {
const schema = options.schema;
const { schema } = options;
const rawResults = getDiagnostics(text, schema, options.validationRules, undefined, options.externalFragments);

@@ -13,0 +13,0 @@ const results = rawResults.map(error => ({

{
"name": "codemirror-graphql",
"version": "2.0.2",
"version": "2.0.3",
"description": "GraphQL mode and helpers for CodeMirror.",

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

"dependencies": {
"graphql-language-service": "5.0.6"
"graphql-language-service": "5.1.1"
},

@@ -57,0 +57,0 @@ "devDependencies": {

@@ -19,4 +19,4 @@ # GraphQL mode for CodeMirror

CodeMirror helpers install themselves to the global CodeMirror when they
are imported.
CodeMirror helpers install themselves to the global CodeMirror when they are
imported.

@@ -47,3 +47,4 @@ ```js

If you want to have autocompletion for external fragment definitions, there's a new configuration setting available
If you want to have autocompletion for external fragment definitions, there's a
new configuration setting available

@@ -85,3 +86,4 @@ ```ts

If you want to show custom validation, you can do that too! It uses the `ValidationRule` interface.
If you want to show custom validation, you can do that too! It uses the
`ValidationRule` interface.

@@ -88,0 +90,0 @@ ```js

@@ -25,3 +25,3 @@ import CodeMirror from 'codemirror';

var _a, _b;
const levels = state.levels;
const { levels } = state;
const level = !levels || levels.length === 0

@@ -28,0 +28,0 @@ ? state.indentLevel

@@ -24,3 +24,3 @@ /**

import '../hint';
import { GraphQLHintOptions, IHint, IHints } from '../hint';
import type { GraphQLHintOptions, IHint, IHints } from '../hint';
import '../mode';

@@ -27,0 +27,0 @@ import {

@@ -22,3 +22,3 @@ /**

mode: 'graphql',
lint: lintConfig ? lintConfig : true,
lint: lintConfig || true,
});

@@ -35,6 +35,5 @@ }

editor.state.lint.options.onUpdateLinting = (errors: any[]) => {
if (errors?.[0]) {
if (!errors[0].message.match('Unexpected EOF')) {
resolve(errors);
}
if (errors?.[0] && !errors[0].message.match('Unexpected EOF')) {
resolve(errors);
return;
}

@@ -41,0 +40,0 @@ resolve([]);

@@ -73,3 +73,3 @@ /**

): IHints | undefined => {
const schema = options.schema;
const { schema } = options;
if (!schema) {

@@ -76,0 +76,0 @@ return;

@@ -64,6 +64,3 @@ /* @flow */

}
const state = token.state;
const kind = state.kind;
const step = state.step;
const { kind, step } = token.state;
const typeInfo = getTypeInfo(options.schema, token.state);

@@ -85,3 +82,4 @@

return into;
} else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
}
if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
const header = document.createElement('div');

@@ -94,3 +92,4 @@ header.className = 'CodeMirror-info-header';

return into;
} else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
}
if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
const header = document.createElement('div');

@@ -103,3 +102,4 @@ header.className = 'CodeMirror-info-header';

return into;
} else if (
}
if (
kind === 'EnumValue' &&

@@ -116,3 +116,4 @@ typeInfo.enumValue &&

return into;
} else if (
}
if (
kind === 'NamedType' &&

@@ -242,3 +243,3 @@ typeInfo.type &&

) {
const description = (def as GraphQLInputField).description;
const { description } = def as GraphQLInputField;
if (description) {

@@ -298,3 +299,3 @@ const descriptionDiv = document.createElement('div');

if (className) {
const onClick = options.onClick;
const { onClick } = options;
let node;

@@ -301,0 +302,0 @@ if (onClick) {

@@ -56,5 +56,4 @@ /**

// or directive) that token references.
const state = token.state;
const kind = state.kind;
const step = state.step;
const { state } = token;
const { kind, step } = state;
const typeInfo = getTypeInfo(options.schema, state);

@@ -67,9 +66,13 @@

return getFieldReference(typeInfo);
} else if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
}
if (kind === 'Directive' && step === 1 && typeInfo.directiveDef) {
return getDirectiveReference(typeInfo);
} else if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
}
if (kind === 'Argument' && step === 0 && typeInfo.argDef) {
return getArgumentReference(typeInfo);
} else if (kind === 'EnumValue' && typeInfo.enumValue) {
}
if (kind === 'EnumValue' && typeInfo.enumValue) {
return getEnumValueReference(typeInfo);
} else if (kind === 'NamedType' && typeInfo.type) {
}
if (kind === 'NamedType' && typeInfo.type) {
return getTypeReference(typeInfo);

@@ -76,0 +79,0 @@ }

@@ -45,3 +45,3 @@ /**

(text: string, options: GraphQLLintOptions): CodeMirror.Annotation[] => {
const schema = options.schema;
const { schema } = options;
const rawResults = getDiagnostics(

@@ -48,0 +48,0 @@ text,

@@ -55,3 +55,3 @@ /**

) {
const levels = state.levels;
const { levels } = state;
// If there is no stack of levels, use the current level.

@@ -58,0 +58,0 @@ // Otherwise, use the top level, preemptively dedenting for close braces.

@@ -27,3 +27,3 @@ /**

if (definition.kind === 'OperationDefinition') {
const variableDefinitions = definition.variableDefinitions;
const { variableDefinitions } = definition;
if (variableDefinitions) {

@@ -30,0 +30,0 @@ variableDefinitions.forEach(({ variable, type }) => {

@@ -48,3 +48,3 @@ /**

function getHoverTime(cm: CodeMirror.Editor) {
const options = cm.state.info.options;
const { options } = cm.state.info;
return options?.hoverTime || 500;

@@ -100,3 +100,3 @@ }

const state = cm.state.info;
const options = state.options;
const { options } = state;
const render = options.render || cm.getHelper(pos, 'info');

@@ -103,0 +103,0 @@ if (render) {

@@ -106,3 +106,3 @@ /**

const onClick = (clickEvent: MouseEvent) => {
const destination = cm.state.jump.destination;
const { destination } = cm.state.jump;
if (destination) {

@@ -127,3 +127,3 @@ cm.state.jump.options.onClick(destination, clickEvent);

navigator &&
navigator.appVersion.indexOf('Mac') !== -1;
navigator.appVersion.includes('Mac');

@@ -139,7 +139,5 @@ function isJumpModifier(key: string) {

const cursor = cm.state.jump.cursor;
const { cursor, options } = cm.state.jump;
const pos = cm.coordsChar(cursor);
const token = cm.getTokenAt(pos, true);
const options = cm.state.jump.options;
const getDestination = options.getDestination || cm.getHelper(pos, 'jump');

@@ -162,3 +160,3 @@ if (getDestination) {

function disableJumpMode(cm: CodeMirror.Editor) {
const marker = cm.state.jump.marker;
const { marker } = cm.state.jump;
cm.state.jump.marker = null;

@@ -165,0 +163,0 @@ cm.state.jump.destination = null;

@@ -22,3 +22,3 @@ /**

) {
const levels = state.levels;
const { levels } = state;
// If there is no stack of levels, use the current level.

@@ -25,0 +25,0 @@ // Otherwise, use the top level, preemptively dedenting for close braces.

@@ -22,3 +22,3 @@ /**

mode: 'graphql-variables',
lint: lintConfig ? lintConfig : true,
lint: lintConfig || true,
});

@@ -36,6 +36,5 @@ }

) => {
if (errors?.[0]) {
if (!errors[0].message?.match('Unexpected EOF')) {
resolve(errors);
}
if (errors?.[0] && !errors[0].message?.match('Unexpected EOF')) {
resolve(errors);
return;
}

@@ -42,0 +41,0 @@ resolve([]);

@@ -92,5 +92,3 @@ /**

const kind = state.kind;
const step = state.step;
const { kind, step } = state;
// Variables can only be an object literal.

@@ -101,3 +99,3 @@ if (kind === 'Document' && step === 0) {

const variableToType = options.variableToType;
const { variableToType } = options;
if (!variableToType) {

@@ -123,17 +121,18 @@ return;

// Input Object fields
if (kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) {
if (typeInfo.fields) {
const inputFields = Object.keys(typeInfo.fields).map(
fieldName => typeInfo.fields![fieldName],
);
return hintList(
cur,
token,
inputFields.map(field => ({
text: `"${field.name}": `,
type: field.type,
description: field.description,
})),
);
}
if (
(kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) &&
typeInfo.fields
) {
const inputFields = Object.keys(typeInfo.fields).map(
fieldName => typeInfo.fields![fieldName],
);
return hintList(
cur,
token,
inputFields.map(field => ({
text: `"${field.name}": `,
type: field.type,
description: field.description,
})),
);
}

@@ -156,3 +155,4 @@

return hintList(cur, token, [{ text: '{' }]);
} else if (namedInputType instanceof GraphQLEnumType) {
}
if (namedInputType instanceof GraphQLEnumType) {
const values = namedInputType.getValues();

@@ -169,3 +169,4 @@ // const values = Object.keys(valueMap).map(name => valueMap[name]); // TODO: Previously added

);
} else if (namedInputType === GraphQLBoolean) {
}
if (namedInputType === GraphQLBoolean) {
return hintList(cur, token, [

@@ -172,0 +173,0 @@ { text: 'true', type: GraphQLBoolean, description: 'Not false.' }, // TODO: type and description don't seem to be used. Added them as optional anyway.

@@ -69,3 +69,3 @@ /**

// If there are not yet known variables, do nothing.
const variableToType = options.variableToType;
const { variableToType } = options;
if (!variableToType) {

@@ -93,3 +93,7 @@ return [];

const type = variableToType[variableName];
if (!type) {
if (type) {
validateValue(type, member.value).forEach(([node, message]) => {
errors.push(lintError(editor, node, message));
});
} else {
errors.push(

@@ -102,6 +106,2 @@ lintError(

);
} else {
validateValue(type, member.value).forEach(([node, message]) => {
errors.push(lintError(editor, node, message));
});
}

@@ -177,9 +177,11 @@ }

const field = type.getFields()[fieldName];
if (!providedFields[fieldName]) {
if (field.type instanceof GraphQLNonNull && !field.defaultValue) {
fieldErrors.push([
valueAST,
`Object of type "${type}" is missing required field "${fieldName}".`,
]);
}
if (
!providedFields[fieldName] &&
field.type instanceof GraphQLNonNull &&
!field.defaultValue
) {
fieldErrors.push([
valueAST,
`Object of type "${type}" is missing required field "${fieldName}".`,
]);
}

@@ -207,12 +209,11 @@ });

// Validate enums and custom scalars.
if (type instanceof GraphQLEnumType || type instanceof 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}".`]];
}
if (
(type instanceof GraphQLEnumType || type instanceof GraphQLScalarType) &&
((valueAST.kind !== 'String' &&
valueAST.kind !== 'Number' &&
valueAST.kind !== 'Boolean' &&
valueAST.kind !== 'Null') ||
isNullish(type.parseValue(valueAST.value)))
) {
return [[valueAST, `Expected value of type "${type}".`]];
}

@@ -219,0 +220,0 @@

@@ -56,3 +56,3 @@ /**

) {
const levels = state.levels;
const { levels } = state;
// If there is no stack of levels, use the current level.

@@ -59,0 +59,0 @@ // Otherwise, use the top level, preemptively dedenting for close braces.

@@ -6,3 +6,3 @@ import { typeFromAST, } from 'graphql';

if (definition.kind === 'OperationDefinition') {
const variableDefinitions = definition.variableDefinitions;
const { variableDefinitions } = definition;
if (variableDefinitions) {

@@ -9,0 +9,0 @@ variableDefinitions.forEach(({ variable, type }) => {

@@ -25,3 +25,3 @@ import CodeMirror from 'codemirror';

function getHoverTime(cm) {
const options = cm.state.info.options;
const { options } = cm.state.info;
return (options === null || options === void 0 ? void 0 : options.hoverTime) || 500;

@@ -66,3 +66,3 @@ }

const state = cm.state.info;
const options = state.options;
const { options } = state;
const render = options.render || cm.getHelper(pos, 'info');

@@ -69,0 +69,0 @@ if (render) {

@@ -71,3 +71,3 @@ import CodeMirror from 'codemirror';

const onClick = (clickEvent) => {
const destination = cm.state.jump.destination;
const { destination } = cm.state.jump;
if (destination) {

@@ -88,3 +88,3 @@ cm.state.jump.options.onClick(destination, clickEvent);

navigator &&
navigator.appVersion.indexOf('Mac') !== -1;
navigator.appVersion.includes('Mac');
function isJumpModifier(key) {

@@ -97,6 +97,5 @@ return key === (isMac ? 'Meta' : 'Control');

}
const cursor = cm.state.jump.cursor;
const { cursor, options } = cm.state.jump;
const pos = cm.coordsChar(cursor);
const token = cm.getTokenAt(pos, true);
const options = cm.state.jump.options;
const getDestination = options.getDestination || cm.getHelper(pos, 'jump');

@@ -113,3 +112,3 @@ if (getDestination) {

function disableJumpMode(cm) {
const marker = cm.state.jump.marker;
const { marker } = cm.state.jump;
cm.state.jump.marker = null;

@@ -116,0 +115,0 @@ cm.state.jump.destination = null;

@@ -92,3 +92,3 @@ "use strict";

navigator &&
navigator.appVersion.indexOf('Mac') !== -1;
navigator.appVersion.includes('Mac');
function isJumpModifier(key) {

@@ -101,6 +101,5 @@ return key === (isMac ? 'Meta' : 'Control');

}
var cursor = cm.state.jump.cursor;
var _a = cm.state.jump, cursor = _a.cursor, options = _a.options;
var pos = cm.coordsChar(cursor);
var token = cm.getTokenAt(pos, true);
var options = cm.state.jump.options;
var getDestination = options.getDestination || cm.getHelper(pos, 'jump');

@@ -107,0 +106,0 @@ if (getDestination) {

export default function indent(state, textAfter) {
var _a, _b;
const levels = state.levels;
const { levels } = state;
const level = !levels || levels.length === 0

@@ -5,0 +5,0 @@ ? state.indentLevel

@@ -18,8 +18,7 @@ import CodeMirror from 'codemirror';

const state = token.state.kind === 'Invalid' ? token.state.prevState : token.state;
const kind = state.kind;
const step = state.step;
const { kind, step } = state;
if (kind === 'Document' && step === 0) {
return hintList(cur, token, [{ text: '{' }]);
}
const variableToType = options.variableToType;
const { variableToType } = options;
if (!variableToType) {

@@ -36,11 +35,10 @@ return;

}
if (kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) {
if (typeInfo.fields) {
const inputFields = Object.keys(typeInfo.fields).map(fieldName => typeInfo.fields[fieldName]);
return hintList(cur, token, inputFields.map(field => ({
text: `"${field.name}": `,
type: field.type,
description: field.description,
})));
}
if ((kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) &&
typeInfo.fields) {
const inputFields = Object.keys(typeInfo.fields).map(fieldName => typeInfo.fields[fieldName]);
return hintList(cur, token, inputFields.map(field => ({
text: `"${field.name}": `,
type: field.type,
description: field.description,
})));
}

@@ -60,3 +58,3 @@ if (kind === 'StringValue' ||

}
else if (namedInputType instanceof GraphQLEnumType) {
if (namedInputType instanceof GraphQLEnumType) {
const values = namedInputType.getValues();

@@ -69,3 +67,3 @@ return hintList(cur, token, values.map(value => ({

}
else if (namedInputType === GraphQLBoolean) {
if (namedInputType === GraphQLBoolean) {
return hintList(cur, token, [

@@ -72,0 +70,0 @@ { text: 'true', type: GraphQLBoolean, description: 'Not false.' },

@@ -23,4 +23,3 @@ "use strict";

var state = token.state.kind === 'Invalid' ? token.state.prevState : token.state;
var kind = state.kind;
var step = state.step;
var kind = state.kind, step = state.step;
if (kind === 'Document' && step === 0) {

@@ -41,11 +40,10 @@ return (0, hintList_1.default)(cur, token, [{ text: '{' }]);

}
if (kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) {
if (typeInfo.fields) {
var inputFields = Object.keys(typeInfo.fields).map(function (fieldName) { return typeInfo.fields[fieldName]; });
return (0, hintList_1.default)(cur, token, inputFields.map(function (field) { return ({
text: "\"".concat(field.name, "\": "),
type: field.type,
description: field.description,
}); }));
}
if ((kind === 'ObjectValue' || (kind === 'ObjectField' && step === 0)) &&
typeInfo.fields) {
var inputFields = Object.keys(typeInfo.fields).map(function (fieldName) { return typeInfo.fields[fieldName]; });
return (0, hintList_1.default)(cur, token, inputFields.map(function (field) { return ({
text: "\"".concat(field.name, "\": "),
type: field.type,
description: field.description,
}); }));
}

@@ -65,3 +63,3 @@ if (kind === 'StringValue' ||

}
else if (namedInputType_1 instanceof graphql_1.GraphQLEnumType) {
if (namedInputType_1 instanceof graphql_1.GraphQLEnumType) {
var values = namedInputType_1.getValues();

@@ -74,3 +72,3 @@ return (0, hintList_1.default)(cur, token, values.map(function (value) { return ({

}
else if (namedInputType_1 === graphql_1.GraphQLBoolean) {
if (namedInputType_1 === graphql_1.GraphQLBoolean) {
return (0, hintList_1.default)(cur, token, [

@@ -77,0 +75,0 @@ { text: 'true', type: graphql_1.GraphQLBoolean, description: 'Not false.' },

@@ -18,3 +18,3 @@ import CodeMirror from 'codemirror';

}
const variableToType = options.variableToType;
const { variableToType } = options;
if (!variableToType) {

@@ -32,6 +32,3 @@ return [];

const type = variableToType[variableName];
if (!type) {
errors.push(lintError(editor, member.key, `Variable "$${variableName}" does not appear in any GraphQL query.`));
}
else {
if (type) {
validateValue(type, member.value).forEach(([node, message]) => {

@@ -41,2 +38,5 @@ errors.push(lintError(editor, node, message));

}
else {
errors.push(lintError(editor, member.key, `Variable "$${variableName}" does not appear in any GraphQL query.`));
}
}

@@ -90,9 +90,9 @@ });

const field = type.getFields()[fieldName];
if (!providedFields[fieldName]) {
if (field.type instanceof GraphQLNonNull && !field.defaultValue) {
fieldErrors.push([
valueAST,
`Object of type "${type}" is missing required field "${fieldName}".`,
]);
}
if (!providedFields[fieldName] &&
field.type instanceof GraphQLNonNull &&
!field.defaultValue) {
fieldErrors.push([
valueAST,
`Object of type "${type}" is missing required field "${fieldName}".`,
]);
}

@@ -112,10 +112,9 @@ });

}
if (type instanceof GraphQLEnumType || type instanceof GraphQLScalarType) {
if ((valueAST.kind !== 'String' &&
if ((type instanceof GraphQLEnumType || type instanceof GraphQLScalarType) &&
((valueAST.kind !== 'String' &&
valueAST.kind !== 'Number' &&
valueAST.kind !== 'Boolean' &&
valueAST.kind !== 'Null') ||
isNullish(type.parseValue(valueAST.value))) {
return [[valueAST, `Expected value of type "${type}".`]];
}
isNullish(type.parseValue(valueAST.value)))) {
return [[valueAST, `Expected value of type "${type}".`]];
}

@@ -122,0 +121,0 @@ return [];

@@ -75,6 +75,3 @@ "use strict";

var type = variableToType[variableName];
if (!type) {
errors.push(lintError(editor, member.key, "Variable \"$".concat(variableName, "\" does not appear in any GraphQL query.")));
}
else {
if (type) {
validateValue(type, member.value).forEach(function (_a) {

@@ -85,2 +82,5 @@ var _b = __read(_a, 2), node = _b[0], message = _b[1];

}
else {
errors.push(lintError(editor, member.key, "Variable \"$".concat(variableName, "\" does not appear in any GraphQL query.")));
}
}

@@ -134,9 +134,9 @@ });

var field = type.getFields()[fieldName];
if (!providedFields_1[fieldName]) {
if (field.type instanceof graphql_1.GraphQLNonNull && !field.defaultValue) {
fieldErrors_1.push([
valueAST,
"Object of type \"".concat(type, "\" is missing required field \"").concat(fieldName, "\"."),
]);
}
if (!providedFields_1[fieldName] &&
field.type instanceof graphql_1.GraphQLNonNull &&
!field.defaultValue) {
fieldErrors_1.push([
valueAST,
"Object of type \"".concat(type, "\" is missing required field \"").concat(fieldName, "\"."),
]);
}

@@ -156,10 +156,9 @@ });

}
if (type instanceof graphql_1.GraphQLEnumType || type instanceof graphql_1.GraphQLScalarType) {
if ((valueAST.kind !== 'String' &&
if ((type instanceof graphql_1.GraphQLEnumType || type instanceof graphql_1.GraphQLScalarType) &&
((valueAST.kind !== 'String' &&
valueAST.kind !== 'Number' &&
valueAST.kind !== 'Boolean' &&
valueAST.kind !== 'Null') ||
isNullish(type.parseValue(valueAST.value))) {
return [[valueAST, "Expected value of type \"".concat(type, "\".")]];
}
isNullish(type.parseValue(valueAST.value)))) {
return [[valueAST, "Expected value of type \"".concat(type, "\".")]];
}

@@ -166,0 +165,0 @@ return [];

@@ -25,3 +25,3 @@ import CodeMirror from 'codemirror';

var _a, _b;
const levels = state.levels;
const { levels } = state;
const level = !levels || levels.length === 0

@@ -28,0 +28,0 @@ ? state.indentLevel

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

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

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

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

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

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

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

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