Socket
Socket
Sign inDemoInstall

graphql-language-service

Package Overview
Dependencies
Maintainers
13
Versions
242
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.0.2 to 5.0.3

131

esm/interface/getAutocompleteSuggestions.js

@@ -22,6 +22,4 @@ import { CompletionItemKind, InsertTextFormat, } from 'vscode-languageserver-types';

export function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs, options) {
const opts = {
...options,
schema,
};
var _a;
const opts = Object.assign(Object.assign({}, options), { schema });
const token = contextToken || getTokenAtPosition(queryText, cursor);

@@ -46,3 +44,3 @@ const state = token.state.kind === 'Invalid' ? token.state.prevState : token.state;

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

@@ -59,11 +57,14 @@ }

if (argDefs) {
return hintList(token, argDefs.map((argDef) => ({
label: argDef.name,
insertText: argDef.name + ': ',
command: SuggestionCommand,
detail: String(argDef.type),
documentation: argDef.description ?? undefined,
kind: CompletionItemKind.Variable,
type: argDef.type,
})));
return hintList(token, argDefs.map((argDef) => {
var _a;
return ({
label: argDef.name,
insertText: argDef.name + ': ',
command: SuggestionCommand,
detail: String(argDef.type),
documentation: (_a = argDef.description) !== null && _a !== void 0 ? _a : undefined,
kind: CompletionItemKind.Variable,
type: argDef.type,
});
}));
}

@@ -78,9 +79,12 @@ }

: CompletionItemKind.Field;
return hintList(token, objectFields.map(field => ({
label: field.name,
detail: String(field.type),
documentation: field.description ?? undefined,
kind: completionKind,
type: field.type,
})));
return hintList(token, objectFields.map(field => {
var _a;
return ({
label: field.name,
detail: String(field.type),
documentation: (_a = field.description) !== null && _a !== void 0 ? _a : undefined,
kind: completionKind,
type: field.type,
});
}));
}

@@ -97,3 +101,3 @@ }

const variableDefinitions = getVariableCompletions(queryText, schema, token);
return hintList(token, variableDefinitions.filter(v => v.detail === namedInputType?.name));
return hintList(token, variableDefinitions.filter(v => v.detail === (namedInputType === null || namedInputType === void 0 ? void 0 : namedInputType.name)));
}

@@ -145,2 +149,3 @@ if ((kind === RuleKinds.TYPE_CONDITION && step === 1) ||

function getSuggestionsForFieldNames(token, typeInfo, options) {
var _a;
if (typeInfo.parentType) {

@@ -155,6 +160,7 @@ const parentType = typeInfo.parentType;

}
if (parentType === options?.schema?.getQueryType()) {
if (parentType === ((_a = options === null || options === void 0 ? void 0 : options.schema) === null || _a === void 0 ? void 0 : _a.getQueryType())) {
fields.push(SchemaMetaFieldDef, TypeMetaFieldDef);
}
return hintList(token, fields.map((field, index) => {
var _a;
const suggestion = {

@@ -164,3 +170,3 @@ sortText: String(index) + field.name,

detail: String(field.type),
documentation: field.description ?? undefined,
documentation: (_a = field.description) !== null && _a !== void 0 ? _a : undefined,
deprecated: Boolean(field.deprecationReason),

@@ -189,12 +195,15 @@ isDeprecated: Boolean(field.deprecationReason),

return hintList(token, values
.map((value) => ({
label: value.name,
detail: String(namedInputType),
documentation: value.description ?? undefined,
deprecated: Boolean(value.deprecationReason),
isDeprecated: Boolean(value.deprecationReason),
deprecationReason: value.deprecationReason,
kind: CompletionItemKind.EnumMember,
type: namedInputType,
}))
.map((value) => {
var _a;
return ({
label: value.name,
detail: String(namedInputType),
documentation: (_a = value.description) !== null && _a !== void 0 ? _a : undefined,
deprecated: Boolean(value.deprecationReason),
isDeprecated: Boolean(value.deprecationReason),
deprecationReason: value.deprecationReason,
kind: CompletionItemKind.EnumMember,
type: namedInputType,
});
})
.concat(queryVariables));

@@ -231,2 +240,3 @@ }

runOnlineParser(documentText, (_, state) => {
var _a, _b, _c, _d, _e;
if (state.name) {

@@ -238,7 +248,5 @@ if (state.kind === RuleKinds.INTERFACE_DEF &&

if (state.kind === RuleKinds.NAMED_TYPE &&
state.prevState?.kind === RuleKinds.IMPLEMENTS) {
((_a = state.prevState) === null || _a === void 0 ? void 0 : _a.kind) === RuleKinds.IMPLEMENTS) {
if (typeInfo.interfaceDef) {
const existingType = typeInfo.interfaceDef
?.getInterfaces()
.find(({ name }) => name === state.name);
const existingType = (_b = typeInfo.interfaceDef) === null || _b === void 0 ? void 0 : _b.getInterfaces().find(({ name }) => name === state.name);
if (existingType) {

@@ -248,16 +256,11 @@ return;

const type = schema.getType(state.name);
const interfaceConfig = typeInfo.interfaceDef?.toConfig();
typeInfo.interfaceDef = new GraphQLInterfaceType({
...interfaceConfig,
interfaces: [
const interfaceConfig = (_c = typeInfo.interfaceDef) === null || _c === void 0 ? void 0 : _c.toConfig();
typeInfo.interfaceDef = new GraphQLInterfaceType(Object.assign(Object.assign({}, interfaceConfig), { interfaces: [
...interfaceConfig.interfaces,
type ||
new GraphQLInterfaceType({ name: state.name, fields: {} }),
],
});
] }));
}
else if (typeInfo.objectTypeDef) {
const existingType = typeInfo.objectTypeDef
?.getInterfaces()
.find(({ name }) => name === state.name);
const existingType = (_d = typeInfo.objectTypeDef) === null || _d === void 0 ? void 0 : _d.getInterfaces().find(({ name }) => name === state.name);
if (existingType) {

@@ -267,11 +270,8 @@ return;

const type = schema.getType(state.name);
const objectTypeConfig = typeInfo.objectTypeDef?.toConfig();
typeInfo.objectTypeDef = new GraphQLObjectType({
...objectTypeConfig,
interfaces: [
const objectTypeConfig = (_e = typeInfo.objectTypeDef) === null || _e === void 0 ? void 0 : _e.toConfig();
typeInfo.objectTypeDef = new GraphQLObjectType(Object.assign(Object.assign({}, objectTypeConfig), { interfaces: [
...objectTypeConfig.interfaces,
type ||
new GraphQLInterfaceType({ name: state.name, fields: {} }),
],
});
] }));
}

@@ -282,7 +282,7 @@ }

const currentTypeToExtend = typeInfo.interfaceDef || typeInfo.objectTypeDef;
const siblingInterfaces = currentTypeToExtend?.getInterfaces() || [];
const siblingInterfaces = (currentTypeToExtend === null || currentTypeToExtend === void 0 ? void 0 : currentTypeToExtend.getInterfaces()) || [];
const siblingInterfaceNames = siblingInterfaces.map(({ name }) => name);
const possibleInterfaces = schemaInterfaces
.concat([...inlineInterfaces].map(name => ({ name })))
.filter(({ name }) => name !== currentTypeToExtend?.name &&
.filter(({ name }) => name !== (currentTypeToExtend === null || currentTypeToExtend === void 0 ? void 0 : currentTypeToExtend.name) &&
!siblingInterfaceNames.includes(name));

@@ -295,3 +295,3 @@ return hintList(token, possibleInterfaces.map(type => {

};
if (type?.description) {
if (type === null || type === void 0 ? void 0 : type.description) {
result.documentation = type.description;

@@ -359,12 +359,13 @@ }

const getParentDefinition = (state, kind) => {
if (state.prevState?.kind === kind) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
if (((_a = state.prevState) === null || _a === void 0 ? void 0 : _a.kind) === kind) {
return state.prevState;
}
if (state.prevState?.prevState?.kind === kind) {
if (((_c = (_b = state.prevState) === null || _b === void 0 ? void 0 : _b.prevState) === null || _c === void 0 ? void 0 : _c.kind) === kind) {
return state.prevState.prevState;
}
if (state.prevState?.prevState?.prevState?.kind === kind) {
if (((_f = (_e = (_d = state.prevState) === null || _d === void 0 ? void 0 : _d.prevState) === null || _e === void 0 ? void 0 : _e.prevState) === null || _f === void 0 ? void 0 : _f.kind) === kind) {
return state.prevState.prevState.prevState;
}
if (state.prevState?.prevState?.prevState?.prevState?.kind === kind) {
if (((_k = (_j = (_h = (_g = state.prevState) === null || _g === void 0 ? void 0 : _g.prevState) === null || _h === void 0 ? void 0 : _h.prevState) === null || _j === void 0 ? void 0 : _j.prevState) === null || _k === void 0 ? void 0 : _k.kind) === kind) {
return state.prevState.prevState.prevState.prevState;

@@ -378,9 +379,9 @@ }

runOnlineParser(queryText, (_, state) => {
if (state?.kind === RuleKinds.VARIABLE && state.name) {
if ((state === null || state === void 0 ? void 0 : state.kind) === RuleKinds.VARIABLE && state.name) {
variableName = state.name;
}
if (state?.kind === RuleKinds.NAMED_TYPE && variableName) {
if ((state === null || state === void 0 ? void 0 : state.kind) === RuleKinds.NAMED_TYPE && variableName) {
const parentDefinition = getParentDefinition(state, RuleKinds.TYPE);
if (parentDefinition?.type) {
variableType = schema.getType(parentDefinition?.type);
if (parentDefinition === null || parentDefinition === void 0 ? void 0 : parentDefinition.type) {
variableType = schema.getType(parentDefinition === null || parentDefinition === void 0 ? void 0 : parentDefinition.type);
}

@@ -462,3 +463,3 @@ }

styleAtCursor = style;
stateAtCursor = { ...state };
stateAtCursor = Object.assign({}, state);
stringAtCursor = stream.current();

@@ -465,0 +466,0 @@ return 'BREAK';

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

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { locToRange, offsetToPosition } from '../utils';

@@ -18,25 +27,29 @@ export const LANGUAGE = 'GraphQL';

}
export async function getDefinitionQueryResultForNamedType(text, node, dependencies) {
const name = node.name.value;
const defNodes = dependencies.filter(({ definition }) => definition.name && definition.name.value === name);
if (defNodes.length === 0) {
throw Error(`Definition not found for GraphQL type ${name}`);
}
const definitions = defNodes.map(({ filePath, content, definition }) => getDefinitionForNodeDefinition(filePath || '', content, definition));
return {
definitions,
queryRange: definitions.map(_ => getRange(text, node)),
};
export function getDefinitionQueryResultForNamedType(text, node, dependencies) {
return __awaiter(this, void 0, void 0, function* () {
const name = node.name.value;
const defNodes = dependencies.filter(({ definition }) => definition.name && definition.name.value === name);
if (defNodes.length === 0) {
throw Error(`Definition not found for GraphQL type ${name}`);
}
const definitions = defNodes.map(({ filePath, content, definition }) => getDefinitionForNodeDefinition(filePath || '', content, definition));
return {
definitions,
queryRange: definitions.map(_ => getRange(text, node)),
};
});
}
export async function getDefinitionQueryResultForFragmentSpread(text, fragment, dependencies) {
const name = fragment.name.value;
const defNodes = dependencies.filter(({ definition }) => definition.name.value === name);
if (defNodes.length === 0) {
throw Error(`Definition not found for GraphQL fragment ${name}`);
}
const definitions = defNodes.map(({ filePath, content, definition }) => getDefinitionForFragmentDefinition(filePath || '', content, definition));
return {
definitions,
queryRange: definitions.map(_ => getRange(text, fragment)),
};
export function getDefinitionQueryResultForFragmentSpread(text, fragment, dependencies) {
return __awaiter(this, void 0, void 0, function* () {
const name = fragment.name.value;
const defNodes = dependencies.filter(({ definition }) => definition.name.value === name);
if (defNodes.length === 0) {
throw Error(`Definition not found for GraphQL fragment ${name}`);
}
const definitions = defNodes.map(({ filePath, content, definition }) => getDefinitionForFragmentDefinition(filePath || '', content, definition));
return {
definitions,
queryRange: definitions.map(_ => getRange(text, fragment)),
};
});
}

@@ -43,0 +56,0 @@ export function getDefinitionQueryResultForDefinitionNode(path, text, definition) {

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

const typeInfo = getTypeInfo(schema, token.state);
const options = { ...config, schema };
const options = Object.assign(Object.assign({}, config), { schema });
if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||

@@ -15,0 +15,0 @@ (kind === 'AliasedField' && step === 2 && typeInfo.fieldDef)) {

@@ -56,12 +56,9 @@ import { Kind, parse, visit, } from 'graphql';

tokenizedText.push(buildToken('plain', node.name));
return { tokenizedText, ...meta(node) };
return Object.assign({ tokenizedText }, meta(node));
},
OperationDefinition: (node) => ({
tokenizedText: [
OperationDefinition: (node) => (Object.assign({ tokenizedText: [
buildToken('keyword', node.operation),
buildToken('whitespace', ' '),
buildToken('class-name', node.name),
],
...meta(node),
}),
] }, meta(node))),
Document: (node) => node.definitions,

@@ -72,64 +69,37 @@ SelectionSet: (node) => concatMap(node.selections, (child) => {

Name: (node) => node.value,
FragmentDefinition: (node) => ({
tokenizedText: [
FragmentDefinition: (node) => (Object.assign({ tokenizedText: [
buildToken('keyword', 'fragment'),
buildToken('whitespace', ' '),
buildToken('class-name', node.name),
],
...meta(node),
}),
InterfaceTypeDefinition: (node) => ({
tokenizedText: [
] }, meta(node))),
InterfaceTypeDefinition: (node) => (Object.assign({ tokenizedText: [
buildToken('keyword', 'interface'),
buildToken('whitespace', ' '),
buildToken('class-name', node.name),
],
...meta(node),
}),
EnumTypeDefinition: (node) => ({
tokenizedText: [
] }, meta(node))),
EnumTypeDefinition: (node) => (Object.assign({ tokenizedText: [
buildToken('keyword', 'enum'),
buildToken('whitespace', ' '),
buildToken('class-name', node.name),
],
...meta(node),
}),
EnumValueDefinition: (node) => ({
tokenizedText: [buildToken('plain', node.name)],
...meta(node),
}),
ObjectTypeDefinition: (node) => ({
tokenizedText: [
] }, meta(node))),
EnumValueDefinition: (node) => (Object.assign({ tokenizedText: [buildToken('plain', node.name)] }, meta(node))),
ObjectTypeDefinition: (node) => (Object.assign({ tokenizedText: [
buildToken('keyword', 'type'),
buildToken('whitespace', ' '),
buildToken('class-name', node.name),
],
...meta(node),
}),
InputObjectTypeDefinition: (node) => ({
tokenizedText: [
] }, meta(node))),
InputObjectTypeDefinition: (node) => (Object.assign({ tokenizedText: [
buildToken('keyword', 'input'),
buildToken('whitespace', ' '),
buildToken('class-name', node.name),
],
...meta(node),
}),
FragmentSpread: (node) => ({
tokenizedText: [
] }, meta(node))),
FragmentSpread: (node) => (Object.assign({ tokenizedText: [
buildToken('plain', '...'),
buildToken('class-name', node.name),
],
...meta(node),
}),
] }, meta(node))),
InputValueDefinition: (node) => {
return {
tokenizedText: [buildToken('plain', node.name)],
...meta(node),
};
return Object.assign({ tokenizedText: [buildToken('plain', node.name)] }, meta(node));
},
FieldDefinition: (node) => {
return {
tokenizedText: [buildToken('plain', node.name)],
...meta(node),
};
return Object.assign({ tokenizedText: [buildToken('plain', node.name)] }, meta(node));
},

@@ -136,0 +106,0 @@ InlineFragment: (node) => node.selectionSet,

@@ -92,3 +92,3 @@ import { LexRules, ParseRules, isIgnored } from './Rules';

if (state.needsSeperator) {
expected = expected && expected?.separator;
expected = expected && (expected === null || expected === void 0 ? void 0 : expected.separator);
}

@@ -137,3 +137,3 @@ if (expected) {

}
state.prevState = { ...state };
state.prevState = Object.assign({}, state);
state.kind = ruleKind;

@@ -140,0 +140,0 @@ state.name = null;

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

};
export const RuleKinds = {
...Kind,
...AdditionalRuleKinds,
};
export const RuleKinds = Object.assign(Object.assign({}, Kind), AdditionalRuleKinds);
//# sourceMappingURL=types.js.map

@@ -21,8 +21,5 @@ import { parse, visit } from 'graphql';

const documentAST = parse(documentString);
return {
...getOperationASTFacts(documentAST, schema),
documentAST,
};
return Object.assign(Object.assign({}, getOperationASTFacts(documentAST, schema)), { documentAST });
}
catch {
catch (_a) {
return;

@@ -29,0 +26,0 @@ }

@@ -42,2 +42,3 @@ import { isEnumType, isInputObjectType, isListType, isNonNullType, isScalarType, } from 'graphql';

function getJSONSchemaFromGraphQLType(type, options) {
var _a;
let required = false;

@@ -54,3 +55,3 @@ let definition = Object.create(null);

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

@@ -92,3 +93,3 @@ if (isListType(type)) {

fieldDef.description = type.description + `\n` + renderTypeToString(type);
if (options?.useMarkdownDescription) {
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription =

@@ -100,3 +101,3 @@ type.description + `\n` + renderTypeToString(type, true);

fieldDef.description = renderTypeToString(type);
if (options?.useMarkdownDescription) {
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
fieldDef.markdownDescription = renderTypeToString(type, true);

@@ -109,6 +110,3 @@ }

const { definition: fieldDefinition, } = getJSONSchemaFromGraphQLType(field, options);
fieldDef.properties[fieldName] = {
...typeDefinition,
...fieldDefinition,
};
fieldDef.properties[fieldName] = Object.assign(Object.assign({}, typeDefinition), fieldDefinition);
const renderedField = renderTypeToString(field.type);

@@ -118,3 +116,3 @@ fieldDef.properties[fieldName].description = field.description

: renderedField;
if (options?.useMarkdownDescription) {
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
const renderedFieldMarkdown = renderTypeToString(field.type, true);

@@ -141,3 +139,3 @@ fieldDef.properties[fieldName].markdownDescription = field.description

definition.description = type.description + '\n' + renderTypeToString(type);
if (options?.useMarkdownDescription) {
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
definition.markdownDescription =

@@ -149,3 +147,3 @@ type.description + '\n' + renderTypeToString(type, true);

definition.description = renderTypeToString(type);
if (options?.useMarkdownDescription) {
if (options === null || options === void 0 ? void 0 : options.useMarkdownDescription) {
definition.markdownDescription = renderTypeToString(type, true);

@@ -165,9 +163,10 @@ }

Object.entries(variableToType).forEach(([variableName, type]) => {
var _a;
const { definition, required, definitions, } = getJSONSchemaFromGraphQLType(type, options);
jsonSchema.properties[variableName] = definition;
if (required) {
jsonSchema.required?.push(variableName);
(_a = jsonSchema.required) === null || _a === void 0 ? void 0 : _a.push(variableName);
}
if (definitions) {
jsonSchema.definitions = { ...jsonSchema?.definitions, ...definitions };
jsonSchema.definitions = Object.assign(Object.assign({}, jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.definitions), definitions);
}

@@ -174,0 +173,0 @@ });

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

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

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