graphql-language-service-server
Version:
Server process backing the GraphQL Language Service
48 lines • 1.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.isProjectSDLOnly = exports.unwrapProjectSchema = void 0;
const glob_1 = require("glob");
const constants_1 = require("./constants");
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];
}, []);
}
exports.unwrapProjectSchema = unwrapProjectSchema;
function globIfFilePattern(pattern) {
if (pattern.includes('*')) {
try {
return glob_1.glob.sync(pattern);
}
catch (_a) { }
}
return [pattern];
}
const allExtensions = [
...constants_1.DEFAULT_SUPPORTED_EXTENSIONS,
...constants_1.DEFAULT_SUPPORTED_GRAPHQL_EXTENSIONS,
];
function isProjectSDLOnly(unwrappedSchema) {
return unwrappedSchema.every(schemaEntry => allExtensions.some(ext => !schemaEntry.startsWith('http') && schemaEntry.endsWith(ext)));
}
exports.isProjectSDLOnly = isProjectSDLOnly;
//# sourceMappingURL=common.js.map
;