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

graphql-language-service-interface

Package Overview
Dependencies
Maintainers
13
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 2.8.2 to 2.8.3

41

CHANGELOG.md

@@ -1,6 +0,9 @@

# Change Log
# graphql-language-service-interface
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## 2.8.3
### Patch Changes
- [`6869ce77`](https://github.com/graphql/graphiql/commit/6869ce7767050787db5f1017abf82fa5a52fc97a) [#1816](https://github.com/graphql/graphiql/pull/1816) Thanks [@acao](https://github.com/acao)! - improve peer resolutions for graphql 14 & 15. `14.5.0` minimum is for built-in typescript types, and another method only available in `14.4.0`
## [2.8.2](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.8.1...graphql-language-service-interface@2.8.2) (2021-01-07)

@@ -16,3 +19,3 @@

# [2.8.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.7.0...graphql-language-service-interface@2.8.0) (2021-01-07)
## [2.8.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.7.0...graphql-language-service-interface@2.8.0) (2021-01-07)

@@ -23,3 +26,3 @@ ### Features

# [2.7.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.6.0...graphql-language-service-interface@2.7.0) (2021-01-03)
## [2.7.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.6.0...graphql-language-service-interface@2.7.0) (2021-01-03)

@@ -30,3 +33,3 @@ ### Features

# [2.6.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.5.0...graphql-language-service-interface@2.6.0) (2020-12-28)
## [2.6.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.5.0...graphql-language-service-interface@2.6.0) (2020-12-28)

@@ -37,3 +40,3 @@ ### Features

# [2.5.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.3...graphql-language-service-interface@2.5.0) (2020-12-08)
## [2.5.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.3...graphql-language-service-interface@2.5.0) (2020-12-08)

@@ -76,3 +79,3 @@ ### Bug Fixes

# [2.4.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.11...graphql-language-service-interface@2.4.0) (2020-06-11)
## [2.4.0](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.11...graphql-language-service-interface@2.4.0) (2020-06-11)

@@ -83,7 +86,7 @@ ### Bug Fixes

# [2.4.0-alpha.11](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.10...graphql-language-service-interface@2.4.0-alpha.11) (2020-06-04)
## [2.4.0-alpha.11](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.10...graphql-language-service-interface@2.4.0-alpha.11) (2020-06-04)
**Note:** Version bump only for package graphql-language-service-interface
# [2.4.0-alpha.10](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.9...graphql-language-service-interface@2.4.0-alpha.10) (2020-06-04)
## [2.4.0-alpha.10](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.9...graphql-language-service-interface@2.4.0-alpha.10) (2020-06-04)

@@ -94,3 +97,3 @@ ### Bug Fixes

# [2.4.0-alpha.9](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.8...graphql-language-service-interface@2.4.0-alpha.9) (2020-05-28)
## [2.4.0-alpha.9](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.8...graphql-language-service-interface@2.4.0-alpha.9) (2020-05-28)

@@ -101,3 +104,3 @@ ### Bug Fixes

# [2.4.0-alpha.8](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.7...graphql-language-service-interface@2.4.0-alpha.8) (2020-05-17)
## [2.4.0-alpha.8](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.7...graphql-language-service-interface@2.4.0-alpha.8) (2020-05-17)

@@ -115,3 +118,3 @@ ### Bug Fixes

# [2.4.0-alpha.7](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.6...graphql-language-service-interface@2.4.0-alpha.7) (2020-04-10)
## [2.4.0-alpha.7](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.6...graphql-language-service-interface@2.4.0-alpha.7) (2020-04-10)

@@ -122,7 +125,7 @@ ### Bug Fixes

# [2.4.0-alpha.6](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.5...graphql-language-service-interface@2.4.0-alpha.6) (2020-04-10)
## [2.4.0-alpha.6](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.5...graphql-language-service-interface@2.4.0-alpha.6) (2020-04-10)
**Note:** Version bump only for package graphql-language-service-interface
# [2.4.0-alpha.5](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.4...graphql-language-service-interface@2.4.0-alpha.5) (2020-04-06)
## [2.4.0-alpha.5](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.4...graphql-language-service-interface@2.4.0-alpha.5) (2020-04-06)

@@ -134,11 +137,11 @@ ### Features

# [2.4.0-alpha.4](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.3...graphql-language-service-interface@2.4.0-alpha.4) (2020-04-03)
## [2.4.0-alpha.4](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.3...graphql-language-service-interface@2.4.0-alpha.4) (2020-04-03)
**Note:** Version bump only for package graphql-language-service-interface
# [2.4.0-alpha.3](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.2...graphql-language-service-interface@2.4.0-alpha.3) (2020-03-20)
## [2.4.0-alpha.3](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.2...graphql-language-service-interface@2.4.0-alpha.3) (2020-03-20)
**Note:** Version bump only for package graphql-language-service-interface
# [2.4.0-alpha.2](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.0...graphql-language-service-interface@2.4.0-alpha.2) (2020-03-20)
## [2.4.0-alpha.2](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.4.0-alpha.0...graphql-language-service-interface@2.4.0-alpha.2) (2020-03-20)

@@ -155,3 +158,3 @@ ### Bug Fixes

# [2.4.0-alpha.1](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.3.3...graphql-language-service-interface@2.4.0-alpha.1) (2020-01-18)
## [2.4.0-alpha.1](https://github.com/graphql/graphiql/compare/graphql-language-service-interface@2.3.3...graphql-language-service-interface@2.4.0-alpha.1) (2020-01-18)

@@ -158,0 +161,0 @@ ### Features

@@ -0,5 +1,6 @@

import type CodeMirror from 'codemirror';
import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql';
import { CompletionItem, AllTypeInfo, IPosition } from 'graphql-language-service-types';
import { CharacterStream, ContextToken, State } from 'graphql-language-service-parser';
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextToken, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>;
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: CodeMirror.Token, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>;
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, forcePrefix?: boolean): CompletionItem[];

@@ -6,0 +7,0 @@ export declare function getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>;

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

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHoverInformation = exports.getOutline = void 0;
__exportStar(require("./autocompleteUtils"), exports);

@@ -15,0 +16,0 @@ __exportStar(require("./getAutocompleteSuggestions"), exports);

@@ -0,5 +1,6 @@

import type CodeMirror from 'codemirror';
import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql';
import { CompletionItem, AllTypeInfo, IPosition } from 'graphql-language-service-types';
import { CharacterStream, ContextToken, State } from 'graphql-language-service-parser';
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextToken, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>;
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: CodeMirror.Token, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>;
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, forcePrefix?: boolean): CompletionItem[];

@@ -6,0 +7,0 @@ export declare function getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>;

@@ -20,3 +20,2 @@ import { CompletionItemKind } from 'vscode-languageserver-types';

export function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs) {
var _a;
const token = contextToken || getTokenAtPosition(queryText, cursor);

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

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

@@ -54,12 +53,9 @@ }

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

@@ -74,12 +70,9 @@ }

: CompletionItemKind.Field;
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,
});
}));
return hintList(token, objectFields.map(field => ({
label: field.name,
detail: String(field.type),
documentation: field.description ?? undefined,
kind: completionKind,
type: field.type,
})));
}

@@ -96,3 +89,3 @@ }

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

@@ -137,16 +130,13 @@ if ((kind === RuleKinds.TYPE_CONDITION && step === 1) ||

}
return hintList(token, fields.map((field, index) => {
var _a;
return ({
sortText: String(index) + field.name,
label: field.name,
detail: String(field.type),
documentation: (_a = field.description) !== null && _a !== void 0 ? _a : undefined,
deprecated: field.isDeprecated,
isDeprecated: field.isDeprecated,
deprecationReason: field.deprecationReason,
kind: CompletionItemKind.Field,
type: field.type,
});
}));
return hintList(token, fields.map((field, index) => ({
sortText: String(index) + field.name,
label: field.name,
detail: String(field.type),
documentation: field.description ?? undefined,
deprecated: field.isDeprecated,
isDeprecated: field.isDeprecated,
deprecationReason: field.deprecationReason,
kind: CompletionItemKind.Field,
type: field.type,
})));
}

@@ -161,15 +151,12 @@ return [];

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

@@ -206,3 +193,2 @@ }

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

@@ -214,5 +200,7 @@ if (state.kind === RuleKinds.INTERFACE_DEF &&

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

@@ -222,11 +210,16 @@ return;

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

@@ -236,8 +229,11 @@ return;

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

@@ -248,7 +244,7 @@ }

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

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

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

@@ -325,13 +321,12 @@ }

const getParentDefinition = (state, 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) {
if (state.prevState?.kind === kind) {
return state.prevState;
}
if (((_c = (_b = state.prevState) === null || _b === void 0 ? void 0 : _b.prevState) === null || _c === void 0 ? void 0 : _c.kind) === kind) {
if (state.prevState?.prevState?.kind === kind) {
return state.prevState.prevState;
}
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) {
if (state.prevState?.prevState?.prevState?.kind === kind) {
return state.prevState.prevState.prevState;
}
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) {
if (state.prevState?.prevState?.prevState?.prevState?.kind === kind) {
return state.prevState.prevState.prevState.prevState;

@@ -350,4 +345,4 @@ }

const parentDefinition = getParentDefinition(state, RuleKinds.TYPE);
if (parentDefinition === null || parentDefinition === void 0 ? void 0 : parentDefinition.type) {
variableType = schema.getType(parentDefinition === null || parentDefinition === void 0 ? void 0 : parentDefinition.type);
if (parentDefinition?.type) {
variableType = schema.getType(parentDefinition?.type);
}

@@ -431,3 +426,3 @@ }

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

@@ -434,0 +429,0 @@ return 'BREAK';

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

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 'graphql-language-service-utils';

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

}
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 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 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)),
};
});
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)),
};
}

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

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

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

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

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

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

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

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 { SymbolKind, } from 'vscode-languageserver-types';

@@ -54,190 +45,174 @@ import { Kind, parse, print } from 'graphql';

}
getDiagnostics(query, uri, isRelayCompatMode) {
return __awaiter(this, void 0, void 0, function* () {
let queryHasExtensions = false;
const projectConfig = this.getConfigForURI(uri);
if (!projectConfig) {
return [];
async getDiagnostics(query, uri, isRelayCompatMode) {
let queryHasExtensions = false;
const projectConfig = this.getConfigForURI(uri);
if (!projectConfig) {
return [];
}
const { schema: schemaPath, name: projectName, extensions } = projectConfig;
try {
const queryAST = parse(query);
if (!schemaPath || uri !== schemaPath) {
queryHasExtensions = queryAST.definitions.some(definition => {
switch (definition.kind) {
case OBJECT_TYPE_DEFINITION:
case INTERFACE_TYPE_DEFINITION:
case ENUM_TYPE_DEFINITION:
case UNION_TYPE_DEFINITION:
case SCALAR_TYPE_DEFINITION:
case INPUT_OBJECT_TYPE_DEFINITION:
case SCALAR_TYPE_EXTENSION:
case OBJECT_TYPE_EXTENSION:
case INTERFACE_TYPE_EXTENSION:
case UNION_TYPE_EXTENSION:
case ENUM_TYPE_EXTENSION:
case INPUT_OBJECT_TYPE_EXTENSION:
case DIRECTIVE_DEFINITION:
return true;
}
return false;
});
}
const { schema: schemaPath, name: projectName, extensions } = projectConfig;
try {
const queryAST = parse(query);
if (!schemaPath || uri !== schemaPath) {
queryHasExtensions = queryAST.definitions.some(definition => {
switch (definition.kind) {
case OBJECT_TYPE_DEFINITION:
case INTERFACE_TYPE_DEFINITION:
case ENUM_TYPE_DEFINITION:
case UNION_TYPE_DEFINITION:
case SCALAR_TYPE_DEFINITION:
case INPUT_OBJECT_TYPE_DEFINITION:
case SCALAR_TYPE_EXTENSION:
case OBJECT_TYPE_EXTENSION:
case INTERFACE_TYPE_EXTENSION:
case UNION_TYPE_EXTENSION:
case ENUM_TYPE_EXTENSION:
case INPUT_OBJECT_TYPE_EXTENSION:
case DIRECTIVE_DEFINITION:
return true;
}
return false;
});
}
}
catch (error) {
const range = getRange(error.locations[0], query);
return [
{
severity: DIAGNOSTIC_SEVERITY.Error,
message: error.message,
source: 'GraphQL: Syntax',
range,
},
];
}
let source = query;
const fragmentDefinitions = yield this._graphQLCache.getFragmentDefinitions(projectConfig);
const fragmentDependencies = yield this._graphQLCache.getFragmentDependencies(query, fragmentDefinitions);
const dependenciesSource = fragmentDependencies.reduce((prev, cur) => `${prev} ${print(cur.definition)}`, '');
source = `${source} ${dependenciesSource}`;
let validationAst = null;
try {
validationAst = parse(source);
}
catch (error) {
return [];
}
let customRules = null;
if ((extensions === null || extensions === void 0 ? void 0 : extensions.customValidationRules) &&
typeof extensions.customValidationRules === 'function') {
customRules = extensions.customValidationRules(this._graphQLConfig);
}
const schema = yield this._graphQLCache.getSchema(projectName, queryHasExtensions);
if (!schema) {
return [];
}
return validateQuery(validationAst, schema, customRules, isRelayCompatMode);
});
}
getAutocompleteSuggestions(query, position, filePath) {
return __awaiter(this, void 0, void 0, function* () {
const projectConfig = this.getConfigForURI(filePath);
const schema = yield this._graphQLCache.getSchema(projectConfig.name);
const fragmentDefinitions = yield this._graphQLCache.getFragmentDefinitions(projectConfig);
const fragmentInfo = Array.from(fragmentDefinitions).map(([, info]) => info.definition);
if (schema) {
return getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo);
}
}
catch (error) {
const range = getRange(error.locations[0], query);
return [
{
severity: DIAGNOSTIC_SEVERITY.Error,
message: error.message,
source: 'GraphQL: Syntax',
range,
},
];
}
let source = query;
const fragmentDefinitions = await this._graphQLCache.getFragmentDefinitions(projectConfig);
const fragmentDependencies = await this._graphQLCache.getFragmentDependencies(query, fragmentDefinitions);
const dependenciesSource = fragmentDependencies.reduce((prev, cur) => `${prev} ${print(cur.definition)}`, '');
source = `${source} ${dependenciesSource}`;
let validationAst = null;
try {
validationAst = parse(source);
}
catch (error) {
return [];
});
}
let customRules = null;
if (extensions?.customValidationRules &&
typeof extensions.customValidationRules === 'function') {
customRules = extensions.customValidationRules(this._graphQLConfig);
}
const schema = await this._graphQLCache.getSchema(projectName, queryHasExtensions);
if (!schema) {
return [];
}
return validateQuery(validationAst, schema, customRules, isRelayCompatMode);
}
getHoverInformation(query, position, filePath) {
return __awaiter(this, void 0, void 0, function* () {
const projectConfig = this.getConfigForURI(filePath);
const schema = yield this._graphQLCache.getSchema(projectConfig.name);
if (schema) {
return getHoverInformation(schema, query, position);
}
return '';
});
async getAutocompleteSuggestions(query, position, filePath) {
const projectConfig = this.getConfigForURI(filePath);
const schema = await this._graphQLCache.getSchema(projectConfig.name);
const fragmentDefinitions = await this._graphQLCache.getFragmentDefinitions(projectConfig);
const fragmentInfo = Array.from(fragmentDefinitions).map(([, info]) => info.definition);
if (schema) {
return getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo);
}
return [];
}
getDefinition(query, position, filePath) {
return __awaiter(this, void 0, void 0, function* () {
const projectConfig = this.getConfigForURI(filePath);
let ast;
try {
ast = parse(query);
async getHoverInformation(query, position, filePath) {
const projectConfig = this.getConfigForURI(filePath);
const schema = await this._graphQLCache.getSchema(projectConfig.name);
if (schema) {
return getHoverInformation(schema, query, position);
}
return '';
}
async getDefinition(query, position, filePath) {
const projectConfig = this.getConfigForURI(filePath);
let ast;
try {
ast = parse(query);
}
catch (error) {
return null;
}
const node = getASTNodeAtPosition(query, ast, position);
if (node) {
switch (node.kind) {
case FRAGMENT_SPREAD:
return this._getDefinitionForFragmentSpread(query, ast, node, filePath, projectConfig);
case FRAGMENT_DEFINITION:
case OPERATION_DEFINITION:
return getDefinitionQueryResultForDefinitionNode(filePath, query, node);
case NAMED_TYPE:
return this._getDefinitionForNamedType(query, ast, node, filePath, projectConfig);
}
catch (error) {
return null;
}
const node = getASTNodeAtPosition(query, ast, position);
if (node) {
switch (node.kind) {
case FRAGMENT_SPREAD:
return this._getDefinitionForFragmentSpread(query, ast, node, filePath, projectConfig);
case FRAGMENT_DEFINITION:
case OPERATION_DEFINITION:
return getDefinitionQueryResultForDefinitionNode(filePath, query, node);
case NAMED_TYPE:
return this._getDefinitionForNamedType(query, ast, node, filePath, projectConfig);
}
}
return null;
});
}
return null;
}
getDocumentSymbols(document, filePath) {
return __awaiter(this, void 0, void 0, function* () {
const outline = yield this.getOutline(document);
if (!outline) {
async getDocumentSymbols(document, filePath) {
const outline = await this.getOutline(document);
if (!outline) {
return [];
}
const output = [];
const input = outline.outlineTrees.map((tree) => [null, tree]);
while (input.length > 0) {
const res = input.pop();
if (!res) {
return [];
}
const output = [];
const input = outline.outlineTrees.map((tree) => [null, tree]);
while (input.length > 0) {
const res = input.pop();
if (!res) {
return [];
}
const [parent, tree] = res;
if (!tree) {
return [];
}
output.push({
name: tree.representativeName,
kind: getKind(tree),
location: {
uri: filePath,
range: {
start: tree.startPosition,
end: tree.endPosition,
},
const [parent, tree] = res;
if (!tree) {
return [];
}
output.push({
name: tree.representativeName,
kind: getKind(tree),
location: {
uri: filePath,
range: {
start: tree.startPosition,
end: tree.endPosition,
},
containerName: parent ? parent.representativeName : undefined,
});
input.push(...tree.children.map(child => [tree, child]));
}
return output;
});
},
containerName: parent ? parent.representativeName : undefined,
});
input.push(...tree.children.map(child => [tree, child]));
}
return output;
}
_getDefinitionForNamedType(query, ast, node, filePath, projectConfig) {
return __awaiter(this, void 0, void 0, function* () {
const objectTypeDefinitions = yield this._graphQLCache.getObjectTypeDefinitions(projectConfig);
const dependencies = yield this._graphQLCache.getObjectTypeDependenciesForAST(ast, objectTypeDefinitions);
const localObjectTypeDefinitions = ast.definitions.filter(definition => definition.kind === OBJECT_TYPE_DEFINITION ||
definition.kind === INPUT_OBJECT_TYPE_DEFINITION ||
definition.kind === ENUM_TYPE_DEFINITION ||
definition.kind === SCALAR_TYPE_DEFINITION ||
definition.kind === INTERFACE_TYPE_DEFINITION);
const typeCastedDefs = localObjectTypeDefinitions;
const localOperationDefinationInfos = typeCastedDefs.map((definition) => ({
filePath,
content: query,
definition,
}));
const result = yield getDefinitionQueryResultForNamedType(query, node, dependencies.concat(localOperationDefinationInfos));
return result;
});
async _getDefinitionForNamedType(query, ast, node, filePath, projectConfig) {
const objectTypeDefinitions = await this._graphQLCache.getObjectTypeDefinitions(projectConfig);
const dependencies = await this._graphQLCache.getObjectTypeDependenciesForAST(ast, objectTypeDefinitions);
const localObjectTypeDefinitions = ast.definitions.filter(definition => definition.kind === OBJECT_TYPE_DEFINITION ||
definition.kind === INPUT_OBJECT_TYPE_DEFINITION ||
definition.kind === ENUM_TYPE_DEFINITION ||
definition.kind === SCALAR_TYPE_DEFINITION ||
definition.kind === INTERFACE_TYPE_DEFINITION);
const typeCastedDefs = localObjectTypeDefinitions;
const localOperationDefinationInfos = typeCastedDefs.map((definition) => ({
filePath,
content: query,
definition,
}));
const result = await getDefinitionQueryResultForNamedType(query, node, dependencies.concat(localOperationDefinationInfos));
return result;
}
_getDefinitionForFragmentSpread(query, ast, node, filePath, projectConfig) {
return __awaiter(this, void 0, void 0, function* () {
const fragmentDefinitions = yield this._graphQLCache.getFragmentDefinitions(projectConfig);
const dependencies = yield this._graphQLCache.getFragmentDependenciesForAST(ast, fragmentDefinitions);
const localFragDefinitions = ast.definitions.filter(definition => definition.kind === FRAGMENT_DEFINITION);
const typeCastedDefs = localFragDefinitions;
const localFragInfos = typeCastedDefs.map((definition) => ({
filePath,
content: query,
definition,
}));
const result = yield getDefinitionQueryResultForFragmentSpread(query, node, dependencies.concat(localFragInfos));
return result;
});
async _getDefinitionForFragmentSpread(query, ast, node, filePath, projectConfig) {
const fragmentDefinitions = await this._graphQLCache.getFragmentDefinitions(projectConfig);
const dependencies = await this._graphQLCache.getFragmentDependenciesForAST(ast, fragmentDefinitions);
const localFragDefinitions = ast.definitions.filter(definition => definition.kind === FRAGMENT_DEFINITION);
const typeCastedDefs = localFragDefinitions;
const localFragInfos = typeCastedDefs.map((definition) => ({
filePath,
content: query,
definition,
}));
const result = await getDefinitionQueryResultForFragmentSpread(query, node, dependencies.concat(localFragInfos));
return result;
}
getOutline(documentText) {
return __awaiter(this, void 0, void 0, function* () {
return getOutline(documentText);
});
async getOutline(documentText) {
return getOutline(documentText);
}
}
//# sourceMappingURL=GraphQLLanguageService.js.map
{
"name": "graphql-language-service-interface",
"version": "2.8.2",
"version": "2.8.3",
"description": "Interface to the GraphQL Language Service",

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

"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0"
"graphql": ">= v14.5.0 <= 15.5.0"
},

@@ -38,4 +38,3 @@ "dependencies": {

"graphql-config": "^3.0.2"
},
"gitHead": "5a26a22e9bc0b6822bcc46a1c8297ddcec2d86be"
}
}

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