graphql-2-json-schema
Version:
`graphql-2-json-schema` package
35 lines (34 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromIntrospectionQuery = void 0;
const lodash_1 = require("lodash");
const reducer_1 = require("./reducer");
const typeGuards_1 = require("./typeGuards");
const fromIntrospectionQuery = (introspection, opts) => {
const options = Object.assign({ ignoreInternals: true, nullableArrayItems: false }, (opts || {}));
const { queryType, mutationType } = introspection.__schema;
if (mutationType) {
const rootMutationType = introspection.__schema.types.find((t) => t.name == mutationType.name);
if (rootMutationType) {
;
introspection.__schema.types.Mutation = rootMutationType;
introspection.__schema.types.Mutation.name = 'Mutation';
}
}
if (queryType) {
const rootQueryType = introspection.__schema.types.find((t) => t.name == queryType.name);
if (rootQueryType) {
;
introspection.__schema.types.Query = rootQueryType;
introspection.__schema.types.Query.name = 'Query';
}
}
const [properties, definitions] = lodash_1.partition(introspection.__schema.types, (type) => typeGuards_1.isIntrospectionObjectType(type) &&
lodash_1.includes(['Query', 'Mutation'], type.name));
return {
$schema: 'http://json-schema.org/draft-06/schema#',
properties: lodash_1.reduce(properties, reducer_1.introspectionTypeReducer('properties', options), {}),
definitions: lodash_1.reduce(typeGuards_1.filterDefinitionsTypes(definitions, options), reducer_1.introspectionTypeReducer('definitions', options), {}),
};
};
exports.fromIntrospectionQuery = fromIntrospectionQuery;