Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@manifoldco/graphql-gen

Package Overview
Dependencies
Maintainers
15
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@manifoldco/graphql-gen - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

2

dist/cjs.js

@@ -1,1 +0,1 @@

"use strict";var prettier=require("prettier"),__assign=function(){return(__assign=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++)for(var a in e=arguments[t])Object.prototype.hasOwnProperty.call(e,a)&&(r[a]=e[a]);return r}).apply(this,arguments)};function __rest(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(r);a<n.length;a++)e.indexOf(n[a])<0&&(t[n[a]]=r[n[a]])}return t}var TYPES={boolean:"Boolean",integer:"Int",number:"Number",string:"String"};function camelCase(r){return r.replace(/(-|_|\.|\s)+[a-z]/g,function(r){return r.toUpperCase().replace(/[^0-9a-z]/gi,"")})}function snakeCase(r){return r.replace(/(-|\.|\s)/g,"_").replace(/[A-Z]/g,function(r){return"_"+r}).toUpperCase()}function parse(r){var e=[],t=[],n=[],a=r.definitions;function s(r){var e=r.replace("#/definitions/","");return[e,a[e]]}function i(r){var e=r[0],t=r[1];n.push("enum "+e+" {"),t.forEach(function(r){if("number"==typeof r||!1===isNaN(parseInt(r,10))){var t=e.search(/[A-Z](?=[^A-Z]*$)/),a=e.substr(t,e.length);n.push(""+a+r)}else n.push(snakeCase(r))}),n.push("}")}function o(){var r=e.pop();if(r){var a=r[0],o=r[1],p=o.allOf,u=o.properties,f=o.required,c=u||{},l=[];if(Array.isArray(p)&&p.forEach(function(r){if(r.$ref){var e=s(r.$ref)[0];l.push(e)}else r.properties&&(c=__assign({},c,r.properties))}),Object.keys(c).length){var h=l.length?" implements "+l.join(", "):"";for(n.push("type "+camelCase(a)+h+" {"),Object.entries(c).forEach(function(r){var i=r[0],o=r[1],p=!Array.isArray(f)||-1===f.indexOf(i)?"":"!",u=camelCase(i),c=camelCase(a+"_"+i),l=function r(t,n){var a=t.$ref,i=t.items,o=t.type,p=__rest(t,["$ref","items","type"]);if(a){var u=s(a),f=u[0],c=u[1];return"ID"===f?"ID":c.items&&c.items.$ref?r(c,f):""+(TYPES[c.type]||f||"scalar")}if("array"===o&&i){if(i.$ref){var l=s(i.$ref);return f=l[0],c=l[1],"ID"===f?"ID":"["+(TYPES[c.type]||f||"scalar")+"]"}return"["+(TYPES[i.type]||"scalar")+"]"}return p.properties?(e.push([n,__assign({$ref:a,items:i,type:o},p)]),n):TYPES[o]||o||"scalar"}(o,c);if("string"==typeof o.description&&n.push('"'+o.description.replace(/\n$/,"").replace(/\n/g," ")+'"'),Array.isArray(o.enum))return t.push([c,o.enum]),void n.push(u+": "+c+p);n.push(u+": "+l+p)}),n.push("}");t.length>0;){var y=t.pop();y&&i(y)}}}}for(Object.entries(a).forEach(function(r){return e.push(r)}),e.sort(function(r,e){return r[0].localeCompare(e[0])});e.length>0;)o();return prettier.format(n.join("\n"),{parser:"graphql"})}var index=function(r,e){var t=e&&e.swagger||2;if(1!==t&&3!==t)return parse(r);console.error("That version is not supported")};module.exports=index;
"use strict";var prettier=require("prettier"),__assign=function(){return(__assign=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var a in r=arguments[t])Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e}).apply(this,arguments)};function __rest(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)r.indexOf(n[a])<0&&(t[n[a]]=e[n[a]])}return t}var TYPES={boolean:"Boolean",float:"Float",integer:"Int",string:"String"};function camelCase(e){return e.replace(/(-|_|\.|\s)+[a-z]/g,function(e){return e.toUpperCase().replace(/[^0-9a-z]/gi,"")})}function snakeCase(e){return e.replace(/(-|\.|\s)/g,"_").replace(/[A-Z]/g,function(e){return"_"+e}).toUpperCase()}function parse(e){var r=[],t=[],n=[],a=e.definitions;function o(e){var r=e.replace("#/definitions/","");return[r,a[r]]}function s(e){var r=e[0],t=e[1];n.push("enum "+r+" {"),t.forEach(function(e){if("number"==typeof e||!1===isNaN(parseInt(e,10))){var t=r.search(/[A-Z](?=[^A-Z]*$)/),a=r.substr(t,r.length);n.push(""+a+e)}else n.push(snakeCase(e))}),n.push("}")}function i(){var e=r.pop();if(e){var a=e[0],i=e[1],p=i.allOf,f=i.properties,u=i.required,c=f||{},l=[];if(Array.isArray(p)&&p.forEach(function(e){if(e.$ref){var r=o(e.$ref)[0];l.push(r)}else e.properties&&(c=__assign({},c,e.properties))}),Object.keys(c).length){var h=l.length?" implements "+l.join(", "):"";for(n.push("type "+camelCase(a)+h+" {"),Object.entries(c).forEach(function(e){var s=e[0],i=e[1];"resizable_to"===s&&console.log(i);var p=!Array.isArray(u)||-1===u.indexOf(s)?"":"!",f=camelCase(s),c=camelCase(a+"_"+s),l=function e(t,n){var a=t.$ref,s=t.items,i=t.type,p=__rest(t,["$ref","items","type"]);if(a){var f=o(a),u=f[0],c=f[1];return"ID"===u?"ID":c.items&&c.items.$ref?e(c,u):c.type&&TYPES[c.type]?TYPES[c.type]||"Scalar":u||"Scalar"}return"number"===i?p.format&&"float"===p.format?TYPES.float:TYPES.integer:s&&s.$ref?"["+e(s,u=o(s.$ref)[0])+"]":s&&s.type&&TYPES[s.type]?"["+TYPES[s.type]+"]":p.oneOf?e(p.oneOf[0],""):p.properties?(r.push([n,__assign({$ref:a,items:s,type:i},p)]),n):i&&(TYPES[i]||i)||"Scalar"}(i,c);if("string"==typeof i.description&&n.push('"'+i.description.replace(/\n$/,"").replace(/\n/g," ")+'"'),Array.isArray(i.enum))return t.push([c,i.enum]),void n.push(f+": "+c+p);n.push(f+": "+l+p)}),n.push("}");t.length>0;){var y=t.pop();y&&s(y)}}}}for(Object.entries(a).forEach(function(e){return r.push(e)}),r.sort(function(e,r){return e[0].localeCompare(r[0])});r.length>0;)i();return prettier.format(n.join("\n"),{parser:"graphql"})}var index=function(e,r){var t=r&&r.swagger||2;if(1!==t&&3!==t)return parse(e);console.error("That version is not supported")};module.exports=index;

@@ -41,4 +41,4 @@ import { format } from 'prettier';

boolean: 'Boolean',
float: 'Float',
integer: 'Int',
number: 'Number',
string: 'String',

@@ -69,20 +69,32 @@ };

var $ref = definition.$ref, items = definition.items, type = definition.type, value = __rest(definition, ["$ref", "items", "type"]);
var DEFAULT_TYPE = 'Scalar';
if ($ref) {
var _a = getRef($ref), refName = _a[0], refProperties = _a[1];
if (refName === 'ID')
if (refName === 'ID') {
return 'ID';
}
if (refProperties.items && refProperties.items.$ref) {
return getType(refProperties, refName);
}
return "" + (TYPES[refProperties.type] || refName || 'scalar');
if (refProperties.type && TYPES[refProperties.type]) {
return TYPES[refProperties.type] || DEFAULT_TYPE;
}
return refName || DEFAULT_TYPE;
}
if (type === 'array' && items) {
if (items.$ref) {
var _b = getRef(items.$ref), refName = _b[0], refProperties = _b[1];
if (refName === 'ID')
return 'ID';
return "[" + (TYPES[refProperties.type] || refName || 'scalar') + "]";
if (type === 'number') {
if (value.format && value.format === 'float') {
return TYPES.float;
}
return "[" + (TYPES[items.type] || 'scalar') + "]";
return TYPES.integer;
}
if (items && items.$ref) {
var refName = getRef(items.$ref)[0];
return "[" + getType(items, refName) + "]";
}
else if (items && items.type && TYPES[items.type]) {
return "[" + TYPES[items.type] + "]";
}
if (value.oneOf) {
return getType(value.oneOf[0], '');
}
if (value.properties) {

@@ -92,3 +104,6 @@ queue.push([nestedName, __assign({ $ref: $ref, items: items, type: type }, value)]);

}
return TYPES[type] || type || 'scalar';
if (type) {
return TYPES[type] || type || DEFAULT_TYPE;
}
return DEFAULT_TYPE;
}

@@ -112,4 +127,5 @@ function buildNextEnum(_a) {

var nextObject = queue.pop();
if (!nextObject)
if (!nextObject) {
return;
}
var ID = nextObject[0], _a = nextObject[1], allOf = _a.allOf, properties = _a.properties, required = _a.required;

@@ -138,2 +154,5 @@ var allProperties = properties || {};

var key = _a[0], value = _a[1];
if (key === 'resizable_to') {
console.log(value);
}
var optional = !Array.isArray(required) || required.indexOf(key) === -1;

@@ -157,4 +176,5 @@ var nonNullable = optional ? '' : '!';

var nextEnum = enumQueue.pop();
if (nextEnum)
if (nextEnum) {
buildNextEnum(nextEnum);
}
}

@@ -161,0 +181,0 @@ }

{
"name": "@manifoldco/graphql-gen",
"version": "1.1.1",
"version": "1.1.2",
"description": "Generate GraphQL schemas from Swagger OpenAPI specs ",

@@ -34,3 +34,4 @@ "main": "dist/index.js",

"generate": "node scripts/generate",
"test": "jest"
"test": "jest",
"test:coverage": "jest --coverage"
},

@@ -50,3 +51,2 @@ "dependencies": {

"@types/prettier": "^1.15.2",
"glob": "^7.1.3",
"jest": "^23.6.0",

@@ -58,2 +58,5 @@ "rollup": "^1.1.2",

"tslib": "^1.9.3",
"tslint": "^5.12.1",
"tslint-config-prettier": "^1.17.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.2.4"

@@ -60,0 +63,0 @@ },

@@ -14,2 +14,3 @@ # ⚛️ graphql-gen

| Implements (`allOf`) | ✅ |
| Polymorphism\* (`oneOf`) | N/A |
| Non-nullable | ✅ |

@@ -20,2 +21,7 @@ | Primitives (string, boolean, number) | ✅ |

To compare actual generated output, see the [example](./example) folder.
_\* Polymorphism isn’t supported by GraphQL by design. If this encounters one
in Swagger, it’ll assign the first type it encounters and throw a warning._
## Usage

@@ -22,0 +28,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc