UNPKG

simpl-to-graphql-schema

Version:
30 lines (27 loc) 913 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var camel = function camel(k) { return k[0].toUpperCase() + k.substr(1); }; // If we have a SimpleSchema key for an Object such as "sublist.subobject.attributes" and the entity name : "List" // we name the new GraphQL type like: ListSublistSubobjectAttributes var subGqlType = exports.subGqlType = function subGqlType(key, name) { return name + key.split('.').reduce(function (a, b) { return a + camel(b); }, ''); }; // get field type var typeDef = exports.typeDef = function typeDef(Schema, key) { if (Schema[key].type.constructor.name === 'SimpleSchemaGroup') { return Schema[key].type.definitions[0].type; } return Schema[key].type; }; var gqlType = exports.gqlType = {}; gqlType[String] = 'String'; gqlType[Number] = 'Float'; gqlType[Boolean] = 'Boolean'; gqlType[Date] = 'Date'; gqlType[RegExp] = 'String';