UNPKG

graphql-language-service-server

Version:
43 lines 1.4 kB
import { glob } from 'glob'; import { DEFAULT_SUPPORTED_EXTENSIONS, DEFAULT_SUPPORTED_GRAPHQL_EXTENSIONS, } from './constants'; export function unwrapProjectSchema(project) { const projectSchema = project.schema; const schemas = []; if (typeof projectSchema === 'string') { schemas.push(projectSchema); } else if (Array.isArray(projectSchema)) { for (const schemaEntry of projectSchema) { if (typeof schemaEntry === 'string') { schemas.push(schemaEntry); } else if (schemaEntry) { schemas.push(...Object.keys(schemaEntry)); } } } else { schemas.push(...Object.keys(projectSchema)); } return schemas.reduce((agg, schema) => { const results = globIfFilePattern(schema); return [...agg, ...results]; }, []); } function globIfFilePattern(pattern) { if (pattern.includes('*')) { try { return glob.sync(pattern); } catch (_a) { } } return [pattern]; } const allExtensions = [ ...DEFAULT_SUPPORTED_EXTENSIONS, ...DEFAULT_SUPPORTED_GRAPHQL_EXTENSIONS, ]; export function isProjectSDLOnly(unwrappedSchema) { return unwrappedSchema.every(schemaEntry => allExtensions.some(ext => !schemaEntry.startsWith('http') && schemaEntry.endsWith(ext))); } //# sourceMappingURL=common.js.map