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

graphql-language-service

Package Overview
Dependencies
Maintainers
14
Versions
243
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-language-service - npm Package Compare versions

Comparing version 5.1.1 to 5.1.2

src/utils/__tests__/__schema__/RecursiveSchema.graphql

42

dist/interface/getAutocompleteSuggestions.js

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

function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs, options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var _a;
const opts = Object.assign(Object.assign({}, options), { schema });

@@ -79,3 +79,3 @@ const token = contextToken || getTokenAtPosition(queryText, cursor);

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

@@ -91,7 +91,7 @@ if (kind === parser_1.RuleKinds.DOCUMENT) {

}
if (((_b = (_a = state.prevState) === null || _a === void 0 ? void 0 : _a.prevState) === null || _b === void 0 ? void 0 : _b.kind) === parser_1.RuleKinds.EXTENSION_DEFINITION &&
if (((_a = prevState === null || prevState === void 0 ? void 0 : prevState.prevState) === null || _a === void 0 ? void 0 : _a.kind) === parser_1.RuleKinds.EXTENSION_DEFINITION &&
state.name) {
return (0, autocompleteUtils_1.hintList)(token, []);
}
if (((_c = state.prevState) === null || _c === void 0 ? void 0 : _c.kind) === graphql_1.Kind.SCALAR_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === graphql_1.Kind.SCALAR_TYPE_EXTENSION) {
return (0, autocompleteUtils_1.hintList)(token, Object.values(schema.getTypeMap())

@@ -104,3 +104,3 @@ .filter(graphql_1.isScalarType)

}
if (((_d = state.prevState) === null || _d === void 0 ? void 0 : _d.kind) === graphql_1.Kind.OBJECT_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === graphql_1.Kind.OBJECT_TYPE_EXTENSION) {
return (0, autocompleteUtils_1.hintList)(token, Object.values(schema.getTypeMap())

@@ -113,3 +113,3 @@ .filter(type => (0, graphql_1.isObjectType)(type) && !type.name.startsWith('__'))

}
if (((_e = state.prevState) === null || _e === void 0 ? void 0 : _e.kind) === graphql_1.Kind.INTERFACE_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === graphql_1.Kind.INTERFACE_TYPE_EXTENSION) {
return (0, autocompleteUtils_1.hintList)(token, Object.values(schema.getTypeMap())

@@ -122,3 +122,3 @@ .filter(graphql_1.isInterfaceType)

}
if (((_f = state.prevState) === null || _f === void 0 ? void 0 : _f.kind) === graphql_1.Kind.UNION_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === graphql_1.Kind.UNION_TYPE_EXTENSION) {
return (0, autocompleteUtils_1.hintList)(token, Object.values(schema.getTypeMap())

@@ -131,3 +131,3 @@ .filter(graphql_1.isUnionType)

}
if (((_g = state.prevState) === null || _g === void 0 ? void 0 : _g.kind) === graphql_1.Kind.ENUM_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === graphql_1.Kind.ENUM_TYPE_EXTENSION) {
return (0, autocompleteUtils_1.hintList)(token, Object.values(schema.getTypeMap())

@@ -140,3 +140,3 @@ .filter(type => (0, graphql_1.isEnumType)(type) && !type.name.startsWith('__'))

}
if (((_h = state.prevState) === null || _h === void 0 ? void 0 : _h.kind) === graphql_1.Kind.INPUT_OBJECT_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === graphql_1.Kind.INPUT_OBJECT_TYPE_EXTENSION) {
return (0, autocompleteUtils_1.hintList)(token, Object.values(schema.getTypeMap())

@@ -150,4 +150,3 @@ .filter(graphql_1.isInputObjectType)

if (kind === parser_1.RuleKinds.IMPLEMENTS ||
(kind === parser_1.RuleKinds.NAMED_TYPE &&
((_j = state.prevState) === null || _j === void 0 ? void 0 : _j.kind) === parser_1.RuleKinds.IMPLEMENTS)) {
(kind === parser_1.RuleKinds.NAMED_TYPE && (prevState === null || prevState === void 0 ? void 0 : prevState.kind) === parser_1.RuleKinds.IMPLEMENTS)) {
return getSuggestionsForImplements(token, state, schema, queryText, typeInfo);

@@ -209,4 +208,4 @@ }

(kind === parser_1.RuleKinds.NAMED_TYPE &&
state.prevState != null &&
state.prevState.kind === parser_1.RuleKinds.TYPE_CONDITION)) {
prevState != null &&
prevState.kind === parser_1.RuleKinds.TYPE_CONDITION)) {
return getSuggestionsForFragmentTypeConditions(token, typeInfo, schema, kind);

@@ -222,4 +221,4 @@ }

!unwrappedState.needsAdvance &&
state.kind === parser_1.RuleKinds.NAMED_TYPE) ||
state.kind === parser_1.RuleKinds.LIST_TYPE) {
kind === parser_1.RuleKinds.NAMED_TYPE) ||
kind === parser_1.RuleKinds.LIST_TYPE) {
if (unwrappedState.kind === parser_1.RuleKinds.FIELD_DEF) {

@@ -245,6 +244,6 @@ return (0, autocompleteUtils_1.hintList)(token, Object.values(schema.getTypeMap())

(kind === parser_1.RuleKinds.NAMED_TYPE &&
state.prevState &&
(state.prevState.kind === parser_1.RuleKinds.VARIABLE_DEFINITION ||
state.prevState.kind === parser_1.RuleKinds.LIST_TYPE ||
state.prevState.kind === parser_1.RuleKinds.NON_NULL_TYPE))) {
prevState &&
(prevState.kind === parser_1.RuleKinds.VARIABLE_DEFINITION ||
prevState.kind === parser_1.RuleKinds.LIST_TYPE ||
prevState.kind === parser_1.RuleKinds.NON_NULL_TYPE))) {
return getSuggestionsForVariableDefinition(token, schema, kind);

@@ -657,7 +656,6 @@ }

function canUseDirective(state, directive) {
var _a;
if (!state || !state.kind) {
return false;
}
const { kind } = state;
const { kind, prevState } = state;
const { locations } = directive;

@@ -699,3 +697,3 @@ switch (kind) {

case parser_1.RuleKinds.INPUT_VALUE_DEF:
const prevStateKind = (_a = state.prevState) === null || _a === void 0 ? void 0 : _a.kind;
const prevStateKind = prevState === null || prevState === void 0 ? void 0 : prevState.kind;
switch (prevStateKind) {

@@ -702,0 +700,0 @@ case parser_1.RuleKinds.ARGUMENTS_DEF:

@@ -27,21 +27,16 @@ "use strict";

let ast = null;
let fragments = '';
if (externalFragments) {
if (typeof externalFragments === 'string') {
query += '\n\n' + externalFragments;
}
else {
query +=
'\n\n' +
externalFragments.reduce((agg, node) => {
agg += (0, graphql_1.print)(node) + '\n\n';
return agg;
}, '');
}
fragments =
typeof externalFragments === 'string'
? externalFragments
: externalFragments.reduce((acc, node) => acc + (0, graphql_1.print)(node) + '\n\n', '');
}
const enhancedQuery = fragments ? `${query}\n\n${fragments}` : query;
try {
ast = (0, graphql_1.parse)(query);
ast = (0, graphql_1.parse)(enhancedQuery);
}
catch (error) {
if (error instanceof graphql_1.GraphQLError) {
const range = getRange((_b = (_a = error.locations) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : { line: 0, column: 0 }, query);
const range = getRange((_b = (_a = error.locations) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : { line: 0, column: 0 }, enhancedQuery);
return [

@@ -77,3 +72,3 @@ {

const highlightedNodes = [];
error.nodes.forEach(node => {
error.nodes.forEach((node, i) => {
const highlightNode = node.kind !== 'Variable' && 'name' in node && node.name !== undefined

@@ -86,3 +81,3 @@ ? node.name

invariant(error.locations, 'GraphQL validation error requires locations.');
const loc = error.locations[0];
const loc = error.locations[i];
const highlightLoc = getLocation(highlightNode);

@@ -89,0 +84,0 @@ const end = loc.column + (highlightLoc.end - highlightLoc.start);

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

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

@@ -15,0 +14,0 @@ const options = Object.assign(Object.assign({}, config), { schema });

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

};
class Marker {
constructor() {
this.set = new Set();
}
mark(name) {
if (this.set.has(name)) {
return false;
}
this.set.add(name);
return true;
}
}
function getJSONSchemaFromGraphQLType(type, options) {
var _a;
let required = false;

@@ -57,4 +68,4 @@ let definition = Object.create(null);

}
if ((0, graphql_1.isScalarType)(type)) {
definition.type = (_a = scalarTypesMap[type.name]) !== null && _a !== void 0 ? _a : 'any';
if ((0, graphql_1.isScalarType)(type) && scalarTypesMap[type.name]) {
definition.type = scalarTypesMap[type.name];
}

@@ -88,46 +99,49 @@ if ((0, graphql_1.isListType)(type)) {

definition.$ref = `#/definitions/${type.name}`;
const fields = type.getFields();
const fieldDef = {
type: 'object',
properties: {},
required: [],
};
if (type.description) {
fieldDef.description = type.description + `\n` + renderTypeToString(type);
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription =
type.description + `\n` + renderTypeToString(type, true);
if (options === null || options === void 0 ? void 0 : options.definitionMarker.mark(type.name)) {
const fields = type.getFields();
const fieldDef = {
type: 'object',
properties: {},
required: [],
};
if (type.description) {
fieldDef.description =
type.description + `\n` + renderTypeToString(type);
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription =
type.description + `\n` + renderTypeToString(type, true);
}
}
}
else {
fieldDef.description = renderTypeToString(type);
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription = renderTypeToString(type, true);
else {
fieldDef.description = renderTypeToString(type);
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription = renderTypeToString(type, true);
}
}
Object.keys(fields).forEach(fieldName => {
const field = fields[fieldName];
const { required: fieldRequired, definition: typeDefinition, definitions: typeDefinitions, } = getJSONSchemaFromGraphQLType(field.type, options);
const { definition: fieldDefinition, } = getJSONSchemaFromGraphQLType(field, options);
fieldDef.properties[fieldName] = Object.assign(Object.assign({}, typeDefinition), fieldDefinition);
const renderedField = renderTypeToString(field.type);
fieldDef.properties[fieldName].description = field.description
? field.description + '\n' + renderedField
: renderedField;
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
const renderedFieldMarkdown = renderTypeToString(field.type, true);
fieldDef.properties[fieldName].markdownDescription = field.description
? field.description + '\n' + renderedFieldMarkdown
: renderedFieldMarkdown;
}
if (fieldRequired) {
fieldDef.required.push(fieldName);
}
if (typeDefinitions) {
Object.keys(typeDefinitions).map(defName => {
definitions[defName] = typeDefinitions[defName];
});
}
});
definitions[type.name] = fieldDef;
}
Object.keys(fields).forEach(fieldName => {
const field = fields[fieldName];
const { required: fieldRequired, definition: typeDefinition, definitions: typeDefinitions, } = getJSONSchemaFromGraphQLType(field.type, options);
const { definition: fieldDefinition, } = getJSONSchemaFromGraphQLType(field, options);
fieldDef.properties[fieldName] = Object.assign(Object.assign({}, typeDefinition), fieldDefinition);
const renderedField = renderTypeToString(field.type);
fieldDef.properties[fieldName].description = field.description
? field.description + '\n' + renderedField
: renderedField;
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
const renderedFieldMarkdown = renderTypeToString(field.type, true);
fieldDef.properties[fieldName].markdownDescription = field.description
? field.description + '\n' + renderedFieldMarkdown
: renderedFieldMarkdown;
}
if (fieldRequired) {
fieldDef.required.push(fieldName);
}
if (typeDefinitions) {
Object.keys(typeDefinitions).map(defName => {
definitions[defName] = typeDefinitions[defName];
});
}
});
definitions[type.name] = fieldDef;
}

@@ -159,6 +173,7 @@ if ('description' in type &&

};
const runtimeOptions = Object.assign(Object.assign({}, options), { definitionMarker: new Marker() });
if (variableToType) {
Object.entries(variableToType).forEach(([variableName, type]) => {
var _a;
const { definition, required, definitions } = getJSONSchemaFromGraphQLType(type, options);
const { definition, required, definitions } = getJSONSchemaFromGraphQLType(type, runtimeOptions);
jsonSchema.properties[variableName] = definition;

@@ -165,0 +180,0 @@ if (required) {

@@ -67,3 +67,3 @@ import { isInterfaceType, GraphQLInterfaceType, GraphQLObjectType, Kind, DirectiveLocation, isListType, isNonNullType, isScalarType, isObjectType, isUnionType, isEnumType, isInputObjectType, isOutputType, GraphQLBoolean, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, assertAbstractType, doTypesOverlap, getNamedType, getNullableType, isAbstractType, isCompositeType, isInputType, visit, BREAK, parse, } from 'graphql';

export function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs, options) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var _a;
const opts = Object.assign(Object.assign({}, options), { schema });

@@ -76,3 +76,3 @@ const token = contextToken || getTokenAtPosition(queryText, cursor);

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

@@ -88,7 +88,7 @@ if (kind === RuleKinds.DOCUMENT) {

}
if (((_b = (_a = state.prevState) === null || _a === void 0 ? void 0 : _a.prevState) === null || _b === void 0 ? void 0 : _b.kind) === RuleKinds.EXTENSION_DEFINITION &&
if (((_a = prevState === null || prevState === void 0 ? void 0 : prevState.prevState) === null || _a === void 0 ? void 0 : _a.kind) === RuleKinds.EXTENSION_DEFINITION &&
state.name) {
return hintList(token, []);
}
if (((_c = state.prevState) === null || _c === void 0 ? void 0 : _c.kind) === Kind.SCALAR_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === Kind.SCALAR_TYPE_EXTENSION) {
return hintList(token, Object.values(schema.getTypeMap())

@@ -101,3 +101,3 @@ .filter(isScalarType)

}
if (((_d = state.prevState) === null || _d === void 0 ? void 0 : _d.kind) === Kind.OBJECT_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === Kind.OBJECT_TYPE_EXTENSION) {
return hintList(token, Object.values(schema.getTypeMap())

@@ -110,3 +110,3 @@ .filter(type => isObjectType(type) && !type.name.startsWith('__'))

}
if (((_e = state.prevState) === null || _e === void 0 ? void 0 : _e.kind) === Kind.INTERFACE_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === Kind.INTERFACE_TYPE_EXTENSION) {
return hintList(token, Object.values(schema.getTypeMap())

@@ -119,3 +119,3 @@ .filter(isInterfaceType)

}
if (((_f = state.prevState) === null || _f === void 0 ? void 0 : _f.kind) === Kind.UNION_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === Kind.UNION_TYPE_EXTENSION) {
return hintList(token, Object.values(schema.getTypeMap())

@@ -128,3 +128,3 @@ .filter(isUnionType)

}
if (((_g = state.prevState) === null || _g === void 0 ? void 0 : _g.kind) === Kind.ENUM_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === Kind.ENUM_TYPE_EXTENSION) {
return hintList(token, Object.values(schema.getTypeMap())

@@ -137,3 +137,3 @@ .filter(type => isEnumType(type) && !type.name.startsWith('__'))

}
if (((_h = state.prevState) === null || _h === void 0 ? void 0 : _h.kind) === Kind.INPUT_OBJECT_TYPE_EXTENSION) {
if ((prevState === null || prevState === void 0 ? void 0 : prevState.kind) === Kind.INPUT_OBJECT_TYPE_EXTENSION) {
return hintList(token, Object.values(schema.getTypeMap())

@@ -147,4 +147,3 @@ .filter(isInputObjectType)

if (kind === RuleKinds.IMPLEMENTS ||
(kind === RuleKinds.NAMED_TYPE &&
((_j = state.prevState) === null || _j === void 0 ? void 0 : _j.kind) === RuleKinds.IMPLEMENTS)) {
(kind === RuleKinds.NAMED_TYPE && (prevState === null || prevState === void 0 ? void 0 : prevState.kind) === RuleKinds.IMPLEMENTS)) {
return getSuggestionsForImplements(token, state, schema, queryText, typeInfo);

@@ -206,4 +205,4 @@ }

(kind === RuleKinds.NAMED_TYPE &&
state.prevState != null &&
state.prevState.kind === RuleKinds.TYPE_CONDITION)) {
prevState != null &&
prevState.kind === RuleKinds.TYPE_CONDITION)) {
return getSuggestionsForFragmentTypeConditions(token, typeInfo, schema, kind);

@@ -219,4 +218,4 @@ }

!unwrappedState.needsAdvance &&
state.kind === RuleKinds.NAMED_TYPE) ||
state.kind === RuleKinds.LIST_TYPE) {
kind === RuleKinds.NAMED_TYPE) ||
kind === RuleKinds.LIST_TYPE) {
if (unwrappedState.kind === RuleKinds.FIELD_DEF) {

@@ -242,6 +241,6 @@ return hintList(token, Object.values(schema.getTypeMap())

(kind === RuleKinds.NAMED_TYPE &&
state.prevState &&
(state.prevState.kind === RuleKinds.VARIABLE_DEFINITION ||
state.prevState.kind === RuleKinds.LIST_TYPE ||
state.prevState.kind === RuleKinds.NON_NULL_TYPE))) {
prevState &&
(prevState.kind === RuleKinds.VARIABLE_DEFINITION ||
prevState.kind === RuleKinds.LIST_TYPE ||
prevState.kind === RuleKinds.NON_NULL_TYPE))) {
return getSuggestionsForVariableDefinition(token, schema, kind);

@@ -649,7 +648,6 @@ }

export function canUseDirective(state, directive) {
var _a;
if (!state || !state.kind) {
return false;
}
const { kind } = state;
const { kind, prevState } = state;
const { locations } = directive;

@@ -691,3 +689,3 @@ switch (kind) {

case RuleKinds.INPUT_VALUE_DEF:
const prevStateKind = (_a = state.prevState) === null || _a === void 0 ? void 0 : _a.kind;
const prevStateKind = prevState === null || prevState === void 0 ? void 0 : prevState.kind;
switch (prevStateKind) {

@@ -694,0 +692,0 @@ case RuleKinds.ARGUMENTS_DEF:

@@ -24,21 +24,16 @@ import { GraphQLError, print, validate, NoDeprecatedCustomRule, parse, } from 'graphql';

let ast = null;
let fragments = '';
if (externalFragments) {
if (typeof externalFragments === 'string') {
query += '\n\n' + externalFragments;
}
else {
query +=
'\n\n' +
externalFragments.reduce((agg, node) => {
agg += print(node) + '\n\n';
return agg;
}, '');
}
fragments =
typeof externalFragments === 'string'
? externalFragments
: externalFragments.reduce((acc, node) => acc + print(node) + '\n\n', '');
}
const enhancedQuery = fragments ? `${query}\n\n${fragments}` : query;
try {
ast = parse(query);
ast = parse(enhancedQuery);
}
catch (error) {
if (error instanceof GraphQLError) {
const range = getRange((_b = (_a = error.locations) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : { line: 0, column: 0 }, query);
const range = getRange((_b = (_a = error.locations) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : { line: 0, column: 0 }, enhancedQuery);
return [

@@ -72,3 +67,3 @@ {

const highlightedNodes = [];
error.nodes.forEach(node => {
error.nodes.forEach((node, i) => {
const highlightNode = node.kind !== 'Variable' && 'name' in node && node.name !== undefined

@@ -81,3 +76,3 @@ ? node.name

invariant(error.locations, 'GraphQL validation error requires locations.');
const loc = error.locations[0];
const loc = error.locations[i];
const highlightLoc = getLocation(highlightNode);

@@ -84,0 +79,0 @@ const end = loc.column + (highlightLoc.end - highlightLoc.start);

@@ -8,4 +8,3 @@ import { GraphQLNonNull, GraphQLList, } from 'graphql';

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

@@ -12,0 +11,0 @@ const options = Object.assign(Object.assign({}, config), { schema });

@@ -41,4 +41,15 @@ import { isEnumType, isInputObjectType, isListType, isNonNullType, isScalarType, } from 'graphql';

};
class Marker {
constructor() {
this.set = new Set();
}
mark(name) {
if (this.set.has(name)) {
return false;
}
this.set.add(name);
return true;
}
}
function getJSONSchemaFromGraphQLType(type, options) {
var _a;
let required = false;

@@ -54,4 +65,4 @@ let definition = Object.create(null);

}
if (isScalarType(type)) {
definition.type = (_a = scalarTypesMap[type.name]) !== null && _a !== void 0 ? _a : 'any';
if (isScalarType(type) && scalarTypesMap[type.name]) {
definition.type = scalarTypesMap[type.name];
}

@@ -85,46 +96,49 @@ if (isListType(type)) {

definition.$ref = `#/definitions/${type.name}`;
const fields = type.getFields();
const fieldDef = {
type: 'object',
properties: {},
required: [],
};
if (type.description) {
fieldDef.description = type.description + `\n` + renderTypeToString(type);
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription =
type.description + `\n` + renderTypeToString(type, true);
if (options === null || options === void 0 ? void 0 : options.definitionMarker.mark(type.name)) {
const fields = type.getFields();
const fieldDef = {
type: 'object',
properties: {},
required: [],
};
if (type.description) {
fieldDef.description =
type.description + `\n` + renderTypeToString(type);
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription =
type.description + `\n` + renderTypeToString(type, true);
}
}
}
else {
fieldDef.description = renderTypeToString(type);
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription = renderTypeToString(type, true);
else {
fieldDef.description = renderTypeToString(type);
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription = renderTypeToString(type, true);
}
}
Object.keys(fields).forEach(fieldName => {
const field = fields[fieldName];
const { required: fieldRequired, definition: typeDefinition, definitions: typeDefinitions, } = getJSONSchemaFromGraphQLType(field.type, options);
const { definition: fieldDefinition, } = getJSONSchemaFromGraphQLType(field, options);
fieldDef.properties[fieldName] = Object.assign(Object.assign({}, typeDefinition), fieldDefinition);
const renderedField = renderTypeToString(field.type);
fieldDef.properties[fieldName].description = field.description
? field.description + '\n' + renderedField
: renderedField;
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
const renderedFieldMarkdown = renderTypeToString(field.type, true);
fieldDef.properties[fieldName].markdownDescription = field.description
? field.description + '\n' + renderedFieldMarkdown
: renderedFieldMarkdown;
}
if (fieldRequired) {
fieldDef.required.push(fieldName);
}
if (typeDefinitions) {
Object.keys(typeDefinitions).map(defName => {
definitions[defName] = typeDefinitions[defName];
});
}
});
definitions[type.name] = fieldDef;
}
Object.keys(fields).forEach(fieldName => {
const field = fields[fieldName];
const { required: fieldRequired, definition: typeDefinition, definitions: typeDefinitions, } = getJSONSchemaFromGraphQLType(field.type, options);
const { definition: fieldDefinition, } = getJSONSchemaFromGraphQLType(field, options);
fieldDef.properties[fieldName] = Object.assign(Object.assign({}, typeDefinition), fieldDefinition);
const renderedField = renderTypeToString(field.type);
fieldDef.properties[fieldName].description = field.description
? field.description + '\n' + renderedField
: renderedField;
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
const renderedFieldMarkdown = renderTypeToString(field.type, true);
fieldDef.properties[fieldName].markdownDescription = field.description
? field.description + '\n' + renderedFieldMarkdown
: renderedFieldMarkdown;
}
if (fieldRequired) {
fieldDef.required.push(fieldName);
}
if (typeDefinitions) {
Object.keys(typeDefinitions).map(defName => {
definitions[defName] = typeDefinitions[defName];
});
}
});
definitions[type.name] = fieldDef;
}

@@ -156,6 +170,7 @@ if ('description' in type &&

};
const runtimeOptions = Object.assign(Object.assign({}, options), { definitionMarker: new Marker() });
if (variableToType) {
Object.entries(variableToType).forEach(([variableName, type]) => {
var _a;
const { definition, required, definitions } = getJSONSchemaFromGraphQLType(type, options);
const { definition, required, definitions } = getJSONSchemaFromGraphQLType(type, runtimeOptions);
jsonSchema.properties[variableName] = definition;

@@ -162,0 +177,0 @@ if (required) {

{
"name": "graphql-language-service",
"version": "5.1.1",
"version": "5.1.2",
"description": "The official, runtime independent Language Service for GraphQL",

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

@@ -15,3 +15,3 @@ /**

import fs from 'fs';
import fs from 'node:fs';
import {

@@ -25,3 +25,3 @@ buildSchema,

import { Position } from '../../utils';
import path from 'path';
import path from 'node:path';

@@ -28,0 +28,0 @@ import { getAutocompleteSuggestions } from '../getAutocompleteSuggestions';

@@ -11,3 +11,3 @@ /**

import fs from 'fs';
import fs from 'node:fs';
import {

@@ -22,3 +22,3 @@ buildSchema,

} from 'graphql';
import path from 'path';
import path from 'node:path';

@@ -51,2 +51,35 @@ import {

it('catches with multiple highlighted nodes', () => {
const errors = validateQuery(
parse('{ hero(episode: $ep) { name } }'),
schema,
);
expect(errors).toMatchObject([
{
range: {
end: {
character: 20,
line: 0,
},
start: {
character: 16,
line: 0,
},
},
},
{
range: {
end: {
character: 32,
line: 0,
},
start: {
character: 0,
line: 0,
},
},
},
]);
});
it('catches multi root validation errors without breaking (with a custom validation function that always throws errors)', () => {

@@ -53,0 +86,0 @@ const error = validateQuery(parse('{ hero { name } } { seq }'), schema, [

@@ -13,6 +13,6 @@ /**

import fs from 'fs';
import fs from 'node:fs';
import { buildSchema, GraphQLSchema } from 'graphql';
import { Position } from 'graphql-language-service';
import path from 'path';
import path from 'node:path';

@@ -19,0 +19,0 @@ import { getHoverInformation } from '../getHoverInformation';

@@ -180,3 +180,3 @@ /**

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

@@ -197,3 +197,3 @@

if (
state.prevState?.prevState?.kind === RuleKinds.EXTENSION_DEFINITION &&
prevState?.prevState?.kind === RuleKinds.EXTENSION_DEFINITION &&
state.name

@@ -205,3 +205,3 @@ ) {

// extend scalar
if (state.prevState?.kind === Kind.SCALAR_TYPE_EXTENSION) {
if (prevState?.kind === Kind.SCALAR_TYPE_EXTENSION) {
return hintList(

@@ -219,3 +219,3 @@ token,

// extend object type
if (state.prevState?.kind === Kind.OBJECT_TYPE_EXTENSION) {
if (prevState?.kind === Kind.OBJECT_TYPE_EXTENSION) {
return hintList(

@@ -233,3 +233,3 @@ token,

// extend interface type
if (state.prevState?.kind === Kind.INTERFACE_TYPE_EXTENSION) {
if (prevState?.kind === Kind.INTERFACE_TYPE_EXTENSION) {
return hintList(

@@ -247,3 +247,3 @@ token,

// extend union type
if (state.prevState?.kind === Kind.UNION_TYPE_EXTENSION) {
if (prevState?.kind === Kind.UNION_TYPE_EXTENSION) {
return hintList(

@@ -261,3 +261,3 @@ token,

// extend enum type
if (state.prevState?.kind === Kind.ENUM_TYPE_EXTENSION) {
if (prevState?.kind === Kind.ENUM_TYPE_EXTENSION) {
return hintList(

@@ -275,3 +275,3 @@ token,

// extend input object type
if (state.prevState?.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION) {
if (prevState?.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION) {
return hintList(

@@ -290,4 +290,3 @@ token,

kind === RuleKinds.IMPLEMENTS ||
(kind === RuleKinds.NAMED_TYPE &&
state.prevState?.kind === RuleKinds.IMPLEMENTS)
(kind === RuleKinds.NAMED_TYPE && prevState?.kind === RuleKinds.IMPLEMENTS)
) {

@@ -386,4 +385,4 @@ return getSuggestionsForImplements(

(kind === RuleKinds.NAMED_TYPE &&
state.prevState != null &&
state.prevState.kind === RuleKinds.TYPE_CONDITION)
prevState != null &&
prevState.kind === RuleKinds.TYPE_CONDITION)
) {

@@ -416,4 +415,4 @@ return getSuggestionsForFragmentTypeConditions(

!unwrappedState.needsAdvance &&
state.kind === RuleKinds.NAMED_TYPE) ||
state.kind === RuleKinds.LIST_TYPE
kind === RuleKinds.NAMED_TYPE) ||
kind === RuleKinds.LIST_TYPE
) {

@@ -449,6 +448,6 @@ if (unwrappedState.kind === RuleKinds.FIELD_DEF) {

(kind === RuleKinds.NAMED_TYPE &&
state.prevState &&
(state.prevState.kind === RuleKinds.VARIABLE_DEFINITION ||
state.prevState.kind === RuleKinds.LIST_TYPE ||
state.prevState.kind === RuleKinds.NON_NULL_TYPE))
prevState &&
(prevState.kind === RuleKinds.VARIABLE_DEFINITION ||
prevState.kind === RuleKinds.LIST_TYPE ||
prevState.kind === RuleKinds.NON_NULL_TYPE))
) {

@@ -676,3 +675,3 @@ return getSuggestionsForVariableDefinition(token, schema, kind);

const type = schema.getType(state.name);
const interfaceConfig = typeInfo.interfaceDef?.toConfig()!;
const interfaceConfig = typeInfo.interfaceDef?.toConfig();
typeInfo.interfaceDef = new GraphQLInterfaceType({

@@ -694,3 +693,3 @@ ...interfaceConfig,

const type = schema.getType(state.name);
const objectTypeConfig = typeInfo.objectTypeDef?.toConfig()!;
const objectTypeConfig = typeInfo.objectTypeDef?.toConfig();
typeInfo.objectTypeDef = new GraphQLObjectType({

@@ -1068,3 +1067,3 @@ ...objectTypeConfig,

}
const { kind } = state;
const { kind, prevState } = state;
const { locations } = directive;

@@ -1108,3 +1107,3 @@ switch (kind) {

case RuleKinds.INPUT_VALUE_DEF:
const prevStateKind = state.prevState?.kind;
const prevStateKind = prevState?.kind;
switch (prevStateKind) {

@@ -1111,0 +1110,0 @@ case RuleKinds.ARGUMENTS_DEF:

@@ -187,2 +187,3 @@ /**

// eslint-disable-next-line sonarjs/no-identical-functions
function getDefinitionForFieldDefinition(

@@ -189,0 +190,0 @@ path: Uri,

@@ -67,17 +67,16 @@ /**

let ast = null;
let fragments = '';
if (externalFragments) {
if (typeof externalFragments === 'string') {
query += '\n\n' + externalFragments;
} else {
query +=
'\n\n' +
externalFragments.reduce((agg, node) => {
agg += print(node) + '\n\n';
return agg;
}, '');
}
fragments =
typeof externalFragments === 'string'
? externalFragments
: externalFragments.reduce(
(acc, node) => acc + print(node) + '\n\n',
'',
);
}
const enhancedQuery = fragments ? `${query}\n\n${fragments}` : query;
try {
ast = parse(query);
ast = parse(enhancedQuery);
} catch (error) {

@@ -87,3 +86,3 @@ if (error instanceof GraphQLError) {

error.locations?.[0] ?? { line: 0, column: 0 },
query,
enhancedQuery,
);

@@ -144,3 +143,3 @@

const highlightedNodes: Diagnostic[] = [];
error.nodes.forEach(node => {
error.nodes.forEach((node, i) => {
const highlightNode =

@@ -160,3 +159,3 @@ node.kind !== 'Variable' && 'name' in node && node.name !== undefined

// https://github.com/microsoft/TypeScript/pull/32695
const loc = error.locations[0];
const loc = error.locations[i];
const highlightLoc = getLocation(highlightNode);

@@ -163,0 +162,0 @@ const end = loc.column + (highlightLoc.end - highlightLoc.start);

@@ -44,4 +44,3 @@ /**

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

@@ -48,0 +47,0 @@ const options = { ...config, schema };

@@ -9,6 +9,6 @@ /**

import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';
import { buildSchema, GraphQLSchema, parse } from 'graphql';
import { join } from 'path';
import { join } from 'node:path';
import { collectVariables } from '../collectVariables';

@@ -261,2 +261,21 @@

});
it('should handle recursive schema properly', () => {
const schemaPath = join(__dirname, '__schema__', 'RecursiveSchema.graphql');
schema = buildSchema(readFileSync(schemaPath, 'utf8'));
const variableToType = collectVariables(
schema,
parse(`query Example(
$where: issues_where_input! = {}
) {
issues(where: $where) {
name
}
}`),
);
getVariablesJSONSchema(variableToType, { useMarkdownDescription: true });
expect(true).toEqual(true);
});
});

@@ -9,3 +9,3 @@ /**

import { readFileSync } from 'fs';
import { readFileSync } from 'node:fs';
import {

@@ -19,3 +19,3 @@ GraphQLError,

} from 'graphql';
import { join } from 'path';
import { join } from 'node:path';

@@ -22,0 +22,0 @@ import { validateWithCustomRules } from '../validateWithCustomRules';

@@ -47,2 +47,5 @@ /**

};
type JSONSchemaRunningOptions = JSONSchemaOptions & {
definitionMarker: Marker;
};

@@ -110,5 +113,17 @@ export const defaultJSONSchemaOptions = {

class Marker {
private set = new Set<string>();
mark(name: string): boolean {
if (this.set.has(name)) {
return false;
}
this.set.add(name);
return true;
}
}
/**
*
* @param type {GraphQLInputType}
* @param options
* @returns {DefinitionResult}

@@ -118,3 +133,3 @@ */

type: GraphQLInputType | GraphQLInputField,
options?: JSONSchemaOptions,
options?: JSONSchemaRunningOptions,
): DefinitionResult {

@@ -134,5 +149,4 @@ let required = false;

if (isScalarType(type)) {
// I think this makes sense for custom scalars?
definition.type = scalarTypesMap[type.name] ?? 'any';
if (isScalarType(type) && scalarTypesMap[type.name]) {
definition.type = scalarTypesMap[type.name];
}

@@ -171,66 +185,69 @@ if (isListType(type)) {

definition.$ref = `#/definitions/${type.name}`;
const fields = type.getFields();
if (options?.definitionMarker.mark(type.name)) {
const fields = type.getFields();
const fieldDef: PropertiedJSON6 = {
type: 'object',
properties: {},
required: [],
};
if (type.description) {
fieldDef.description = type.description + `\n` + renderTypeToString(type);
if (options?.useMarkdownDescription) {
// @ts-expect-error
fieldDef.markdownDescription =
type.description + `\n` + renderTypeToString(type, true);
const fieldDef: PropertiedJSON6 = {
type: 'object',
properties: {},
required: [],
};
if (type.description) {
fieldDef.description =
type.description + `\n` + renderTypeToString(type);
if (options?.useMarkdownDescription) {
// @ts-expect-error
fieldDef.markdownDescription =
type.description + `\n` + renderTypeToString(type, true);
}
} else {
fieldDef.description = renderTypeToString(type);
if (options?.useMarkdownDescription) {
// @ts-expect-error
fieldDef.markdownDescription = renderTypeToString(type, true);
}
}
} else {
fieldDef.description = renderTypeToString(type);
if (options?.useMarkdownDescription) {
// @ts-expect-error
fieldDef.markdownDescription = renderTypeToString(type, true);
}
}
Object.keys(fields).forEach(fieldName => {
const field = fields[fieldName];
const {
required: fieldRequired,
definition: typeDefinition,
definitions: typeDefinitions,
} = getJSONSchemaFromGraphQLType(field.type, options);
Object.keys(fields).forEach(fieldName => {
const field = fields[fieldName];
const {
required: fieldRequired,
definition: typeDefinition,
definitions: typeDefinitions,
} = getJSONSchemaFromGraphQLType(field.type, options);
const {
definition: fieldDefinition,
// definitions: fieldDefinitions,
} = getJSONSchemaFromGraphQLType(field, options);
const {
definition: fieldDefinition,
// definitions: fieldDefinitions,
} = getJSONSchemaFromGraphQLType(field, options);
fieldDef.properties[fieldName] = {
...typeDefinition,
...fieldDefinition,
} as JSONSchema6;
fieldDef.properties[fieldName] = {
...typeDefinition,
...fieldDefinition,
} as JSONSchema6;
const renderedField = renderTypeToString(field.type);
fieldDef.properties[fieldName].description = field.description
? field.description + '\n' + renderedField
: renderedField;
if (options?.useMarkdownDescription) {
const renderedFieldMarkdown = renderTypeToString(field.type, true);
fieldDef.properties[
fieldName
// @ts-expect-error
].markdownDescription = field.description
? field.description + '\n' + renderedFieldMarkdown
: renderedFieldMarkdown;
}
const renderedField = renderTypeToString(field.type);
fieldDef.properties[fieldName].description = field.description
? field.description + '\n' + renderedField
: renderedField;
if (options?.useMarkdownDescription) {
const renderedFieldMarkdown = renderTypeToString(field.type, true);
fieldDef.properties[
fieldName
// @ts-expect-error
].markdownDescription = field.description
? field.description + '\n' + renderedFieldMarkdown
: renderedFieldMarkdown;
}
if (fieldRequired) {
fieldDef.required!.push(fieldName);
}
if (typeDefinitions) {
Object.keys(typeDefinitions).map(defName => {
definitions[defName] = typeDefinitions[defName];
});
}
});
definitions![type.name] = fieldDef;
if (fieldRequired) {
fieldDef.required!.push(fieldName);
}
if (typeDefinitions) {
Object.keys(typeDefinitions).map(defName => {
definitions[defName] = typeDefinitions[defName];
});
}
});
definitions![type.name] = fieldDef;
}
}

@@ -308,2 +325,7 @@ // append descriptions

const runtimeOptions: JSONSchemaRunningOptions = {
...options,
definitionMarker: new Marker(),
};
if (variableToType) {

@@ -313,3 +335,3 @@ // I would use a reduce here, but I wanted it to be readable.

const { definition, required, definitions } =
getJSONSchemaFromGraphQLType(type, options);
getJSONSchemaFromGraphQLType(type, runtimeOptions);
jsonSchema.properties[variableName] = definition;

@@ -316,0 +338,0 @@ if (required) {

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc