UNPKG

get-graphql-from-jsonschema

Version:

get-graphql-from-jsonschema gets a GraphQL schema from a JSON schema.

28 lines (27 loc) 956 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseUnion = void 0; const parseSchema_1 = require("./parseSchema"); const parseUnion = function ({ path, schema, direction }) { let subSchemas; if ('oneOf' in schema) { subSchemas = schema.oneOf; } else { subSchemas = schema.anyOf; } const graphqlTypeDefinitions = [], graphqlTypeNames = []; subSchemas.forEach((subSchema, index) => { const result = (0, parseSchema_1.parseSchema)({ schema: subSchema, direction, path: [...path, `I${index}`] }); graphqlTypeNames.push(result.typeName); graphqlTypeDefinitions.push(...result.typeDefinitions); }); const graphqlTypeName = graphqlTypeNames. filter((name) => name.trim() !== ''). join(' | '); return { typeName: graphqlTypeName, typeDefinitions: graphqlTypeDefinitions }; }; exports.parseUnion = parseUnion;