graphql-language-service-interface
Advanced tools
Comparing version 2.6.0 to 2.7.0
@@ -6,2 +6,8 @@ # Change Log | ||
# [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) | ||
### Features | ||
- merge completion logic (for implements &, variables) ([#1747](https://github.com/graphql/graphiql/issues/1747)) ([0ac0a85](https://github.com/graphql/graphiql/commit/0ac0a856cfc715d7885a9965a9a9114ef2ca4b1a)) | ||
# [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) | ||
@@ -8,0 +14,0 @@ |
@@ -5,2 +5,3 @@ import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql'; | ||
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: Position, contextToken?: ContextToken, fragmentDefs?: FragmentDefinitionNode[]): Array<CompletionItem>; | ||
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, forcePrefix?: boolean): CompletionItem[]; | ||
export declare function getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>; | ||
@@ -7,0 +8,0 @@ export declare function getTokenAtPosition(queryText: string, cursor: Position): ContextToken; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTypeInfo = exports.canUseDirective = exports.runOnlineParser = exports.getTokenAtPosition = exports.getFragmentDefinitions = exports.getAutocompleteSuggestions = void 0; | ||
exports.getTypeInfo = exports.canUseDirective = exports.runOnlineParser = exports.getTokenAtPosition = exports.getFragmentDefinitions = exports.getVariableCompletions = exports.getAutocompleteSuggestions = void 0; | ||
const vscode_languageserver_types_1 = require("vscode-languageserver-types"); | ||
@@ -31,3 +31,3 @@ const graphql_1 = require("graphql"); | ||
((_a = state.prevState) === null || _a === void 0 ? void 0 : _a.kind) === graphql_language_service_parser_1.RuleKinds.IMPLEMENTS)) { | ||
return getSuggestionsForImplements(token, state, schema, queryText); | ||
return getSuggestionsForImplements(token, state, schema, queryText, typeInfo); | ||
} | ||
@@ -50,2 +50,3 @@ if (kind === graphql_language_service_parser_1.RuleKinds.SELECTION_SET || | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Variable, | ||
type: argDef.type, | ||
}); | ||
@@ -69,2 +70,3 @@ })); | ||
kind: completionKind, | ||
type: field.type, | ||
}); | ||
@@ -78,21 +80,8 @@ })); | ||
(kind === graphql_language_service_parser_1.RuleKinds.ARGUMENT && step === 2)) { | ||
return getSuggestionsForInputValues(token, typeInfo); | ||
return getSuggestionsForInputValues(token, typeInfo, queryText, schema); | ||
} | ||
if (kind === graphql_language_service_parser_1.RuleKinds.VARIABLE && step === 1) { | ||
const queryVariables = []; | ||
graphql_1.visit(graphql_1.parse(queryText, { | ||
allowLegacySDLEmptyFields: true, | ||
allowLegacySDLImplementsInterfaces: true, | ||
}), { | ||
VariableDefinition(node) { | ||
queryVariables.push(node); | ||
}, | ||
}); | ||
return autocompleteUtils_1.hintList(token, queryVariables.map(variableDef => ({ | ||
label: `$${variableDef.variable.name.value}`, | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Variable, | ||
detail: 'name' in variableDef.type | ||
? variableDef.type.name.value | ||
: 'Variable', | ||
}))); | ||
const namedInputType = graphql_2.getNamedType(typeInfo.inputType); | ||
const variableDefinitions = getVariableCompletions(queryText, schema); | ||
return autocompleteUtils_1.hintList(token, variableDefinitions.filter(v => v.detail === (namedInputType === null || namedInputType === void 0 ? void 0 : namedInputType.name))); | ||
} | ||
@@ -147,2 +136,3 @@ if ((kind === graphql_language_service_parser_1.RuleKinds.TYPE_CONDITION && step === 1) || | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Field, | ||
type: field.type, | ||
}); | ||
@@ -153,7 +143,9 @@ })); | ||
} | ||
function getSuggestionsForInputValues(token, typeInfo) { | ||
function getSuggestionsForInputValues(token, typeInfo, queryText, schema) { | ||
const namedInputType = graphql_2.getNamedType(typeInfo.inputType); | ||
const queryVariables = getVariableCompletions(queryText, schema, true).filter(v => v.detail === namedInputType.name); | ||
if (namedInputType instanceof graphql_2.GraphQLEnumType) { | ||
const values = namedInputType.getValues(); | ||
return autocompleteUtils_1.hintList(token, values.map((value) => { | ||
return autocompleteUtils_1.hintList(token, values | ||
.map((value) => { | ||
var _a; | ||
@@ -168,7 +160,9 @@ return ({ | ||
kind: vscode_languageserver_types_1.CompletionItemKind.EnumMember, | ||
type: namedInputType, | ||
}); | ||
})); | ||
}) | ||
.concat(queryVariables)); | ||
} | ||
else if (namedInputType === graphql_2.GraphQLBoolean) { | ||
return autocompleteUtils_1.hintList(token, [ | ||
return autocompleteUtils_1.hintList(token, queryVariables.concat([ | ||
{ | ||
@@ -179,2 +173,3 @@ label: 'true', | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Variable, | ||
type: graphql_2.GraphQLBoolean, | ||
}, | ||
@@ -186,22 +181,61 @@ { | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Variable, | ||
type: graphql_2.GraphQLBoolean, | ||
}, | ||
]); | ||
])); | ||
} | ||
return []; | ||
return queryVariables; | ||
} | ||
function getSuggestionsForImplements(token, tokenState, schema, documentText) { | ||
function getSuggestionsForImplements(token, tokenState, schema, documentText, typeInfo) { | ||
if (tokenState.needsSeperator) { | ||
return []; | ||
} | ||
const typeMap = schema.getTypeMap(); | ||
const schemaInterfaces = autocompleteUtils_1.objectValues(typeMap).filter(graphql_1.isInterfaceType); | ||
const schemaInterfaceNames = schemaInterfaces.map(({ name }) => name); | ||
const inlineInterfaces = new Set(); | ||
runOnlineParser(documentText, (_, state) => { | ||
if (state.name && state.kind === graphql_language_service_parser_1.RuleKinds.INTERFACE_DEF) { | ||
inlineInterfaces.add(state.name); | ||
var _a, _b, _c, _d, _e; | ||
if (state.name) { | ||
if (state.kind === graphql_language_service_parser_1.RuleKinds.INTERFACE_DEF && | ||
!schemaInterfaceNames.includes(state.name)) { | ||
inlineInterfaces.add(state.name); | ||
} | ||
if (state.kind === graphql_language_service_parser_1.RuleKinds.NAMED_TYPE && | ||
((_a = state.prevState) === null || _a === void 0 ? void 0 : _a.kind) === graphql_language_service_parser_1.RuleKinds.IMPLEMENTS) { | ||
if (typeInfo.interfaceDef) { | ||
const existingType = (_b = typeInfo.interfaceDef) === null || _b === void 0 ? void 0 : _b.getInterfaces().find(({ name }) => name === state.name); | ||
if (existingType) { | ||
return; | ||
} | ||
const type = schema.getType(state.name); | ||
const interfaceConfig = (_c = typeInfo.interfaceDef) === null || _c === void 0 ? void 0 : _c.toConfig(); | ||
typeInfo.interfaceDef = new graphql_1.GraphQLInterfaceType(Object.assign(Object.assign({}, interfaceConfig), { interfaces: [ | ||
...interfaceConfig.interfaces, | ||
type || | ||
new graphql_1.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); | ||
if (existingType) { | ||
return; | ||
} | ||
const type = schema.getType(state.name); | ||
const objectTypeConfig = (_e = typeInfo.objectTypeDef) === null || _e === void 0 ? void 0 : _e.toConfig(); | ||
typeInfo.objectTypeDef = new graphql_1.GraphQLObjectType(Object.assign(Object.assign({}, objectTypeConfig), { interfaces: [ | ||
...objectTypeConfig.interfaces, | ||
type || | ||
new graphql_1.GraphQLInterfaceType({ name: state.name, fields: {} }), | ||
] })); | ||
} | ||
} | ||
} | ||
}); | ||
const typeMap = schema.getTypeMap(); | ||
const schemaInterfaces = autocompleteUtils_1.objectValues(typeMap).filter(graphql_1.isInterfaceType); | ||
const possibleInterfaces = schemaInterfaces.concat([...inlineInterfaces] | ||
.filter(v => { var _a; return v !== ((_a = tokenState.prevState) === null || _a === void 0 ? void 0 : _a.name); }) | ||
.map(name => ({ name }))); | ||
const currentTypeToExtend = typeInfo.interfaceDef || typeInfo.objectTypeDef; | ||
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 === null || currentTypeToExtend === void 0 ? void 0 : currentTypeToExtend.name) && | ||
!siblingInterfaceNames.includes(name)); | ||
return autocompleteUtils_1.hintList(token, possibleInterfaces.map(type => { | ||
@@ -211,2 +245,3 @@ const result = { | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Interface, | ||
type, | ||
}; | ||
@@ -269,4 +304,53 @@ if (type === null || type === void 0 ? void 0 : type.description) { | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Field, | ||
type: typeMap[frag.typeCondition.name.value], | ||
}))); | ||
} | ||
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) { | ||
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) { | ||
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) { | ||
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) { | ||
return state.prevState.prevState.prevState.prevState; | ||
} | ||
}; | ||
function getVariableCompletions(queryText, schema, forcePrefix = false) { | ||
let variableName; | ||
let variableType; | ||
const definitions = Object.create({}); | ||
runOnlineParser(queryText, (_, state) => { | ||
if (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) { | ||
const parentDefinition = getParentDefinition(state, graphql_language_service_parser_1.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 (variableName && variableType) { | ||
if (!definitions[variableName]) { | ||
definitions[variableName] = { | ||
detail: variableType.toString(), | ||
label: `$${variableName}`, | ||
type: variableType, | ||
kind: vscode_languageserver_types_1.CompletionItemKind.Variable, | ||
}; | ||
if (forcePrefix) { | ||
definitions[variableName].insertText = `$${variableName}`; | ||
} | ||
variableName = null; | ||
variableType = null; | ||
} | ||
} | ||
}); | ||
return autocompleteUtils_1.objectValues(definitions); | ||
} | ||
exports.getVariableCompletions = getVariableCompletions; | ||
function getFragmentDefinitions(queryText) { | ||
@@ -434,5 +518,7 @@ const fragmentDefs = []; | ||
let inputType; | ||
let objectTypeDef; | ||
let objectFieldDefs; | ||
let parentType; | ||
let type; | ||
let interfaceDef; | ||
autocompleteUtils_1.forEachState(tokenState, state => { | ||
@@ -457,3 +543,3 @@ switch (state.kind) { | ||
case graphql_language_service_parser_1.RuleKinds.FIELD: | ||
case graphql_language_service_parser_1.RuleKinds.ALIASED_FIELD: | ||
case graphql_language_service_parser_1.RuleKinds.ALIASED_FIELD: { | ||
if (!type || !state.name) { | ||
@@ -469,2 +555,3 @@ fieldDef = null; | ||
break; | ||
} | ||
case graphql_language_service_parser_1.RuleKinds.SELECTION_SET: | ||
@@ -476,3 +563,23 @@ parentType = graphql_2.getNamedType(type); | ||
break; | ||
case graphql_language_service_parser_1.RuleKinds.ARGUMENTS: | ||
case graphql_language_service_parser_1.RuleKinds.INTERFACE_DEF: | ||
if (state.name) { | ||
objectTypeDef = null; | ||
interfaceDef = new graphql_1.GraphQLInterfaceType({ | ||
name: state.name, | ||
interfaces: [], | ||
fields: {}, | ||
}); | ||
} | ||
break; | ||
case graphql_language_service_parser_1.RuleKinds.OBJECT_TYPE_DEF: | ||
if (state.name) { | ||
interfaceDef = null; | ||
objectTypeDef = new graphql_1.GraphQLObjectType({ | ||
name: state.name, | ||
interfaces: [], | ||
fields: {}, | ||
}); | ||
} | ||
break; | ||
case graphql_language_service_parser_1.RuleKinds.ARGUMENTS: { | ||
if (!state.prevState) { | ||
@@ -489,3 +596,3 @@ argDefs = null; | ||
break; | ||
case graphql_language_service_parser_1.RuleKinds.ALIASED_FIELD: | ||
case graphql_language_service_parser_1.RuleKinds.ALIASED_FIELD: { | ||
const name = state.prevState && state.prevState.name; | ||
@@ -505,2 +612,3 @@ if (!name) { | ||
break; | ||
} | ||
default: | ||
@@ -512,2 +620,3 @@ argDefs = null; | ||
break; | ||
} | ||
case graphql_language_service_parser_1.RuleKinds.ARGUMENT: | ||
@@ -564,2 +673,4 @@ if (argDefs) { | ||
type, | ||
interfaceDef, | ||
objectTypeDef, | ||
}; | ||
@@ -566,0 +677,0 @@ } |
@@ -5,2 +5,3 @@ import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql'; | ||
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: Position, contextToken?: ContextToken, fragmentDefs?: FragmentDefinitionNode[]): Array<CompletionItem>; | ||
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, forcePrefix?: boolean): CompletionItem[]; | ||
export declare function getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>; | ||
@@ -7,0 +8,0 @@ export declare function getTokenAtPosition(queryText: string, cursor: Position): ContextToken; |
import { CompletionItemKind } from 'vscode-languageserver-types'; | ||
import { parse, visit, isInterfaceType, } from 'graphql'; | ||
import { isInterfaceType, GraphQLInterfaceType, GraphQLObjectType, } from 'graphql'; | ||
import { GraphQLBoolean, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, assertAbstractType, doTypesOverlap, getNamedType, getNullableType, isAbstractType, isCompositeType, isInputType, } from 'graphql'; | ||
@@ -28,3 +28,3 @@ import { CharacterStream, onlineParser, RuleKinds, } from 'graphql-language-service-parser'; | ||
((_a = state.prevState) === null || _a === void 0 ? void 0 : _a.kind) === RuleKinds.IMPLEMENTS)) { | ||
return getSuggestionsForImplements(token, state, schema, queryText); | ||
return getSuggestionsForImplements(token, state, schema, queryText, typeInfo); | ||
} | ||
@@ -47,2 +47,3 @@ if (kind === RuleKinds.SELECTION_SET || | ||
kind: CompletionItemKind.Variable, | ||
type: argDef.type, | ||
}); | ||
@@ -66,2 +67,3 @@ })); | ||
kind: completionKind, | ||
type: field.type, | ||
}); | ||
@@ -75,21 +77,8 @@ })); | ||
(kind === RuleKinds.ARGUMENT && step === 2)) { | ||
return getSuggestionsForInputValues(token, typeInfo); | ||
return getSuggestionsForInputValues(token, typeInfo, queryText, schema); | ||
} | ||
if (kind === RuleKinds.VARIABLE && step === 1) { | ||
const queryVariables = []; | ||
visit(parse(queryText, { | ||
allowLegacySDLEmptyFields: true, | ||
allowLegacySDLImplementsInterfaces: true, | ||
}), { | ||
VariableDefinition(node) { | ||
queryVariables.push(node); | ||
}, | ||
}); | ||
return hintList(token, queryVariables.map(variableDef => ({ | ||
label: `$${variableDef.variable.name.value}`, | ||
kind: CompletionItemKind.Variable, | ||
detail: 'name' in variableDef.type | ||
? variableDef.type.name.value | ||
: 'Variable', | ||
}))); | ||
const namedInputType = getNamedType(typeInfo.inputType); | ||
const variableDefinitions = getVariableCompletions(queryText, schema); | ||
return hintList(token, variableDefinitions.filter(v => v.detail === (namedInputType === null || namedInputType === void 0 ? void 0 : namedInputType.name))); | ||
} | ||
@@ -143,2 +132,3 @@ if ((kind === RuleKinds.TYPE_CONDITION && step === 1) || | ||
kind: CompletionItemKind.Field, | ||
type: field.type, | ||
}); | ||
@@ -149,7 +139,9 @@ })); | ||
} | ||
function getSuggestionsForInputValues(token, typeInfo) { | ||
function getSuggestionsForInputValues(token, typeInfo, queryText, schema) { | ||
const namedInputType = getNamedType(typeInfo.inputType); | ||
const queryVariables = getVariableCompletions(queryText, schema, true).filter(v => v.detail === namedInputType.name); | ||
if (namedInputType instanceof GraphQLEnumType) { | ||
const values = namedInputType.getValues(); | ||
return hintList(token, values.map((value) => { | ||
return hintList(token, values | ||
.map((value) => { | ||
var _a; | ||
@@ -164,7 +156,9 @@ return ({ | ||
kind: CompletionItemKind.EnumMember, | ||
type: namedInputType, | ||
}); | ||
})); | ||
}) | ||
.concat(queryVariables)); | ||
} | ||
else if (namedInputType === GraphQLBoolean) { | ||
return hintList(token, [ | ||
return hintList(token, queryVariables.concat([ | ||
{ | ||
@@ -175,2 +169,3 @@ label: 'true', | ||
kind: CompletionItemKind.Variable, | ||
type: GraphQLBoolean, | ||
}, | ||
@@ -182,22 +177,61 @@ { | ||
kind: CompletionItemKind.Variable, | ||
type: GraphQLBoolean, | ||
}, | ||
]); | ||
])); | ||
} | ||
return []; | ||
return queryVariables; | ||
} | ||
function getSuggestionsForImplements(token, tokenState, schema, documentText) { | ||
function getSuggestionsForImplements(token, tokenState, schema, documentText, typeInfo) { | ||
if (tokenState.needsSeperator) { | ||
return []; | ||
} | ||
const typeMap = schema.getTypeMap(); | ||
const schemaInterfaces = objectValues(typeMap).filter(isInterfaceType); | ||
const schemaInterfaceNames = schemaInterfaces.map(({ name }) => name); | ||
const inlineInterfaces = new Set(); | ||
runOnlineParser(documentText, (_, state) => { | ||
if (state.name && state.kind === RuleKinds.INTERFACE_DEF) { | ||
inlineInterfaces.add(state.name); | ||
var _a, _b, _c, _d, _e; | ||
if (state.name) { | ||
if (state.kind === RuleKinds.INTERFACE_DEF && | ||
!schemaInterfaceNames.includes(state.name)) { | ||
inlineInterfaces.add(state.name); | ||
} | ||
if (state.kind === RuleKinds.NAMED_TYPE && | ||
((_a = state.prevState) === null || _a === void 0 ? void 0 : _a.kind) === RuleKinds.IMPLEMENTS) { | ||
if (typeInfo.interfaceDef) { | ||
const existingType = (_b = typeInfo.interfaceDef) === null || _b === void 0 ? void 0 : _b.getInterfaces().find(({ name }) => name === state.name); | ||
if (existingType) { | ||
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: [ | ||
...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); | ||
if (existingType) { | ||
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: [ | ||
...objectTypeConfig.interfaces, | ||
type || | ||
new GraphQLInterfaceType({ name: state.name, fields: {} }), | ||
] })); | ||
} | ||
} | ||
} | ||
}); | ||
const typeMap = schema.getTypeMap(); | ||
const schemaInterfaces = objectValues(typeMap).filter(isInterfaceType); | ||
const possibleInterfaces = schemaInterfaces.concat([...inlineInterfaces] | ||
.filter(v => { var _a; return v !== ((_a = tokenState.prevState) === null || _a === void 0 ? void 0 : _a.name); }) | ||
.map(name => ({ name }))); | ||
const currentTypeToExtend = typeInfo.interfaceDef || typeInfo.objectTypeDef; | ||
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 === null || currentTypeToExtend === void 0 ? void 0 : currentTypeToExtend.name) && | ||
!siblingInterfaceNames.includes(name)); | ||
return hintList(token, possibleInterfaces.map(type => { | ||
@@ -207,2 +241,3 @@ const result = { | ||
kind: CompletionItemKind.Interface, | ||
type, | ||
}; | ||
@@ -265,4 +300,52 @@ if (type === null || type === void 0 ? void 0 : type.description) { | ||
kind: CompletionItemKind.Field, | ||
type: typeMap[frag.typeCondition.name.value], | ||
}))); | ||
} | ||
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) { | ||
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) { | ||
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) { | ||
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) { | ||
return state.prevState.prevState.prevState.prevState; | ||
} | ||
}; | ||
export function getVariableCompletions(queryText, schema, forcePrefix = false) { | ||
let variableName; | ||
let variableType; | ||
const definitions = Object.create({}); | ||
runOnlineParser(queryText, (_, state) => { | ||
if (state.kind === RuleKinds.VARIABLE && state.name) { | ||
variableName = state.name; | ||
} | ||
if (state.kind === RuleKinds.NAMED_TYPE && variableName) { | ||
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 (variableName && variableType) { | ||
if (!definitions[variableName]) { | ||
definitions[variableName] = { | ||
detail: variableType.toString(), | ||
label: `$${variableName}`, | ||
type: variableType, | ||
kind: CompletionItemKind.Variable, | ||
}; | ||
if (forcePrefix) { | ||
definitions[variableName].insertText = `$${variableName}`; | ||
} | ||
variableName = null; | ||
variableType = null; | ||
} | ||
} | ||
}); | ||
return objectValues(definitions); | ||
} | ||
export function getFragmentDefinitions(queryText) { | ||
@@ -426,5 +509,7 @@ const fragmentDefs = []; | ||
let inputType; | ||
let objectTypeDef; | ||
let objectFieldDefs; | ||
let parentType; | ||
let type; | ||
let interfaceDef; | ||
forEachState(tokenState, state => { | ||
@@ -449,3 +534,3 @@ switch (state.kind) { | ||
case RuleKinds.FIELD: | ||
case RuleKinds.ALIASED_FIELD: | ||
case RuleKinds.ALIASED_FIELD: { | ||
if (!type || !state.name) { | ||
@@ -461,2 +546,3 @@ fieldDef = null; | ||
break; | ||
} | ||
case RuleKinds.SELECTION_SET: | ||
@@ -468,3 +554,23 @@ parentType = getNamedType(type); | ||
break; | ||
case RuleKinds.ARGUMENTS: | ||
case RuleKinds.INTERFACE_DEF: | ||
if (state.name) { | ||
objectTypeDef = null; | ||
interfaceDef = new GraphQLInterfaceType({ | ||
name: state.name, | ||
interfaces: [], | ||
fields: {}, | ||
}); | ||
} | ||
break; | ||
case RuleKinds.OBJECT_TYPE_DEF: | ||
if (state.name) { | ||
interfaceDef = null; | ||
objectTypeDef = new GraphQLObjectType({ | ||
name: state.name, | ||
interfaces: [], | ||
fields: {}, | ||
}); | ||
} | ||
break; | ||
case RuleKinds.ARGUMENTS: { | ||
if (!state.prevState) { | ||
@@ -481,3 +587,3 @@ argDefs = null; | ||
break; | ||
case RuleKinds.ALIASED_FIELD: | ||
case RuleKinds.ALIASED_FIELD: { | ||
const name = state.prevState && state.prevState.name; | ||
@@ -497,2 +603,3 @@ if (!name) { | ||
break; | ||
} | ||
default: | ||
@@ -504,2 +611,3 @@ argDefs = null; | ||
break; | ||
} | ||
case RuleKinds.ARGUMENT: | ||
@@ -556,2 +664,4 @@ if (argDefs) { | ||
type, | ||
interfaceDef, | ||
objectTypeDef, | ||
}; | ||
@@ -558,0 +668,0 @@ } |
{ | ||
"name": "graphql-language-service-interface", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "Interface to the GraphQL Language Service", | ||
@@ -30,5 +30,5 @@ "contributors": [ | ||
"dependencies": { | ||
"graphql-language-service-parser": "^1.7.0", | ||
"graphql-language-service-types": "^1.6.3", | ||
"graphql-language-service-utils": "^2.4.3", | ||
"graphql-language-service-parser": "^1.8.0", | ||
"graphql-language-service-types": "^1.7.0", | ||
"graphql-language-service-utils": "^2.4.4", | ||
"vscode-languageserver-types": "^3.15.1" | ||
@@ -39,3 +39,3 @@ }, | ||
}, | ||
"gitHead": "ed6c94cb8240fd89324104f0a9a40ce80a2dd71c" | ||
"gitHead": "4038cf235b71eaf9a576c86800707f204ded8865" | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
275200
3182