UNPKG

graphql-language-service-server

Version:
23 lines 1.09 kB
import { extname } from 'node:path'; import { Range, Position } from 'graphql-language-service'; import { findGraphQLTags } from './findGraphQLTags'; import { DEFAULT_SUPPORTED_EXTENSIONS, DEFAULT_SUPPORTED_GRAPHQL_EXTENSIONS, } from './constants'; import { NoopLogger } from './Logger'; export async function parseDocument(text, uri, fileExtensions = DEFAULT_SUPPORTED_EXTENSIONS, graphQLFileExtensions = DEFAULT_SUPPORTED_GRAPHQL_EXTENSIONS, logger = new NoopLogger()) { const ext = extname(uri); if (!text || text === '') { return []; } if (fileExtensions.includes(ext)) { const templates = await findGraphQLTags(text, ext, uri, logger); return templates.map(({ template, range }) => ({ query: template, range })); } if (graphQLFileExtensions.includes(ext)) { const query = text; const lines = query.split('\n'); const range = new Range(new Position(0, 0), new Position(lines.length - 1, lines.at(-1).length - 1)); return [{ query, range }]; } return []; } //# sourceMappingURL=parseDocument.js.map