graphql-language-service-interface
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -32,4 +32,4 @@ 'use strict'; | ||
function getAutocompleteSuggestions(schema, queryText, cursor) { | ||
var token = getTokenAtPosition(queryText, cursor); | ||
function getAutocompleteSuggestions(schema, queryText, cursor, contextToken) { | ||
var token = contextToken || getTokenAtPosition(queryText, cursor); | ||
@@ -252,5 +252,4 @@ var state = token.state.kind === 'Invalid' ? token.state.prevState : token.state; | ||
if (state.prevState && state.prevState.kind) { | ||
var stateKind = state.prevState.kind; | ||
var directives = schema.getDirectives().filter(function (directive) { | ||
return canUseDirective(stateKind, directive); | ||
return canUseDirective(state.prevState, directive); | ||
}); | ||
@@ -335,3 +334,7 @@ return (0, _autocompleteUtils.hintList)(token, directives.map(function (directive) { | ||
function canUseDirective(kind, directive) { | ||
function canUseDirective(state, directive) { | ||
if (!state || !state.kind) { | ||
return false; | ||
} | ||
var kind = state.kind; | ||
var locations = directive.locations; | ||
@@ -354,2 +357,30 @@ switch (kind) { | ||
return locations.indexOf('INLINE_FRAGMENT') !== -1; | ||
// Schema Definitions | ||
case 'SchemaDef': | ||
return locations.indexOf('SCHEMA') !== -1; | ||
case 'ScalarDef': | ||
return locations.indexOf('SCALAR') !== -1; | ||
case 'ObjectTypeDef': | ||
return locations.indexOf('OBJECT') !== -1; | ||
case 'FieldDef': | ||
return locations.indexOf('FIELD_DEFINITION') !== -1; | ||
case 'InterfaceDef': | ||
return locations.indexOf('INTERFACE') !== -1; | ||
case 'UnionDef': | ||
return locations.indexOf('UNION') !== -1; | ||
case 'EnumDef': | ||
return locations.indexOf('ENUM') !== -1; | ||
case 'EnumValue': | ||
return locations.indexOf('ENUM_VALUE') !== -1; | ||
case 'InputDef': | ||
return locations.indexOf('INPUT_OBJECT') !== -1; | ||
case 'InputValueDef': | ||
var prevStateKind = state.prevState && state.prevState.kind; | ||
switch (prevStateKind) { | ||
case 'ArgumentsDef': | ||
return locations.indexOf('ARGUMENT_DEFINITION') !== -1; | ||
case 'InputDef': | ||
return locations.indexOf('INPUT_FIELD_DEFINITION') !== -1; | ||
} | ||
} | ||
@@ -356,0 +387,0 @@ return false; |
{ | ||
"name": "graphql-language-service-interface", | ||
"repository": "https://github.com/graphql/graphql-language-service", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Interface to the GraphQL Language Service", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
87247
1136
0