graphql-paper
Version:
A flexible in-memory store based on a GraphQL Schema
20 lines (18 loc) • 1.08 kB
JavaScript
;
var graphql = require('graphql');
function storeTypenamesFromSchema(schema) {
const storeTypenames = [];
const typeMap = schema.getTypeMap();
for (const typeName in typeMap) {
var _schema$getQueryType, _schema$getMutationTy, _schema$getSubscripti;
const type = typeMap[typeName];
const isInternalType = type.name.startsWith('__');
const rootTypeNames = [(_schema$getQueryType = schema.getQueryType()) === null || _schema$getQueryType === void 0 ? void 0 : _schema$getQueryType.name, (_schema$getMutationTy = schema.getMutationType()) === null || _schema$getMutationTy === void 0 ? void 0 : _schema$getMutationTy.name, (_schema$getSubscripti = schema.getSubscriptionType()) === null || _schema$getSubscripti === void 0 ? void 0 : _schema$getSubscripti.name];
if (graphql.isObjectType(type) && !isInternalType && !rootTypeNames.includes(type.name)) {
storeTypenames.push(type.name);
}
}
return storeTypenames;
}
exports.storeTypenamesFromSchema = storeTypenamesFromSchema;
//# sourceMappingURL=store-typenames-from-schema.js.map