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.5-canary-3dcdd158.0 to 2.9.5-canary-412904c6.0

4

CHANGELOG.md
# graphql-language-service-interface
## 2.9.5-canary-3dcdd158.0
## 2.9.5-canary-412904c6.0
### Patch Changes
- [`38e67621`](https://github.com/graphql/graphiql/commit/38e6762107aeea0e590e841d2c7be2c8eb5025eb) [#2065](https://github.com/graphql/graphiql/pull/2065) Thanks [@acao](https://github.com/acao)! - Add an opt-in feature to generate markdown in hover elements, starting with highlighting type information. Enabled for the language server and also the language service and thus `monaco-graphql` as well.
- [`a3368e00`](https://github.com/graphql/graphiql/commit/a3368e00f408c4108595c10bad1cb00e1cc71f7f) [#2070](https://github.com/graphql/graphiql/pull/2070) Thanks [@acao](https://github.com/acao)! - Fix a bug with variable completion with or without `# graphql-language-service-interface across the ecosytem. Introduce more triggerCharacters for fun!

@@ -9,0 +9,0 @@ ## 2.9.4

@@ -5,3 +5,3 @@ import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql';

export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>;
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, forcePrefix?: boolean): CompletionItem[];
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, token: ContextToken): CompletionItem[];
export declare function getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>;

@@ -8,0 +8,0 @@ export declare function getTokenAtPosition(queryText: string, cursor: IPosition): ContextToken;

@@ -55,6 +55,11 @@ "use strict";

if (argDefs) {
return autocompleteUtils_1.hintList(token, argDefs.map(argDef => {
return autocompleteUtils_1.hintList(token, argDefs.map((argDef) => {
var _a;
return ({
label: argDef.name,
insertText: argDef.name + ': ',
command: {
command: 'editor.action.triggerSuggest',
title: 'Suggestions',
},
detail: String(argDef.type),

@@ -95,3 +100,3 @@ documentation: (_a = argDef.description) !== null && _a !== void 0 ? _a : undefined,

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

@@ -157,3 +162,3 @@ }

const namedInputType = graphql_2.getNamedType(typeInfo.inputType);
const queryVariables = getVariableCompletions(queryText, schema, true).filter(v => v.detail === namedInputType.name);
const queryVariables = getVariableCompletions(queryText, schema, token).filter(v => v.detail === namedInputType.name);
if (namedInputType instanceof graphql_2.GraphQLEnumType) {

@@ -333,11 +338,11 @@ const values = namedInputType.getValues();

};
function getVariableCompletions(queryText, schema, forcePrefix = false) {
let variableName;
function getVariableCompletions(queryText, schema, token) {
let variableName = null;
let variableType;
const definitions = Object.create({});
runOnlineParser(queryText, (_, state) => {
if (state.kind === graphql_language_service_parser_1.RuleKinds.VARIABLE && state.name) {
if ((state === null || state === void 0 ? void 0 : state.kind) === graphql_language_service_parser_1.RuleKinds.VARIABLE && state.name) {
variableName = state.name;
}
if (state.kind === graphql_language_service_parser_1.RuleKinds.NAMED_TYPE && variableName) {
if ((state === null || state === void 0 ? void 0 : state.kind) === graphql_language_service_parser_1.RuleKinds.NAMED_TYPE && variableName) {
const parentDefinition = getParentDefinition(state, graphql_language_service_parser_1.RuleKinds.TYPE);

@@ -350,11 +355,9 @@ if (parentDefinition === null || parentDefinition === void 0 ? void 0 : parentDefinition.type) {

if (!definitions[variableName]) {
const label = token.string === '$' ? variableName : '$' + variableName;
definitions[variableName] = {
detail: variableType.toString(),
label: `$${variableName}`,
label,
type: variableType,
kind: vscode_languageserver_types_1.CompletionItemKind.Variable,
};
if (forcePrefix) {
definitions[variableName].insertText = `$${variableName}`;
}
variableName = null;

@@ -361,0 +364,0 @@ variableType = null;

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

import { Hover } from 'vscode-languageserver-types';
export declare type HoverConfig = {
useMarkdown?: boolean;
};
export declare function getHoverInformation(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextToken, config?: HoverConfig): Hover['contents'];
export declare function getHoverInformation(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextToken): Hover['contents'];
//# sourceMappingURL=getHoverInformation.d.ts.map

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

const getAutocompleteSuggestions_1 = require("./getAutocompleteSuggestions");
function getHoverInformation(schema, queryText, cursor, contextToken, config) {
function getHoverInformation(schema, queryText, cursor, contextToken) {
const token = contextToken || getAutocompleteSuggestions_1.getTokenAtPosition(queryText, cursor);

@@ -16,9 +16,7 @@ if (!schema || !token || !token.state) {

const typeInfo = getAutocompleteSuggestions_1.getTypeInfo(schema, token.state);
const options = Object.assign(Object.assign({}, config), { schema });
const options = { schema };
if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||
(kind === 'AliasedField' && step === 2 && typeInfo.fieldDef)) {
const into = [];
renderMdCodeStart(into, options);
renderField(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.fieldDef);

@@ -29,5 +27,3 @@ return into.join('').trim();

const into = [];
renderMdCodeStart(into, options);
renderDirective(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.directiveDef);

@@ -38,5 +34,3 @@ return into.join('').trim();

const into = [];
renderMdCodeStart(into, options);
renderArg(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.argDef);

@@ -49,5 +43,3 @@ return into.join('').trim();

const into = [];
renderMdCodeStart(into, options);
renderEnumValue(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.enumValue);

@@ -60,5 +52,3 @@ return into.join('').trim();

const into = [];
renderMdCodeStart(into, options);
renderType(into, typeInfo, options, typeInfo.type);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.type);

@@ -70,12 +60,2 @@ return into.join('').trim();

exports.getHoverInformation = getHoverInformation;
function renderMdCodeStart(into, options) {
if (options.useMarkdown) {
text(into, '```graphql\n');
}
}
function renderMdCodeEnd(into, options) {
if (options.useMarkdown) {
text(into, '\n```');
}
}
function renderField(into, typeInfo, options) {

@@ -82,0 +62,0 @@ renderQualifiedField(into, typeInfo, options);

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

import { Hover, SymbolInformation } from 'vscode-languageserver-types';
import { HoverConfig } from './getHoverInformation';
import { DefinitionQueryResult } from './getDefinition';

@@ -15,3 +14,3 @@ export declare class GraphQLLanguageService {

getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri): Promise<Array<CompletionItem>>;
getHoverInformation(query: string, position: IPosition, filePath: Uri, options?: HoverConfig): Promise<Hover['contents']>;
getHoverInformation(query: string, position: IPosition, filePath: Uri): Promise<Hover['contents']>;
getDefinition(query: string, position: IPosition, filePath: Uri): Promise<DefinitionQueryResult | null>;

@@ -18,0 +17,0 @@ getDocumentSymbols(document: string, filePath: Uri): Promise<SymbolInformation[]>;

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

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

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

if (schema) {
return getHoverInformation_1.getHoverInformation(schema, query, position, undefined, options);
return getHoverInformation_1.getHoverInformation(schema, query, position);
}

@@ -145,0 +145,0 @@ return '';

@@ -5,3 +5,3 @@ import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql';

export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>;
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, forcePrefix?: boolean): CompletionItem[];
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, token: ContextToken): CompletionItem[];
export declare function getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>;

@@ -8,0 +8,0 @@ export declare function getTokenAtPosition(queryText: string, cursor: IPosition): ContextToken;

@@ -52,6 +52,11 @@ import { CompletionItemKind } from 'vscode-languageserver-types';

if (argDefs) {
return hintList(token, argDefs.map(argDef => {
return hintList(token, argDefs.map((argDef) => {
var _a;
return ({
label: argDef.name,
insertText: argDef.name + ': ',
command: {
command: 'editor.action.triggerSuggest',
title: 'Suggestions',
},
detail: String(argDef.type),

@@ -92,3 +97,3 @@ documentation: (_a = argDef.description) !== null && _a !== void 0 ? _a : undefined,

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

@@ -153,3 +158,3 @@ }

const namedInputType = getNamedType(typeInfo.inputType);
const queryVariables = getVariableCompletions(queryText, schema, true).filter(v => v.detail === namedInputType.name);
const queryVariables = getVariableCompletions(queryText, schema, token).filter(v => v.detail === namedInputType.name);
if (namedInputType instanceof GraphQLEnumType) {

@@ -329,11 +334,11 @@ const values = namedInputType.getValues();

};
export function getVariableCompletions(queryText, schema, forcePrefix = false) {
let variableName;
export function getVariableCompletions(queryText, schema, token) {
let variableName = null;
let variableType;
const definitions = Object.create({});
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);

@@ -346,11 +351,9 @@ if (parentDefinition === null || parentDefinition === void 0 ? void 0 : parentDefinition.type) {

if (!definitions[variableName]) {
const label = token.string === '$' ? variableName : '$' + variableName;
definitions[variableName] = {
detail: variableType.toString(),
label: `$${variableName}`,
label,
type: variableType,
kind: CompletionItemKind.Variable,
};
if (forcePrefix) {
definitions[variableName].insertText = `$${variableName}`;
}
variableName = null;

@@ -357,0 +360,0 @@ variableType = null;

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

import { Hover } from 'vscode-languageserver-types';
export declare type HoverConfig = {
useMarkdown?: boolean;
};
export declare function getHoverInformation(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextToken, config?: HoverConfig): Hover['contents'];
export declare function getHoverInformation(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextToken): Hover['contents'];
//# sourceMappingURL=getHoverInformation.d.ts.map
import { GraphQLNonNull, GraphQLList, } from 'graphql';
import { getTokenAtPosition, getTypeInfo } from './getAutocompleteSuggestions';
export function getHoverInformation(schema, queryText, cursor, contextToken, config) {
export function getHoverInformation(schema, queryText, cursor, contextToken) {
const token = contextToken || getTokenAtPosition(queryText, cursor);

@@ -12,9 +12,7 @@ if (!schema || !token || !token.state) {

const typeInfo = getTypeInfo(schema, token.state);
const options = Object.assign(Object.assign({}, config), { schema });
const options = { schema };
if ((kind === 'Field' && step === 0 && typeInfo.fieldDef) ||
(kind === 'AliasedField' && step === 2 && typeInfo.fieldDef)) {
const into = [];
renderMdCodeStart(into, options);
renderField(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.fieldDef);

@@ -25,5 +23,3 @@ return into.join('').trim();

const into = [];
renderMdCodeStart(into, options);
renderDirective(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.directiveDef);

@@ -34,5 +30,3 @@ return into.join('').trim();

const into = [];
renderMdCodeStart(into, options);
renderArg(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.argDef);

@@ -45,5 +39,3 @@ return into.join('').trim();

const into = [];
renderMdCodeStart(into, options);
renderEnumValue(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.enumValue);

@@ -56,5 +48,3 @@ return into.join('').trim();

const into = [];
renderMdCodeStart(into, options);
renderType(into, typeInfo, options, typeInfo.type);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.type);

@@ -65,12 +55,2 @@ return into.join('').trim();

}
function renderMdCodeStart(into, options) {
if (options.useMarkdown) {
text(into, '```graphql\n');
}
}
function renderMdCodeEnd(into, options) {
if (options.useMarkdown) {
text(into, '\n```');
}
}
function renderField(into, typeInfo, options) {

@@ -77,0 +57,0 @@ renderQualifiedField(into, typeInfo, options);

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

import { Hover, SymbolInformation } from 'vscode-languageserver-types';
import { HoverConfig } from './getHoverInformation';
import { DefinitionQueryResult } from './getDefinition';

@@ -15,3 +14,3 @@ export declare class GraphQLLanguageService {

getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri): Promise<Array<CompletionItem>>;
getHoverInformation(query: string, position: IPosition, filePath: Uri, options?: HoverConfig): Promise<Hover['contents']>;
getHoverInformation(query: string, position: IPosition, filePath: Uri): Promise<Hover['contents']>;
getDefinition(query: string, position: IPosition, filePath: Uri): Promise<DefinitionQueryResult | null>;

@@ -18,0 +17,0 @@ getDocumentSymbols(document: string, filePath: Uri): Promise<SymbolInformation[]>;

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

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

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

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

@@ -142,0 +142,0 @@ return '';

{
"name": "graphql-language-service-interface",
"version": "2.9.5-canary-3dcdd158.0",
"version": "2.9.5-canary-412904c6.0",
"description": "Interface to the GraphQL Language Service",

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

@@ -282,3 +282,3 @@ /**

it('provides correct suggestions when autocompleting for declared variable while typing', () => {
it('provides correct suggestions for declared variables upon typing $', () => {
const result = testSuggestions(

@@ -291,3 +291,3 @@ 'query($id: String, $ep: Episode!){ hero(episode: $ }',

it('provides correct suggestions when autocompleting for declared variable', () => {
it('provides correct suggestions for variables based on argument context', () => {
const result = testSuggestions(

@@ -302,2 +302,3 @@ 'query($id: String!, $episode: Episode!){ hero(episode: ',

{ label: 'NEWHOPE', detail: 'Episode' },
// no $id here, it's not compatible :P
]);

@@ -304,0 +305,0 @@ });

@@ -159,4 +159,9 @@ /**

token,
argDefs.map(argDef => ({
argDefs.map((argDef: GraphQLArgument): CompletionItem => ({
label: argDef.name,
insertText: argDef.name + ': ',
command: {
command: 'editor.action.triggerSuggest',
title: 'Suggestions',
},
detail: String(argDef.type),

@@ -207,3 +212,7 @@ documentation: argDef.description ?? undefined,

const namedInputType = getNamedType(typeInfo.inputType as GraphQLType);
const variableDefinitions = getVariableCompletions(queryText, schema);
const variableDefinitions = getVariableCompletions(
queryText,
schema,
token,
);
return hintList(

@@ -316,3 +325,3 @@ token,

schema,
true,
token,
).filter(v => v.detail === namedInputType.name);

@@ -585,12 +594,13 @@

schema: GraphQLSchema,
forcePrefix: boolean = false,
token: ContextToken,
): CompletionItem[] {
let variableName: null | string;
let variableName: null | string = null;
let variableType: GraphQLInputObjectType | undefined | null;
const definitions: Record<string, any> = Object.create({});
runOnlineParser(queryText, (_, state: State) => {
if (state.kind === RuleKinds.VARIABLE && state.name) {
// TODO: gather this as part of `AllTypeInfo`, as I don't think it's optimal to re-run the parser like this
if (state?.kind === RuleKinds.VARIABLE && state.name) {
variableName = state.name;
}
if (state.kind === RuleKinds.NAMED_TYPE && variableName) {
if (state?.kind === RuleKinds.NAMED_TYPE && variableName) {
const parentDefinition = getParentDefinition(state, RuleKinds.TYPE);

@@ -606,11 +616,11 @@ if (parentDefinition?.type) {

if (!definitions[variableName]) {
// append `$` if the `token.string` is not already `$`
const label = token.string === '$' ? variableName : '$' + variableName;
definitions[variableName] = {
detail: variableType.toString(),
label: `$${variableName}`,
label,
type: variableType,
kind: CompletionItemKind.Variable,
} as CompletionItem;
if (forcePrefix) {
definitions[variableName].insertText = `$${variableName}`;
}
variableName = null;

@@ -617,0 +627,0 @@ variableType = null;

@@ -29,4 +29,2 @@ /**

export type HoverConfig = { useMarkdown?: boolean };
export function getHoverInformation(

@@ -37,3 +35,2 @@ schema: GraphQLSchema,

contextToken?: ContextToken,
config?: HoverConfig,
): Hover['contents'] {

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

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

@@ -61,5 +58,3 @@ // Given a Schema and a Token, produce the contents of an info tooltip.

const into: string[] = [];
renderMdCodeStart(into, options);
renderField(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.fieldDef);

@@ -69,5 +64,3 @@ return into.join('').trim();

const into: string[] = [];
renderMdCodeStart(into, options);
renderDirective(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.directiveDef);

@@ -77,5 +70,3 @@ return into.join('').trim();

const into: string[] = [];
renderMdCodeStart(into, options);
renderArg(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.argDef);

@@ -89,5 +80,3 @@ return into.join('').trim();

const into: string[] = [];
renderMdCodeStart(into, options);
renderEnumValue(into, typeInfo, options);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.enumValue);

@@ -101,5 +90,3 @@ return into.join('').trim();

const into: string[] = [];
renderMdCodeStart(into, options);
renderType(into, typeInfo, options, typeInfo.type);
renderMdCodeEnd(into, options);
renderDescription(into, options, typeInfo.type);

@@ -111,13 +98,2 @@ return into.join('').trim();

function renderMdCodeStart(into: string[], options: any) {
if (options.useMarkdown) {
text(into, '```graphql\n');
}
}
function renderMdCodeEnd(into: string[], options: any) {
if (options.useMarkdown) {
text(into, '\n```');
}
}
function renderField(into: string[], typeInfo: AllTypeInfo, options: any) {

@@ -204,3 +180,2 @@ renderQualifiedField(into, typeInfo, options);

}
if (t instanceof GraphQLNonNull) {

@@ -207,0 +182,0 @@ renderType(into, typeInfo, options, t.ofType);

@@ -38,3 +38,3 @@ /**

import { getAutocompleteSuggestions } from './getAutocompleteSuggestions';
import { getHoverInformation, HoverConfig } from './getHoverInformation';
import { getHoverInformation } from './getHoverInformation';
import { validateQuery, getRange, DIAGNOSTIC_SEVERITY } from './getDiagnostics';

@@ -254,3 +254,2 @@ import {

filePath: Uri,
options?: HoverConfig,
): Promise<Hover['contents']> {

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

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

@@ -264,0 +263,0 @@ return '';

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