UNPKG

graphql-language-service-server

Version:
30 lines 1.24 kB
import { extname } from 'path'; import { Range, Position } from 'graphql-language-service-utils'; import { findGraphQLTags, DEFAULT_TAGS } from './findGraphQLTags'; export const DEFAULT_SUPPORTED_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx']; export const DEFAULT_SUPPORTED_GRAPHQL_EXTENSIONS = [ '.graphql', '.graphqls', '.gql', ]; export function parseDocument(text, uri, fileExtensions = DEFAULT_SUPPORTED_EXTENSIONS, graphQLFileExtensions = DEFAULT_SUPPORTED_GRAPHQL_EXTENSIONS) { const ext = extname(uri); if (fileExtensions.some(e => e === ext)) { if (DEFAULT_TAGS.some(t => t === text)) { return []; } const templates = findGraphQLTags(text, ext); return templates.map(({ template, range }) => ({ query: template, range })); } if (graphQLFileExtensions.some(e => e === ext)) { 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 }]; } return [{ query: text, range: null }]; } //# sourceMappingURL=parseDocument.js.map