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.4 to 2.9.5-canary-325c04b9.0

8

CHANGELOG.md
# graphql-language-service-interface
## 2.9.5-canary-325c04b9.0
### Patch Changes
- [`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. Far less`\$myVariable`bugs, though one still occurs sometimes on deleting a variable name. Introduce more triggerCharacters for`monaco-graphql`and`graphql-language-service-server`, including on newlines and for characters unrelated to this effort, as a precursor to more upcoming improvements.
Improve argument/variable completion experience as a whole. Trigger completion where needed.
## 2.9.4

@@ -4,0 +12,0 @@

2

dist/getAutocompleteSuggestions.d.ts

@@ -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,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;

{
"name": "graphql-language-service-interface",
"version": "2.9.4",
"version": "2.9.5-canary-325c04b9.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;

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc