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.9.6-canary-eb5c4300.0 to 2.9.6-canary-fae7d199.0

6

dist/getAutocompleteSuggestions.d.ts
import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql';
import { CompletionItem, AllTypeInfo, IPosition } from 'graphql-language-service-types';
import { CharacterStream, ContextToken, State, ContextTokenForCodeMirror } from 'graphql-language-service-parser';
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>;
export declare type AutocompleteSuggestionOptions = {
fillLeafsOnComplete?: boolean;
schema?: GraphQLSchema;
};
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string, options?: AutocompleteSuggestionOptions): Array<CompletionItem>;
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, token: ContextToken): CompletionItem[];

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

@@ -9,2 +9,3 @@ "use strict";

const autocompleteUtils_1 = require("./autocompleteUtils");
const graphql_language_service_utils_1 = require("graphql-language-service-utils");
const collectFragmentDefs = (op) => {

@@ -23,4 +24,5 @@ const externalFragments = [];

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

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

kind === graphql_language_service_parser_1.RuleKinds.ALIASED_FIELD) {
return getSuggestionsForFieldNames(token, typeInfo, schema);
return getSuggestionsForFieldNames(token, typeInfo, opts);
}

@@ -131,3 +133,37 @@ if (kind === graphql_language_service_parser_1.RuleKinds.ARGUMENTS ||

exports.getAutocompleteSuggestions = getAutocompleteSuggestions;
function getSuggestionsForFieldNames(token, typeInfo, schema) {
const insertSuffix = ` {\n $1\n}`;
const appendInsertText = (field, type, options) => {
if (options === null || options === void 0 ? void 0 : options.fillLeafsOnComplete) {
const selectionSet = graphql_language_service_utils_1.buildSelectionSet(field, type, graphql_language_service_utils_1.defaultGetDefaultFieldNames, options.schema);
if (selectionSet) {
return ` ${graphql_1.print(selectionSet)}`;
}
}
return insertSuffix;
};
const getInsertText = (field, options) => {
var _a;
const type = field.type;
if (graphql_2.isCompositeType(type)) {
return appendInsertText(field, type, options);
}
if (graphql_1.isListType(type)) {
if ('ofType' in type) {
return appendInsertText(field, type === null || type === void 0 ? void 0 : type.ofType, options);
}
}
if (graphql_1.isNonNullType(type)) {
if ('ofType' in type) {
if (graphql_1.isObjectType(type.ofType)) {
return appendInsertText(field, type.ofType, options);
}
if (graphql_1.isListType(type.ofType)) {
return appendInsertText(field, (_a = type === null || type === void 0 ? void 0 : type.ofType) === null || _a === void 0 ? void 0 : _a.ofType, options);
}
}
}
return null;
};
function getSuggestionsForFieldNames(token, typeInfo, options) {
var _a;
if (typeInfo.parentType) {

@@ -142,3 +178,3 @@ const parentType = typeInfo.parentType;

}
if (parentType === schema.getQueryType()) {
if (parentType === ((_a = options === null || options === void 0 ? void 0 : options.schema) === null || _a === void 0 ? void 0 : _a.getQueryType())) {
fields.push(graphql_2.SchemaMetaFieldDef, graphql_2.TypeMetaFieldDef);

@@ -148,5 +184,9 @@ }

var _a;
return ({
if (field.name === 'securityAdvisories') {
console.log(field);
}
const suggestion = {
sortText: String(index) + field.name,
label: field.name,
insertTextFormat: vscode_languageserver_types_1.InsertTextFormat.Snippet,
detail: String(field.type),

@@ -159,3 +199,8 @@ documentation: (_a = field.description) !== null && _a !== void 0 ? _a : undefined,

type: field.type,
});
};
const insertText = getInsertText(field, options);
if (insertText) {
suggestion.insertText = field.name + insertText;
}
return suggestion;
}));

@@ -162,0 +207,0 @@ }

3

dist/GraphQLLanguageService.d.ts

@@ -7,2 +7,3 @@ import { DocumentNode, FragmentSpreadNode, NamedTypeNode } from 'graphql';

import { DefinitionQueryResult } from './getDefinition';
import { AutocompleteSuggestionOptions } from '.';
export declare class GraphQLLanguageService {

@@ -14,3 +15,3 @@ _graphQLCache: GraphQLCache;

getDiagnostics(query: string, uri: Uri, isRelayCompatMode?: boolean): Promise<Array<Diagnostic>>;
getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri): Promise<Array<CompletionItem>>;
getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri, options?: AutocompleteSuggestionOptions): Promise<Array<CompletionItem>>;
getHoverInformation(query: string, position: IPosition, filePath: Uri, options?: HoverConfig): Promise<Hover['contents']>;

@@ -17,0 +18,0 @@ getDefinition(query: string, position: IPosition, filePath: Uri): Promise<DefinitionQueryResult | null>;

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

}
getAutocompleteSuggestions(query, position, filePath) {
getAutocompleteSuggestions(query, position, filePath, options) {
return __awaiter(this, void 0, void 0, function* () {

@@ -132,3 +132,3 @@ const projectConfig = this.getConfigForURI(filePath);

if (schema) {
return getAutocompleteSuggestions_1.getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo);
return getAutocompleteSuggestions_1.getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo, options);
}

@@ -135,0 +135,0 @@ return [];

@@ -6,4 +6,4 @@ export * from './autocompleteUtils';

export { getOutline } from './getOutline';
export { getHoverInformation } from './getHoverInformation';
export { getHoverInformation, HoverConfig } from './getHoverInformation';
export * from './GraphQLLanguageService';
//# sourceMappingURL=index.d.ts.map
import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql';
import { CompletionItem, AllTypeInfo, IPosition } from 'graphql-language-service-types';
import { CharacterStream, ContextToken, State, ContextTokenForCodeMirror } from 'graphql-language-service-parser';
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>;
export declare type AutocompleteSuggestionOptions = {
fillLeafsOnComplete?: boolean;
schema?: GraphQLSchema;
};
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string, options?: AutocompleteSuggestionOptions): Array<CompletionItem>;
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, token: ContextToken): CompletionItem[];

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

@@ -1,6 +0,7 @@

import { CompletionItemKind } from 'vscode-languageserver-types';
import { isInterfaceType, GraphQLInterfaceType, GraphQLObjectType, Kind, DirectiveLocation, } from 'graphql';
import { CompletionItemKind, InsertTextFormat, } from 'vscode-languageserver-types';
import { isInterfaceType, GraphQLInterfaceType, GraphQLObjectType, Kind, DirectiveLocation, isObjectType, isListType, isNonNullType, print, } from 'graphql';
import { GraphQLBoolean, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, assertAbstractType, doTypesOverlap, getNamedType, getNullableType, isAbstractType, isCompositeType, isInputType, visit, parse, } from 'graphql';
import { CharacterStream, onlineParser, RuleKinds, } from 'graphql-language-service-parser';
import { forEachState, getDefinitionState, getFieldDef, hintList, objectValues, } from './autocompleteUtils';
import { buildSelectionSet, defaultGetDefaultFieldNames, } from 'graphql-language-service-utils';
const collectFragmentDefs = (op) => {

@@ -19,4 +20,5 @@ const externalFragments = [];

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

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

kind === RuleKinds.ALIASED_FIELD) {
return getSuggestionsForFieldNames(token, typeInfo, schema);
return getSuggestionsForFieldNames(token, typeInfo, opts);
}

@@ -126,3 +128,37 @@ if (kind === RuleKinds.ARGUMENTS ||

}
function getSuggestionsForFieldNames(token, typeInfo, schema) {
const insertSuffix = ` {\n $1\n}`;
const appendInsertText = (field, type, options) => {
if (options === null || options === void 0 ? void 0 : options.fillLeafsOnComplete) {
const selectionSet = buildSelectionSet(field, type, defaultGetDefaultFieldNames, options.schema);
if (selectionSet) {
return ` ${print(selectionSet)}`;
}
}
return insertSuffix;
};
const getInsertText = (field, options) => {
var _a;
const type = field.type;
if (isCompositeType(type)) {
return appendInsertText(field, type, options);
}
if (isListType(type)) {
if ('ofType' in type) {
return appendInsertText(field, type === null || type === void 0 ? void 0 : type.ofType, options);
}
}
if (isNonNullType(type)) {
if ('ofType' in type) {
if (isObjectType(type.ofType)) {
return appendInsertText(field, type.ofType, options);
}
if (isListType(type.ofType)) {
return appendInsertText(field, (_a = type === null || type === void 0 ? void 0 : type.ofType) === null || _a === void 0 ? void 0 : _a.ofType, options);
}
}
}
return null;
};
function getSuggestionsForFieldNames(token, typeInfo, options) {
var _a;
if (typeInfo.parentType) {

@@ -137,3 +173,3 @@ const parentType = typeInfo.parentType;

}
if (parentType === 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);

@@ -143,5 +179,9 @@ }

var _a;
return ({
if (field.name === 'securityAdvisories') {
console.log(field);
}
const suggestion = {
sortText: String(index) + field.name,
label: field.name,
insertTextFormat: InsertTextFormat.Snippet,
detail: String(field.type),

@@ -154,3 +194,8 @@ documentation: (_a = field.description) !== null && _a !== void 0 ? _a : undefined,

type: field.type,
});
};
const insertText = getInsertText(field, options);
if (insertText) {
suggestion.insertText = field.name + insertText;
}
return suggestion;
}));

@@ -157,0 +202,0 @@ }

@@ -7,2 +7,3 @@ import { DocumentNode, FragmentSpreadNode, NamedTypeNode } from 'graphql';

import { DefinitionQueryResult } from './getDefinition';
import { AutocompleteSuggestionOptions } from '.';
export declare class GraphQLLanguageService {

@@ -14,3 +15,3 @@ _graphQLCache: GraphQLCache;

getDiagnostics(query: string, uri: Uri, isRelayCompatMode?: boolean): Promise<Array<Diagnostic>>;
getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri): Promise<Array<CompletionItem>>;
getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri, options?: AutocompleteSuggestionOptions): Promise<Array<CompletionItem>>;
getHoverInformation(query: string, position: IPosition, filePath: Uri, options?: HoverConfig): Promise<Hover['contents']>;

@@ -17,0 +18,0 @@ getDefinition(query: string, position: IPosition, filePath: Uri): Promise<DefinitionQueryResult | null>;

@@ -121,3 +121,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

}
getAutocompleteSuggestions(query, position, filePath) {
getAutocompleteSuggestions(query, position, filePath, options) {
return __awaiter(this, void 0, void 0, function* () {

@@ -129,3 +129,3 @@ const projectConfig = this.getConfigForURI(filePath);

if (schema) {
return getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo);
return getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo, options);
}

@@ -132,0 +132,0 @@ return [];

@@ -6,4 +6,4 @@ export * from './autocompleteUtils';

export { getOutline } from './getOutline';
export { getHoverInformation } from './getHoverInformation';
export { getHoverInformation, HoverConfig } from './getHoverInformation';
export * from './GraphQLLanguageService';
//# sourceMappingURL=index.d.ts.map
{
"name": "graphql-language-service-interface",
"version": "2.9.6-canary-eb5c4300.0",
"version": "2.9.6-canary-fae7d199.0",
"description": "Interface to the GraphQL Language Service",

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

"graphql-language-service-types": "^1.8.6",
"graphql-language-service-utils": "^2.6.3",
"graphql-language-service-utils": "^2.7.0-canary-fae7d199.0",
"vscode-languageserver-types": "^3.15.1"

@@ -37,0 +37,0 @@ },

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

*/
import { CompletionItemKind } from 'vscode-languageserver-types';
import {
CompletionItemKind,
InsertTextFormat,
} from 'vscode-languageserver-types';

@@ -28,2 +31,7 @@ import {

GraphQLArgument,
isObjectType,
isListType,
isNonNullType,
GraphQLOutputType,
print,
} from 'graphql';

@@ -74,2 +82,6 @@

} from './autocompleteUtils';
import {
buildSelectionSet,
defaultGetDefaultFieldNames,
} from 'graphql-language-service-utils';

@@ -93,2 +105,7 @@ const collectFragmentDefs = (op: string | undefined) => {

export type AutocompleteSuggestionOptions = {
fillLeafsOnComplete?: boolean;
schema?: GraphQLSchema;
};
/**

@@ -104,3 +121,8 @@ * Given GraphQLSchema, queryText, and context of the current position within

fragmentDefs?: FragmentDefinitionNode[] | string,
options?: AutocompleteSuggestionOptions,
): Array<CompletionItem> {
const opts = {
...options,
schema,
};
const token: ContextToken =

@@ -119,3 +141,2 @@ contextToken || getTokenAtPosition(queryText, cursor);

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

@@ -153,3 +174,3 @@ // Definition kinds

) {
return getSuggestionsForFieldNames(token, typeInfo, schema);
return getSuggestionsForFieldNames(token, typeInfo, opts);
}

@@ -280,2 +301,54 @@

const insertSuffix = ` {\n $1\n}`;
const appendInsertText = (
field: GraphQLField<null, null>,
type: GraphQLOutputType,
options?: AutocompleteSuggestionOptions,
) => {
if (options?.fillLeafsOnComplete) {
const selectionSet = buildSelectionSet(
field,
type,
defaultGetDefaultFieldNames,
options.schema,
);
if (selectionSet) {
return ` ${print(selectionSet)}`;
}
}
return insertSuffix;
};
const getInsertText = (
field: GraphQLField<null, null>,
options?: AutocompleteSuggestionOptions,
) => {
const type = field.type;
if (isCompositeType(type)) {
return appendInsertText(field, type, options);
}
if (isListType(type)) {
if ('ofType' in type) {
return appendInsertText(field, type?.ofType, options);
}
}
if (isNonNullType(type)) {
if ('ofType' in type) {
if (isObjectType(type.ofType)) {
return appendInsertText(field, type.ofType, options);
}
if (isListType(type.ofType)) {
return appendInsertText(
field,
type?.ofType?.ofType as GraphQLOutputType,
options,
);
}
}
}
return null;
};
// Helper functions to get suggestions for each kinds

@@ -285,3 +358,3 @@ function getSuggestionsForFieldNames(

typeInfo: AllTypeInfo,
schema: GraphQLSchema,
options?: AutocompleteSuggestionOptions,
): Array<CompletionItem> {

@@ -301,3 +374,3 @@ if (typeInfo.parentType) {

}
if (parentType === schema.getQueryType()) {
if (parentType === options?.schema?.getQueryType()) {
fields.push(SchemaMetaFieldDef, TypeMetaFieldDef);

@@ -307,14 +380,27 @@ }

token,
fields.map<CompletionItem>((field, index) => ({
// This will sort the fields in the same order they are listed in the schema
sortText: String(index) + field.name,
label: field.name,
detail: String(field.type),
documentation: field.description ?? undefined,
deprecated: Boolean(field.deprecationReason),
isDeprecated: Boolean(field.deprecationReason),
deprecationReason: field.deprecationReason,
kind: CompletionItemKind.Field,
type: field.type,
})),
fields.map<CompletionItem>((field, index) => {
if (field.name === 'securityAdvisories') {
console.log(field);
}
const suggestion: CompletionItem = {
// This will sort the fields in the same order they are listed in the schema
sortText: String(index) + field.name,
label: field.name,
insertTextFormat: InsertTextFormat.Snippet,
detail: String(field.type),
documentation: field.description ?? undefined,
deprecated: Boolean(field.deprecationReason),
isDeprecated: Boolean(field.deprecationReason),
deprecationReason: field.deprecationReason,
kind: CompletionItemKind.Field,
type: field.type,
};
const insertText = getInsertText(field, options);
if (insertText) {
suggestion.insertText = field.name + insertText;
}
return suggestion;
}),
);

@@ -321,0 +407,0 @@ }

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

import { getASTNodeAtPosition } from 'graphql-language-service-utils';
import { AutocompleteSuggestionOptions } from '.';

@@ -227,2 +228,3 @@ const {

filePath: Uri,
options?: AutocompleteSuggestionOptions,
): Promise<Array<CompletionItem>> {

@@ -246,2 +248,3 @@ const projectConfig = this.getConfigForURI(filePath);

fragmentInfo,
options,
);

@@ -248,0 +251,0 @@ }

@@ -19,4 +19,4 @@ /**

export { getOutline } from './getOutline';
export { getHoverInformation } from './getHoverInformation';
export { getHoverInformation, HoverConfig } from './getHoverInformation';
export * from './GraphQLLanguageService';

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