Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const tk = require('terminal-kit');
const {introspectionQuery, buildClientSchema, parse} = require('graphql');
const {cli} = require('cli-ux');
const query = require('./query');
const {validateQuery, getAutocompleteSuggestions} = require('graphql-language-service-interface');
const {Position} = require('graphql-language-service-utils');
// FIXME: needs js idiomatic refactor eslint-disable-line no-warning-comments
var term = tk.terminal;
let qs = '';
let p = new Position(1, 0);
let ib;
let qReady = false;
let schema;
let menuOn = false;
let exit = false;
let gResolve, gReject;
const terminate = error => {
term.nextLine(1);
term.grabInput(false);
term.fullscreen(false);
if (error) {
gReject(error);
return;
}
gResolve(qs);
text.indexOf('graphql`') === -1 &&
text.indexOf('graphql.experimental`') === -1 &&
text.indexOf('gql`') === -1
) {
return [];
}
const templates = findGraphQLTags(text);
return templates.map(({ template, range }) => ({ query: template, range }));
} else {
const query = text;
if (!query && query !== '') {
return [];
}
const lines = query.split('\n');
const range = new Range(
new Position(0, 0),
new Position(lines.length - 1, lines[lines.length - 1].length - 1)
);
return [{ query, range }];
}
}
text.indexOf('graphql.experimental`') === -1 &&
text.indexOf('gql`') === -1
) {
return [];
}
const templates = findGraphQLTags(text);
return templates.map(({ template, range }) => ({ query: template, range }));
} else {
const query = text;
if (!query && query !== '') {
return [];
}
const lines = query.split('\n');
const range = new Range(
new Position(0, 0),
new Position(lines.length - 1, lines[lines.length - 1].length - 1)
);
return [{ query, range }];
}
}
async function provideDiagnosticsMessage(
query: string,
uri: Uri,
): Promise> {
let results = await languageService.getDiagnostics(query, uri);
if (results && results.length > 0) {
const queryLines = query.split('\n');
const totalLines = queryLines.length;
const lastLineLength = queryLines[totalLines - 1].length;
const lastCharacterPosition = new Position(totalLines, lastLineLength);
results = results.filter(diagnostic =>
diagnostic.range.end.lessThanOrEqualTo(lastCharacterPosition),
);
}
return results;
}
fragments.properties.forEach(property => {
const tagName = getGraphQLTagName(property.value.tag);
const template = getGraphQLText(property.value.quasi);
if (tagName) {
const loc = property.value.loc;
const range = new Range(
new Position(loc.start.line - 1, loc.start.column),
new Position(loc.end.line - 1, loc.end.column)
);
result.push({
tag: tagName,
template,
range,
});
}
});
} else {
return processedResults.map(diagnostic => ({
...diagnostic,
range: new Range(
new Position(
diagnostic.range.start.line + offset.line,
diagnostic.range.start.character
),
new Position(
diagnostic.range.end.line + offset.line,
diagnostic.range.end.character
)
),
}));
}
export async function provideHoverInfo({
position,
model,
schema
}: ProviderItemInput): Promise {
const graphQLPosition = new GraphQLPosition(
position.lineNumber - 1,
position.column,
);
graphQLPosition.setCharacter(position.column);
graphQLPosition.line = position.lineNumber - 1;
const hoverInfo = getHoverInformation(
schema,
model.getValue(),
graphQLPosition,
);
if (!hoverInfo) {
return {
contents: [],
};
}
return {
return processedResults.map(diagnostic => ({
...diagnostic,
range: new Range(
new Position(
diagnostic.range.start.line + offset.line,
diagnostic.range.start.character
),
new Position(
diagnostic.range.end.line + offset.line,
diagnostic.range.end.character
)
),
}));
}